autoctxd 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,62 +1,77 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## [0.4.0] - 2026-05-15
9
-
10
- Quality pass before the first public release. Same surface area, three pre-existing bugs in the classifier and decision extractor fixed.
11
-
12
- ### Fixed
13
- - Decision extractor no longer captures `npm install` / `bun add` / `pip install` mentions in Monitor commands, task descriptions, and log streams as architectural decisions. The dependency detector now validates the captured token against a reject list (`output`, `progress`, `tsx`, `tests`, `dev`, `prod`, …) and rejects numeric-only tokens, very short bare words, and anything without alphabetic characters.
14
- - Classifier filters internal harness tools (`Monitor`, `ToolSearch`, `TaskStop`, `TaskOutput`, `TodoWrite`) and Bash/PowerShell summaries that carry their payloads. These are still persisted but at importance 1, so they fall out of "top observations" and never get injected as recovered context.
15
- - Bash/PowerShell exploration commands (`List …`, `Check …`, `Find …`, `git status`, `git log`, `git diff`, `git blame`, …) are now classified as `research` with low importance instead of dropping to `other`. PowerShell gets the same Bash heuristics it lacked before.
16
- - Decisions no longer duplicate across sessions. A unique index on `(project_path, title)` plus `INSERT OR IGNORE` makes re-extraction idempotent.
17
- - The decision extractor's "tool-prefixed noise" guard was extended to catch `Bash:` / `PowerShell:` / `Edit:` / `Edited ` / `Monitor:` / `ToolSearch:` / `TodoWrite` / `TaskStop:` / `TaskOutput:` summaries that previously slipped through when the classifier promoted them to type=decision via a stray keyword.
18
-
19
- ### Added
20
- - `autoctxd cleanup-decisions [--dry-run]` deletes generic-word noise (`Added npm dep: output`, …) and tool-prefixed leftovers from the pre-0.4 extractor, and collapses any cross-session duplicates that predate the unique index. Idempotent; safe to re-run.
21
- - Schema migration: cross-session duplicate decisions in legacy DBs are collapsed to the earliest row on open, then the unique index is enforced going forward.
22
-
23
- ### Improved
24
- - On the author's real DB, this collapsed the architectural-decisions feed from 142 noisy rows to 4 actual decisions.
25
-
26
- ## [0.3.0] - 2026-05-15
27
-
28
- First public release.
29
-
30
- ### Added
31
- - **MCP server** with 7 tools (`recall_decisions`, `recall_unfinished`, `search_memory`, `get_project_history`, `check_intent`, `record_feedback`, `record_decision`) for active memory recall in Claude Code, Cursor, Windsurf, Cline, and Claude Desktop.
32
- - **Active Guard** `check_intent` flags actions that contradict past decisions before they happen.
33
- - **Feedback loop** — `record_feedback` lets the system learn which memories are useful, irrelevant, or wrong per user.
34
- - **Pluggable embeddings** — TF-IDF (default, zero-install), MiniLM-L6-v2 via `@xenova/transformers` (opt-in), and Ollama for any local embedding model. Switch with `autoctxd embeddings switch`; cache is partitioned per provider.
35
- - **Local web dashboard** at `http://localhost:4589` metric cards, activity timeline, decision feed, decision chains, pattern panel, hybrid search.
36
- - **Decision chains** automatically detects sequences like `mysql postgres sqlite` across sessions.
37
- - **Token-savings metrics** — accumulated estimate of tokens injected vs. tokens that would otherwise be re-explained.
38
- - **One-command installer** for macOS, Linux (`install.sh`) and Windows (`install.ps1`) — bootstraps Bun if missing, clones the repo, installs deps, initializes the DB, registers the hooks in `settings.json` (non-destructive merge).
39
- - **Health-check doctor** (`autoctxd doctor`) validates runtime, deps, DB schema, LanceDB, hook registration, data directory, and accumulated metrics.
40
- - **`.autoctxd-ignore`** — gitignore-style opt-out for sensitive projects (single `*` opts the whole project out).
41
- - **Cross-session pattern detection** — tool preferences, work-type focus, file hotspots, TDD vs. fix-first, peak coding hours (after 3+ sessions per project).
42
- - **Hybrid search** — semantic (vector) + full-text (FTS5) with project filter.
43
- - **Re-classification** — `autoctxd reclassify` re-runs the classifier on old observations after improvements.
44
- - **Export** — `autoctxd export ./my-app > context.md` for project memory as markdown.
45
-
46
- ### Stack
47
- - Bun runtime
48
- - SQLite + FTS5 for structured storage and full-text search
49
- - LanceDB for vector storage (dim adapts to active provider)
50
- - Keyword + tool/file heuristics for classification (no LLM calls)
51
-
52
- ### Privacy
53
- - No telemetry. No cloud. No network calls during operation.
54
- - Everything in `~/.claude/autoctxd/data/`delete to wipe.
55
- - See [SECURITY.md](SECURITY.md) for the full threat model.
56
-
57
- ### Testing
58
- - 75 tests, isolated temp DB (never touches real memory).
59
- - Cross-provider embeddings benchmark (`bun run benchmark:embeddings`).
60
- - Tests cover classifier, compressor, decision extractor, decision chains, ignore matcher, embedding providers, and end-to-end integration.
61
-
62
- [0.3.0]: https://github.com/autoctxd/autoctxd/releases/tag/v0.3.0
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.4.2] - 2026-05-16
9
+
10
+ ### Fixed
11
+ - `npm install -g autoctxd` now shows a helpful message when Bun is missing from PATH, instead of crashing with a cryptic error. The new Node.js wrapper in `bin/autoctxd.cjs` detects Bun availability and provides clear, platform-specific installation instructions for the user.
12
+
13
+ ## [0.4.1] - 2026-05-16
14
+
15
+ ### Added
16
+ - `.npmignore` so the npm tarball ships only the runtime files (excludes `tests/`, dev scripts, models, docs assets, internal notes, build artifacts).
17
+ - `repository`, `homepage`, `bugs`, and `preferGlobal` fields in `package.json` for npm discoverability.
18
+
19
+ ### Fixed
20
+ - Typecheck cleanup in `src/db/vector/search.ts` (consistent `_distance` access via `as any`).
21
+ - `tsconfig.json` types switched from the unmaintained `bun-types` package to the official `bun` types.
22
+
23
+ ## [0.4.0] - 2026-05-15
24
+
25
+ Quality pass before the first public release. Same surface area, three pre-existing bugs in the classifier and decision extractor fixed.
26
+
27
+ ### Fixed
28
+ - Decision extractor no longer captures `npm install` / `bun add` / `pip install` mentions in Monitor commands, task descriptions, and log streams as architectural decisions. The dependency detector now validates the captured token against a reject list (`output`, `progress`, `tsx`, `tests`, `dev`, `prod`, …) and rejects numeric-only tokens, very short bare words, and anything without alphabetic characters.
29
+ - Classifier filters internal harness tools (`Monitor`, `ToolSearch`, `TaskStop`, `TaskOutput`, `TodoWrite`) and Bash/PowerShell summaries that carry their payloads. These are still persisted but at importance 1, so they fall out of "top observations" and never get injected as recovered context.
30
+ - Bash/PowerShell exploration commands (`List …`, `Check …`, `Find …`, `git status`, `git log`, `git diff`, `git blame`, …) are now classified as `research` with low importance instead of dropping to `other`. PowerShell gets the same Bash heuristics it lacked before.
31
+ - Decisions no longer duplicate across sessions. A unique index on `(project_path, title)` plus `INSERT OR IGNORE` makes re-extraction idempotent.
32
+ - The decision extractor's "tool-prefixed noise" guard was extended to catch `Bash:` / `PowerShell:` / `Edit:` / `Edited ` / `Monitor:` / `ToolSearch:` / `TodoWrite` / `TaskStop:` / `TaskOutput:` summaries that previously slipped through when the classifier promoted them to type=decision via a stray keyword.
33
+
34
+ ### Added
35
+ - `autoctxd cleanup-decisions [--dry-run]` deletes generic-word noise (`Added npm dep: output`, …) and tool-prefixed leftovers from the pre-0.4 extractor, and collapses any cross-session duplicates that predate the unique index. Idempotent; safe to re-run.
36
+ - Schema migration: cross-session duplicate decisions in legacy DBs are collapsed to the earliest row on open, then the unique index is enforced going forward.
37
+
38
+ ### Improved
39
+ - On the author's real DB, this collapsed the architectural-decisions feed from 142 noisy rows to 4 actual decisions.
40
+
41
+ ## [0.3.0] - 2026-05-15
42
+
43
+ First public release.
44
+
45
+ ### Added
46
+ - **MCP server** with 7 tools (`recall_decisions`, `recall_unfinished`, `search_memory`, `get_project_history`, `check_intent`, `record_feedback`, `record_decision`) for active memory recall in Claude Code, Cursor, Windsurf, Cline, and Claude Desktop.
47
+ - **Active Guard** — `check_intent` flags actions that contradict past decisions before they happen.
48
+ - **Feedback loop** `record_feedback` lets the system learn which memories are useful, irrelevant, or wrong per user.
49
+ - **Pluggable embeddings** TF-IDF (default, zero-install), MiniLM-L6-v2 via `@xenova/transformers` (opt-in), and Ollama for any local embedding model. Switch with `autoctxd embeddings switch`; cache is partitioned per provider.
50
+ - **Local web dashboard** at `http://localhost:4589` metric cards, activity timeline, decision feed, decision chains, pattern panel, hybrid search.
51
+ - **Decision chains** — automatically detects sequences like `mysql → postgres → sqlite` across sessions.
52
+ - **Token-savings metrics** — accumulated estimate of tokens injected vs. tokens that would otherwise be re-explained.
53
+ - **One-command installer** for macOS, Linux (`install.sh`) and Windows (`install.ps1`) bootstraps Bun if missing, clones the repo, installs deps, initializes the DB, registers the hooks in `settings.json` (non-destructive merge).
54
+ - **Health-check doctor** (`autoctxd doctor`) validates runtime, deps, DB schema, LanceDB, hook registration, data directory, and accumulated metrics.
55
+ - **`.autoctxd-ignore`** gitignore-style opt-out for sensitive projects (single `*` opts the whole project out).
56
+ - **Cross-session pattern detection** — tool preferences, work-type focus, file hotspots, TDD vs. fix-first, peak coding hours (after 3+ sessions per project).
57
+ - **Hybrid search** — semantic (vector) + full-text (FTS5) with project filter.
58
+ - **Re-classification** `autoctxd reclassify` re-runs the classifier on old observations after improvements.
59
+ - **Export** — `autoctxd export ./my-app > context.md` for project memory as markdown.
60
+
61
+ ### Stack
62
+ - Bun runtime
63
+ - SQLite + FTS5 for structured storage and full-text search
64
+ - LanceDB for vector storage (dim adapts to active provider)
65
+ - Keyword + tool/file heuristics for classification (no LLM calls)
66
+
67
+ ### Privacy
68
+ - No telemetry. No cloud. No network calls during operation.
69
+ - Everything in `~/.claude/autoctxd/data/` — delete to wipe.
70
+ - See [SECURITY.md](SECURITY.md) for the full threat model.
71
+
72
+ ### Testing
73
+ - 75 tests, isolated temp DB (never touches real memory).
74
+ - Cross-provider embeddings benchmark (`bun run benchmark:embeddings`).
75
+ - Tests cover classifier, compressor, decision extractor, decision chains, ignore matcher, embedding providers, and end-to-end integration.
76
+
77
+ [0.3.0]: https://github.com/autoctxd/autoctxd/releases/tag/v0.3.0
package/README.md CHANGED
@@ -1,301 +1,309 @@
1
- # autoctxd
2
-
3
- **Persistent, local memory for Claude Code.**
4
-
5
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
- [![Bun](https://img.shields.io/badge/runtime-Bun%20%E2%89%A51.1-black)](https://bun.sh)
7
- [![CI](https://github.com/autoctxd/autoctxd/actions/workflows/ci.yml/badge.svg)](https://github.com/autoctxd/autoctxd/actions/workflows/ci.yml)
8
- [![Zero API](https://img.shields.io/badge/API%20calls-0-success)](#privacy)
9
- [![MCP](https://img.shields.io/badge/MCP-7%20tools-purple)](#how-it-works)
10
- [![PRs welcome](https://img.shields.io/badge/PRs-welcome-orange)](CONTRIBUTING.md)
11
-
12
- ![Active Guard Demo](docs/assets/active-guard-demo.gif)
13
-
14
- Every Claude Code session starts from scratch. You re-explain your project, re-state decisions you already made, re-describe what you were in the middle of. `autoctxd` fixes that — silently, locally, with zero API cost.
15
-
16
- - **100% local, zero API cost** — pure heuristics, no LLM calls, nothing leaves your machine
17
- - Captures every tool use automatically through Claude Code hooks
18
- - Injects the right ~600 tokens of context into each new session
19
- - Tracks architectural decisions separately — they never get forgotten
20
- - Detects work patterns across sessions
21
- - **Active Guard** — flags actions that contradict past decisions, before you make them
22
-
23
- ## Why autoctxd?
24
-
25
- | | autoctxd | Mem0 / memori (cloud) | Plain CLAUDE.md |
26
- |---|---|---|---|
27
- | Where your code context lives | **Your disk** | Their servers | A static file you maintain |
28
- | Cost per session | **$0** | API calls billed | $0 |
29
- | Captures automatically | **Yes** (hooks) | Via SDK calls | No — you write it |
30
- | Active recall during reasoning | **Yes** (7 MCP tools) | Yes | No |
31
- | Flags decision contradictions | **Yes** (Active Guard) | No | No |
32
- | Works offline | **Yes** | No | Yes |
33
- | Cross-session patterns / hotspots | **Yes** | Limited | No |
34
- | Setup | **One command** | Account + API key | Edit a file |
35
-
36
- Built specifically for the **Claude Code workflow** — hooks, MCP, and a local dashboard, not a generic SDK you bolt onto something.
37
-
38
- ## How it works
39
-
40
- ```
41
- Session 1 Session 2 (days later)
42
- ───────── ─────────────────────
43
- You work on auth refactor ───┐ ┌──► Claude already knows:
44
- Claude uses Edit/Write/Bash │ │ • "Migrated from jwt to iron-session"
45
- ▼ │ • Hot files: auth/session.ts
46
- ┌──────────┐ │ • Last session left the login route
47
- │ SQLite │ │ half-wired (blocked)
48
- │ LanceDB │─────┘
49
- └──────────┘ no re-explaining needed
50
- ```
51
-
52
- Two integration modes, use either or both:
53
-
54
- **1. Passive (hooks, Claude Code only)** — injects context at session start.
55
-
56
- | Hook | What it does |
57
- |---|---|
58
- | `PreToolUse` | Builds context block from past sessions and injects it |
59
- | `PostToolUse` | Classifies and stores each tool use as an observation |
60
- | `Stop` | Compresses the session, extracts decisions, detects patterns, generates embeddings |
61
-
62
- **2. Active (MCP server, works everywhere)** — Claude/Cursor/Windsurf/Cline query memory **during** reasoning via 7 tools:
63
-
64
- | Tool | What it enables |
65
- |---|---|
66
- | `recall_decisions` | Look up past architectural decisions for a project |
67
- | `recall_unfinished` | Surface blockers from past sessions |
68
- | `search_memory` | Semantic + FTS search across all your coding memory |
69
- | `get_project_history` | Recent session summaries |
70
- | **`check_intent`** | **Active Guard** — flags actions that contradict past decisions |
71
- | `record_feedback` | Learns from "useful/irrelevant/wrong" signals |
72
- | `record_decision` | Persists decisions made in-conversation (never forgotten) |
73
-
74
- See [docs/INTEGRATIONS.md](docs/INTEGRATIONS.md) for setup in each editor.
75
-
76
- Nothing leaves your machine.
77
-
78
- ## Install
79
-
80
- ### One-command install
81
-
82
- **macOS / Linux**
83
- ```bash
84
- curl -fsSL https://raw.githubusercontent.com/autoctxd/autoctxd/main/scripts/install.sh | bash
85
- ```
86
-
87
- **Windows (PowerShell)**
88
- ```powershell
89
- irm https://raw.githubusercontent.com/autoctxd/autoctxd/main/scripts/install.ps1 | iex
90
- ```
91
-
92
- That's it — installs Bun if missing, clones the repo into `~/.claude/autoctxd`, installs deps, initializes the DB, and registers the three hooks in your existing `settings.json` (preserving anything already there).
93
-
94
- Verify with `autoctxd doctor`. Uninstall cleanly with `bun run scripts/uninstall-hooks.ts`.
95
-
96
- ### Manual install
97
-
98
- If you prefer step-by-step, requires [Bun](https://bun.sh) and Claude Code:
99
-
100
- ```bash
101
- cd ~/.claude
102
- git clone https://github.com/autoctxd/autoctxd.git
103
- cd autoctxd
104
- bun install
105
- bun run src/cli/index.ts init
106
- bun run scripts/install-hooks.ts # merges hooks into settings.json
107
- bun run src/cli/index.ts doctor # verify
108
- ```
109
-
110
- <details>
111
- <summary>Or if you want to add the hooks manually, here's the block:</summary>
112
-
113
- ```json
114
- {
115
- "hooks": {
116
- "PreToolUse": [{
117
- "matcher": "",
118
- "hooks": [{
119
- "type": "command",
120
- "command": "bun run ~/.claude/autoctxd/src/hooks/pre-tool-use.ts"
121
- }]
122
- }],
123
- "PostToolUse": [{
124
- "matcher": "",
125
- "hooks": [{
126
- "type": "command",
127
- "command": "bun run ~/.claude/autoctxd/src/hooks/post-tool-use.ts"
128
- }]
129
- }],
130
- "Stop": [{
131
- "matcher": "",
132
- "hooks": [{
133
- "type": "command",
134
- "command": "bun run ~/.claude/autoctxd/src/hooks/stop.ts"
135
- }]
136
- }]
137
- }
138
- }
139
- ```
140
-
141
-
142
- </details>
143
-
144
- Restart Claude Code. The next session starts collecting. The one after that starts getting context.
145
-
146
- ## CLI
147
-
148
- ```bash
149
- # What has autoctxd learned about you?
150
- bun run src/cli/index.ts stats
151
-
152
- # Every decision you've made across projects
153
- bun run src/cli/index.ts decisions
154
-
155
- # Hybrid search (semantic + full-text) across everything
156
- bun run src/cli/index.ts search "race condition async"
157
-
158
- # Drill into one session
159
- bun run src/cli/index.ts show session <session-id>
160
-
161
- # Patterns detected in your workflow
162
- bun run src/cli/index.ts patterns
163
-
164
- # Export a project's memory to markdown
165
- bun run src/cli/index.ts export ./my-app > context.md
166
-
167
- # Re-run the classifier on old observations (after classifier improvements)
168
- bun run src/cli/index.ts reclassify
169
-
170
- # Token accounting: what autoctxd has saved you
171
- bun run src/cli/index.ts metrics
172
-
173
- # Launch the local web dashboard
174
- bun run src/cli/index.ts dashboard
175
- # http://localhost:4589
176
-
177
- # Health check your install
178
- bun run src/cli/index.ts doctor
179
- ```
180
-
181
- ## Dashboard
182
-
183
- ![Dashboard](docs/assets/dashboard.png)
184
-
185
- Running `autoctxd dashboard` launches a local web UI at `http://localhost:4589`:
186
-
187
- - Metric cards: sessions, observations, decisions, projects, context hit rate, avg explore calls, tokens saved
188
- - Activity timeline of every observation across all projects
189
- - Architectural decision feed with alternatives and rationale
190
- - **Decision chains** — automatically detected sequences like `mysql → postgres → sqlite` across sessions
191
- - Pattern panel (tool preferences, work focus, hotspots, TDD vs fix-first, peak coding hours)
192
- - Hybrid search (semantic + full-text) with project filter
193
-
194
- Everything read-only, everything local. No accounts, no network.
195
-
196
- ## Debug mode
197
-
198
- Set `AUTOCTXD_DEBUG=1` to log every hook invocation to `data/debug.log`:
199
-
200
- ```bash
201
- AUTOCTXD_DEBUG=1 claude # then tail data/debug.log
202
- ```
203
-
204
- You'll see what was injected, why, and timings.
205
-
206
- ## What gets captured
207
-
208
- Each `PostToolUse` becomes an **observation**, classified as one of:
209
-
210
- `bug_fix` · `refactor` · `new_feature` · `config` · `research` · `test` · `decision` · `blocked` · `deploy` · `other`
211
-
212
- The classifier is pure heuristics. Scores each observation 0–10 for importance. Critical files (`auth`, `payment`, `migration`, `schema`) get boosted. Docs/readmes get demoted.
213
-
214
- **Decisions** are first-class. Every `bun add`, `npm install`, `cargo add` becomes a stack decision. Every "switched from X to Y" becomes an architectural decision. These never get compressed away.
215
-
216
- **Patterns** emerge after 3+ sessions in the same project: tool preferences, work-type focus, file hotspots, TDD vs. fix-first workflows, peak coding hours.
217
-
218
- ## What gets injected
219
-
220
- At session start, `autoctxd` assembles a context block from:
221
-
222
- - **Architectural decisions** on this project (all of them, always)
223
- - **Recent session highlights** (top 3 sessions by recency)
224
- - **Semantically similar past sessions** (cross-project if relevant)
225
- - **Hot files** (modified 3+ times recently)
226
- - **Your patterns in this project**
227
-
228
- Format is compact targets ~600-800 tokens so it doesn't crowd your context window.
229
-
230
- ## Privacy
231
-
232
- Everything stays in `~/.claude/autoctxd/data/`. Delete the folder to wipe all memory. No telemetry, no cloud, no network calls during operation.
233
-
234
- For sensitive projects, drop a `.autoctxd-ignore` file at the project root. Patterns follow a `.gitignore`-style subset — a single `*` opts the whole project out. See [SECURITY.md](SECURITY.md) for the full threat model and the list of what does/doesn't get persisted.
235
-
236
- ## Embedding providers
237
-
238
- Pick the right trade-off for your machine and threat model. **TF-IDF is the default** — zero install pain, deterministic, fast. Upgrade when you want richer retrieval.
239
-
240
- | Provider | Dim | Latency | Discrimination | Setup |
241
- |---|---:|---:|---:|---|
242
- | `tfidf` *(default)* | 128 | **0.1 ms** | gap 0.170, 92% wins | nothing built in |
243
- | `minilm` | 384 | 4.5 ms | gap 0.621, **100% wins** | `autoctxd embeddings switch minilm --yes` (~25MB model download on first use) |
244
- | `ollama` | 768 | varies | run `bun run benchmark:embeddings` on your box | Requires [Ollama](https://ollama.com) running locally with `ollama pull nomic-embed-text` |
245
-
246
- *Numbers from `scripts/benchmark-embeddings.ts` over 12 dev-text pairs (anchor / paraphrase / unrelated). "Wins" is the share of pairs where the model puts the paraphrase closer to the anchor than the unrelated text. Higher = better.*
247
-
248
- ```bash
249
- # What's active and what's available?
250
- autoctxd embeddings list
251
- autoctxd embeddings status
252
-
253
- # Switch — re-embeds everything you've stored, automatically
254
- autoctxd embeddings switch minilm --yes
255
-
256
- # Or pin via env (no persistence)
257
- AUTOCTXD_EMBEDDING=minilm autoctxd ...
258
- ```
259
-
260
- The cache is partitioned by provider, so switching back is cheap. `@xenova/transformers` is an `optionalDependency` — if `bun install` fails to fetch it, MiniLM is just unavailable and TF-IDF keeps working.
261
-
262
- ## Stack
263
-
264
- | Component | Tech |
265
- |---|---|
266
- | Runtime | Bun |
267
- | Structured DB | SQLite + FTS5 (full-text search) |
268
- | Vector DB | LanceDB (dim adapts to active provider) |
269
- | Embeddings | TF-IDF (default) · MiniLM-L6-v2 via transformers.js · Ollama (any embedding model) |
270
- | Classification | Keyword + tool/file heuristics |
271
-
272
- ## Roadmap
273
-
274
- - [x] Local web dashboard
275
- - [x] Decision chains across sessions
276
- - [x] Token savings metrics
277
- - [x] One-command installer for all platforms
278
- - [x] Health-check doctor
279
- - [x] Integration test suite
280
- - [x] **MCP server mode** — Claude queries memory actively, not just at session start
281
- - [x] **Active Guard** — flags actions that contradict past decisions
282
- - [x] **Feedback loop** — system learns what's useful to each user
283
- - [x] **Multi-editor** Cursor, Windsurf, Cline, Claude Desktop, Claude Code
284
- - [x] **Pluggable embeddings** — TF-IDF default, MiniLM and Ollama opt-in
285
- - [x] **`.autoctxd-ignore`** gitignore-style opt-out for sensitive projects
286
- - [ ] Codebase awareness — integrate git blame + AST analysis
287
- - [ ] Predictive context — surface what you'll need next based on patterns
288
-
289
- ## Testing
290
-
291
- ```bash
292
- bun test # 75 tests, isolated temp DB
293
- bun run benchmark:embeddings # cross-provider quality + latency
294
- bun run typecheck # tsc --noEmit
295
- ```
296
-
297
- Coverage spans the classifier, compressor, decision extractor, decision chains, ignore matcher, embedding providers, and an end-to-end integration flow. Tests never touch your real memory.
298
-
299
- ## License
300
-
301
- MIT.
1
+ # autoctxd
2
+
3
+ **Persistent, local memory for Claude Code.**
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
+ [![Bun](https://img.shields.io/badge/runtime-Bun%20%E2%89%A51.1-black)](https://bun.sh)
7
+ [![CI](https://github.com/autoctxd/autoctxd/actions/workflows/ci.yml/badge.svg)](https://github.com/autoctxd/autoctxd/actions/workflows/ci.yml)
8
+ [![Zero API](https://img.shields.io/badge/API%20calls-0-success)](#privacy)
9
+ [![MCP](https://img.shields.io/badge/MCP-7%20tools-purple)](#how-it-works)
10
+ [![PRs welcome](https://img.shields.io/badge/PRs-welcome-orange)](CONTRIBUTING.md)
11
+
12
+ ![Active Guard Demo](docs/assets/active-guard-demo.gif)
13
+
14
+ Every Claude Code session starts from scratch. You re-explain your project, re-state decisions you already made, re-describe what you were in the middle of. `autoctxd` fixes that — silently, locally, with zero API cost.
15
+
16
+ - **100% local, zero API cost** — pure heuristics, no LLM calls, nothing leaves your machine
17
+ - Captures every tool use automatically through Claude Code hooks
18
+ - Injects the right ~600 tokens of context into each new session
19
+ - Tracks architectural decisions separately — they never get forgotten
20
+ - Detects work patterns across sessions
21
+ - **Active Guard** — flags actions that contradict past decisions, before you make them
22
+
23
+ ## Why autoctxd?
24
+
25
+ | | autoctxd | Mem0 / memori (cloud) | Plain CLAUDE.md |
26
+ |---|---|---|---|
27
+ | Where your code context lives | **Your disk** | Their servers | A static file you maintain |
28
+ | Cost per session | **$0** | API calls billed | $0 |
29
+ | Captures automatically | **Yes** (hooks) | Via SDK calls | No — you write it |
30
+ | Active recall during reasoning | **Yes** (7 MCP tools) | Yes | No |
31
+ | Flags decision contradictions | **Yes** (Active Guard) | No | No |
32
+ | Works offline | **Yes** | No | Yes |
33
+ | Cross-session patterns / hotspots | **Yes** | Limited | No |
34
+ | Setup | **One command** | Account + API key | Edit a file |
35
+
36
+ Built specifically for the **Claude Code workflow** — hooks, MCP, and a local dashboard, not a generic SDK you bolt onto something.
37
+
38
+ ## How it works
39
+
40
+ ```
41
+ Session 1 Session 2 (days later)
42
+ ───────── ─────────────────────
43
+ You work on auth refactor ───┐ ┌──► Claude already knows:
44
+ Claude uses Edit/Write/Bash │ │ • "Migrated from jwt to iron-session"
45
+ ▼ │ • Hot files: auth/session.ts
46
+ ┌──────────┐ │ • Last session left the login route
47
+ │ SQLite │ │ half-wired (blocked)
48
+ │ LanceDB │─────┘
49
+ └──────────┘ no re-explaining needed
50
+ ```
51
+
52
+ Two integration modes, use either or both:
53
+
54
+ **1. Passive (hooks, Claude Code only)** — injects context at session start.
55
+
56
+ | Hook | What it does |
57
+ |---|---|
58
+ | `PreToolUse` | Builds context block from past sessions and injects it |
59
+ | `PostToolUse` | Classifies and stores each tool use as an observation |
60
+ | `Stop` | Compresses the session, extracts decisions, detects patterns, generates embeddings |
61
+
62
+ **2. Active (MCP server, works everywhere)** — Claude/Cursor/Windsurf/Cline query memory **during** reasoning via 7 tools:
63
+
64
+ | Tool | What it enables |
65
+ |---|---|
66
+ | `recall_decisions` | Look up past architectural decisions for a project |
67
+ | `recall_unfinished` | Surface blockers from past sessions |
68
+ | `search_memory` | Semantic + FTS search across all your coding memory |
69
+ | `get_project_history` | Recent session summaries |
70
+ | **`check_intent`** | **Active Guard** — flags actions that contradict past decisions |
71
+ | `record_feedback` | Learns from "useful/irrelevant/wrong" signals |
72
+ | `record_decision` | Persists decisions made in-conversation (never forgotten) |
73
+
74
+ See [docs/INTEGRATIONS.md](docs/INTEGRATIONS.md) for setup in each editor.
75
+
76
+ Nothing leaves your machine.
77
+
78
+ ## Install
79
+
80
+ ### One-command install
81
+
82
+ **macOS / Linux**
83
+ ```bash
84
+ curl -fsSL https://raw.githubusercontent.com/autoctxd/autoctxd/main/scripts/install.sh | bash
85
+ ```
86
+
87
+ **Windows (PowerShell)**
88
+ ```powershell
89
+ irm https://raw.githubusercontent.com/autoctxd/autoctxd/main/scripts/install.ps1 | iex
90
+ ```
91
+
92
+ That's it — installs Bun if missing, clones the repo into `~/.claude/autoctxd`, installs deps, initializes the DB, and registers the three hooks in your existing `settings.json` (preserving anything already there).
93
+
94
+ Verify with `autoctxd doctor`. Uninstall cleanly with `bun run scripts/uninstall-hooks.ts`.
95
+
96
+ ### From npm
97
+
98
+ ```bash
99
+ npm install -g autoctxd
100
+ ```
101
+
102
+ > Requires [Bun](https://bun.sh) on your PATH. If you don't have Bun, `autoctxd` will print install instructions on first run, or use the one-command installer above which handles Bun for you.
103
+
104
+ ### Manual install
105
+
106
+ If you prefer step-by-step, requires [Bun](https://bun.sh) and Claude Code:
107
+
108
+ ```bash
109
+ cd ~/.claude
110
+ git clone https://github.com/autoctxd/autoctxd.git
111
+ cd autoctxd
112
+ bun install
113
+ bun run src/cli/index.ts init
114
+ bun run scripts/install-hooks.ts # merges hooks into settings.json
115
+ bun run src/cli/index.ts doctor # verify
116
+ ```
117
+
118
+ <details>
119
+ <summary>Or if you want to add the hooks manually, here's the block:</summary>
120
+
121
+ ```json
122
+ {
123
+ "hooks": {
124
+ "PreToolUse": [{
125
+ "matcher": "",
126
+ "hooks": [{
127
+ "type": "command",
128
+ "command": "bun run ~/.claude/autoctxd/src/hooks/pre-tool-use.ts"
129
+ }]
130
+ }],
131
+ "PostToolUse": [{
132
+ "matcher": "",
133
+ "hooks": [{
134
+ "type": "command",
135
+ "command": "bun run ~/.claude/autoctxd/src/hooks/post-tool-use.ts"
136
+ }]
137
+ }],
138
+ "Stop": [{
139
+ "matcher": "",
140
+ "hooks": [{
141
+ "type": "command",
142
+ "command": "bun run ~/.claude/autoctxd/src/hooks/stop.ts"
143
+ }]
144
+ }]
145
+ }
146
+ }
147
+ ```
148
+
149
+
150
+ </details>
151
+
152
+ Restart Claude Code. The next session starts collecting. The one after that starts getting context.
153
+
154
+ ## CLI
155
+
156
+ ```bash
157
+ # What has autoctxd learned about you?
158
+ bun run src/cli/index.ts stats
159
+
160
+ # Every decision you've made across projects
161
+ bun run src/cli/index.ts decisions
162
+
163
+ # Hybrid search (semantic + full-text) across everything
164
+ bun run src/cli/index.ts search "race condition async"
165
+
166
+ # Drill into one session
167
+ bun run src/cli/index.ts show session <session-id>
168
+
169
+ # Patterns detected in your workflow
170
+ bun run src/cli/index.ts patterns
171
+
172
+ # Export a project's memory to markdown
173
+ bun run src/cli/index.ts export ./my-app > context.md
174
+
175
+ # Re-run the classifier on old observations (after classifier improvements)
176
+ bun run src/cli/index.ts reclassify
177
+
178
+ # Token accounting: what autoctxd has saved you
179
+ bun run src/cli/index.ts metrics
180
+
181
+ # Launch the local web dashboard
182
+ bun run src/cli/index.ts dashboard
183
+ # → http://localhost:4589
184
+
185
+ # Health check your install
186
+ bun run src/cli/index.ts doctor
187
+ ```
188
+
189
+ ## Dashboard
190
+
191
+ ![Dashboard](docs/assets/dashboard.png)
192
+
193
+ Running `autoctxd dashboard` launches a local web UI at `http://localhost:4589`:
194
+
195
+ - Metric cards: sessions, observations, decisions, projects, context hit rate, avg explore calls, tokens saved
196
+ - Activity timeline of every observation across all projects
197
+ - Architectural decision feed with alternatives and rationale
198
+ - **Decision chains** automatically detected sequences like `mysql → postgres → sqlite` across sessions
199
+ - Pattern panel (tool preferences, work focus, hotspots, TDD vs fix-first, peak coding hours)
200
+ - Hybrid search (semantic + full-text) with project filter
201
+
202
+ Everything read-only, everything local. No accounts, no network.
203
+
204
+ ## Debug mode
205
+
206
+ Set `AUTOCTXD_DEBUG=1` to log every hook invocation to `data/debug.log`:
207
+
208
+ ```bash
209
+ AUTOCTXD_DEBUG=1 claude # then tail data/debug.log
210
+ ```
211
+
212
+ You'll see what was injected, why, and timings.
213
+
214
+ ## What gets captured
215
+
216
+ Each `PostToolUse` becomes an **observation**, classified as one of:
217
+
218
+ `bug_fix` · `refactor` · `new_feature` · `config` · `research` · `test` · `decision` · `blocked` · `deploy` · `other`
219
+
220
+ The classifier is pure heuristics. Scores each observation 0–10 for importance. Critical files (`auth`, `payment`, `migration`, `schema`) get boosted. Docs/readmes get demoted.
221
+
222
+ **Decisions** are first-class. Every `bun add`, `npm install`, `cargo add` becomes a stack decision. Every "switched from X to Y" becomes an architectural decision. These never get compressed away.
223
+
224
+ **Patterns** emerge after 3+ sessions in the same project: tool preferences, work-type focus, file hotspots, TDD vs. fix-first workflows, peak coding hours.
225
+
226
+ ## What gets injected
227
+
228
+ At session start, `autoctxd` assembles a context block from:
229
+
230
+ - **Architectural decisions** on this project (all of them, always)
231
+ - **Recent session highlights** (top 3 sessions by recency)
232
+ - **Semantically similar past sessions** (cross-project if relevant)
233
+ - **Hot files** (modified 3+ times recently)
234
+ - **Your patterns in this project**
235
+
236
+ Format is compact — targets ~600-800 tokens so it doesn't crowd your context window.
237
+
238
+ ## Privacy
239
+
240
+ Everything stays in `~/.claude/autoctxd/data/`. Delete the folder to wipe all memory. No telemetry, no cloud, no network calls during operation.
241
+
242
+ For sensitive projects, drop a `.autoctxd-ignore` file at the project root. Patterns follow a `.gitignore`-style subset — a single `*` opts the whole project out. See [SECURITY.md](SECURITY.md) for the full threat model and the list of what does/doesn't get persisted.
243
+
244
+ ## Embedding providers
245
+
246
+ Pick the right trade-off for your machine and threat model. **TF-IDF is the default** zero install pain, deterministic, fast. Upgrade when you want richer retrieval.
247
+
248
+ | Provider | Dim | Latency | Discrimination | Setup |
249
+ |---|---:|---:|---:|---|
250
+ | `tfidf` *(default)* | 128 | **0.1 ms** | gap 0.170, 92% wins | nothing — built in |
251
+ | `minilm` | 384 | 4.5 ms | gap 0.621, **100% wins** | `autoctxd embeddings switch minilm --yes` (~25MB model download on first use) |
252
+ | `ollama` | 768 | varies | run `bun run benchmark:embeddings` on your box | Requires [Ollama](https://ollama.com) running locally with `ollama pull nomic-embed-text` |
253
+
254
+ *Numbers from `scripts/benchmark-embeddings.ts` over 12 dev-text pairs (anchor / paraphrase / unrelated). "Wins" is the share of pairs where the model puts the paraphrase closer to the anchor than the unrelated text. Higher = better.*
255
+
256
+ ```bash
257
+ # What's active and what's available?
258
+ autoctxd embeddings list
259
+ autoctxd embeddings status
260
+
261
+ # Switch — re-embeds everything you've stored, automatically
262
+ autoctxd embeddings switch minilm --yes
263
+
264
+ # Or pin via env (no persistence)
265
+ AUTOCTXD_EMBEDDING=minilm autoctxd ...
266
+ ```
267
+
268
+ The cache is partitioned by provider, so switching back is cheap. `@xenova/transformers` is an `optionalDependency` — if `bun install` fails to fetch it, MiniLM is just unavailable and TF-IDF keeps working.
269
+
270
+ ## Stack
271
+
272
+ | Component | Tech |
273
+ |---|---|
274
+ | Runtime | Bun |
275
+ | Structured DB | SQLite + FTS5 (full-text search) |
276
+ | Vector DB | LanceDB (dim adapts to active provider) |
277
+ | Embeddings | TF-IDF (default) · MiniLM-L6-v2 via transformers.js · Ollama (any embedding model) |
278
+ | Classification | Keyword + tool/file heuristics |
279
+
280
+ ## Roadmap
281
+
282
+ - [x] Local web dashboard
283
+ - [x] Decision chains across sessions
284
+ - [x] Token savings metrics
285
+ - [x] One-command installer for all platforms
286
+ - [x] Health-check doctor
287
+ - [x] Integration test suite
288
+ - [x] **MCP server mode** — Claude queries memory actively, not just at session start
289
+ - [x] **Active Guard** — flags actions that contradict past decisions
290
+ - [x] **Feedback loop** — system learns what's useful to each user
291
+ - [x] **Multi-editor** — Cursor, Windsurf, Cline, Claude Desktop, Claude Code
292
+ - [x] **Pluggable embeddings** — TF-IDF default, MiniLM and Ollama opt-in
293
+ - [x] **`.autoctxd-ignore`** — gitignore-style opt-out for sensitive projects
294
+ - [ ] Codebase awareness — integrate git blame + AST analysis
295
+ - [ ] Predictive context — surface what you'll need next based on patterns
296
+
297
+ ## Testing
298
+
299
+ ```bash
300
+ bun test # 75 tests, isolated temp DB
301
+ bun run benchmark:embeddings # cross-provider quality + latency
302
+ bun run typecheck # tsc --noEmit
303
+ ```
304
+
305
+ Coverage spans the classifier, compressor, decision extractor, decision chains, ignore matcher, embedding providers, and an end-to-end integration flow. Tests never touch your real memory.
306
+
307
+ ## License
308
+
309
+ MIT.
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env node
2
+ const { spawnSync } = require('node:child_process');
3
+ const path = require('node:path');
4
+
5
+ const bunCheck = spawnSync('bun', ['--version'], {
6
+ stdio: 'ignore',
7
+ shell: process.platform === 'win32',
8
+ });
9
+
10
+ if (bunCheck.error || bunCheck.status !== 0) {
11
+ const isWindows = process.platform === 'win32';
12
+ console.error('');
13
+ console.error(' autoctxd requires Bun (https://bun.sh) but it was not found in PATH.');
14
+ console.error('');
15
+ console.error(' Install Bun:');
16
+ if (isWindows) {
17
+ console.error(' powershell -c "irm bun.sh/install.ps1 | iex"');
18
+ } else {
19
+ console.error(' curl -fsSL https://bun.sh/install | bash');
20
+ }
21
+ console.error('');
22
+ console.error(' Then restart your terminal and run `autoctxd` again.');
23
+ console.error('');
24
+ console.error(' Alternative: use the one-command installer that handles Bun for you:');
25
+ if (isWindows) {
26
+ console.error(' irm https://raw.githubusercontent.com/autoctxd/autoctxd/main/scripts/install.ps1 | iex');
27
+ } else {
28
+ console.error(' curl -fsSL https://raw.githubusercontent.com/autoctxd/autoctxd/main/scripts/install.sh | bash');
29
+ }
30
+ console.error('');
31
+ process.exit(1);
32
+ }
33
+
34
+ const cliPath = path.join(__dirname, '..', 'src', 'cli', 'index.ts');
35
+ const args = process.argv.slice(2);
36
+
37
+ const result = spawnSync('bun', [cliPath, ...args], {
38
+ stdio: 'inherit',
39
+ shell: process.platform === 'win32',
40
+ });
41
+
42
+ process.exit(result.status ?? 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autoctxd",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Persistent, local, zero-API memory for Claude Code.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -27,7 +27,7 @@
27
27
  "benchmark:embeddings": "bun run scripts/benchmark-embeddings.ts"
28
28
  },
29
29
  "bin": {
30
- "autoctxd": "src/cli/index.ts"
30
+ "autoctxd": "bin/autoctxd.cjs"
31
31
  },
32
32
  "keywords": [
33
33
  "claude",