ctxkeeper
A local-first MCP server for durable project memory and token-budgeted context retrieval.
Get a session-start
project_briefwith stack, commands, files to read first, git state, TODOs, decisions, gotchas, and recent work.Save durable memories as decisions, gotchas, facts, commands, todos, or notes, with tags, related files, importance, and project/global scope.
Search saved memories with keyword/CJK-aware
recall, filtered by type, tag, scope, done/archived status.Archive or restore memories with
forget.Manage a durable project todo list: add, list, mark done, or reopen items.
Log completed work with summary, files, commands, outcome, next steps, and duration.
Generate a token-budgeted
context_packof relevant code excerpts withpath:linecitations plus matching memories.Inspect server/project status, detected root, store paths, counts, git state, and limits.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@ctxkeeper pull the project brief and open TODOs so I can get up to speed"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
ctxkeeper is a local-first MCP server that gives AI coding agents durable project memory and token-budgeted context packs.
No API keys. No vector database. No telemetry. One node process, one append-only file.
Agent → project_brief
← stack · run/test commands · files to read first · git state
open TODOs · decisions · gotchas · recent work ~1.2k tokens
Agent → context_pack("where is the OAuth token refreshed?")
← src/auth/refresh.ts:42-78 + the decision that explains it ~1.5k tokens
Agent → remember(type="gotcha", ...) # survives the session
Agent → log_work(summary=..., next_steps=...) # hands off to tomorrowThe problem
Every new agent session starts cold:
You re-explain the architecture, the constraints, and the command that actually runs the tests.
The agent greps the repo, reads whole files, and burns thousands of tokens to find 30 lines.
Decisions and gotchas live in yesterday's chat, not in the project.
Switch from Claude Code to Cursor to OpenCode and all context is gone again.
Most MCP servers add more tools. ctxkeeper makes the tools you already have need less context.
Related MCP server: Sugar Memory
What you get
Tool | R/W | What it does |
| read | Stack, commands, files to read first, git, TODOs, decisions, gotchas, recent work — one call |
| read | Given a concrete question, returns only the relevant code windows ( |
| read | Keyword + CJK-aware search over saved memories, ranked by field, importance, and recency |
| write | Persist a decision, gotcha, fact, command, todo, or note; identical entries are deduplicated |
| write | Durable add / list / done / reopen across sessions |
| write | Archive a memory; |
| write | Timestamped work log: summary, files, commands, outcome, next steps |
| read | Detected root, store paths, counts, git state, limits |
Also exposed: resource ctxkeeper://brief, prompt onboard, and server instructions that describe the workflow at handshake time.
Why another MCP server?
The ecosystem has plenty of connectors. The 2026 survey data shows ~47k active servers in the official registry, but the scarce layer is context:
Layer | Examples | Supply |
L1 Connect | filesystem, GitHub, browser, databases, SaaS | saturated |
L2 Operate | deploy, open PRs, update tickets | crowded |
L3 Domain workflow | finance, legal, recruiting | scarce, data-gated |
L4 Context | remember the project, pick the right lines, budget tokens, hand off | underserved |
ctxkeeper is deliberately L4. It does not replace your GitHub or Playwright server; it reduces how often the agent needs them.
Design choices that follow from that:
Append-only JSONL, not a database. No native build, crash-tolerant, multi-client friendly, auditable, and
forgetis reversible.Memory bridges language. A Chinese question can retrieve English code: memories contribute file paths and identifiers (e.g.
refreshToken) as bridge terms for window selection.Code blocks are never cut in half. Each file gets a budget; if it does not fit, use the single best window or skip it and say so.
Read-only by construction. No arbitrary shell. The only subprocess is fixed-argument, read-only
git.Sensitive files never enter context.
.env*, keys, credentials, and common token shapes are skipped or redacted.
Quick start
Requires Node.js >= 20.11.
git clone https://github.com/Coisini-cyber/ctxkeeper-mcp.git
cd ctxkeeper-mcp
npm install # also builds via the prepare script
npm test # 11 end-to-end tests over real stdio
npm run demo -- . "how does the store work"demo prints status, project_brief, and one context_pack, so you can judge the output quality before wiring it into a client.
No clone? Point your MCP client at the repository directly (it builds on first run):
npx -y github:Coisini-cyber/ctxkeeper-mcpRunning that in a terminal will look like it hangs — it is a stdio server waiting for a client.
The same binary is also a small CLI, useful for checking output without an MCP client:
node dist/index.js --brief
node dist/index.js --pack "where is the token refreshed?"
node dist/index.js --doctorConnect to OpenCode
Add this to your global config, ~/.config/opencode/opencode.json (on Windows: C:\Users\<you>\.config\opencode\opencode.json):
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"ctxkeeper": {
"type": "local",
"command": ["node", "/absolute/path/to/ctxkeeper-mcp/dist/index.js"],
"enabled": true,
"timeout": 20000
}
}
}Do not set cwd: the server detects the project root from the workspace, so one entry works in every repository.
If you prefer not to clone, use "command": ["npx", "-y", "github:Coisini-cyber/ctxkeeper-mcp"]. It builds on first run and is slower to start; the local path is recommended for daily use.
Verify:
opencode mcp list
# ✓ ctxkeeper connectedTools appear as ctxkeeper_project_brief, ctxkeeper_context_pack, and so on.
For project-only setup, put the same mcp block in the repository's opencode.json.
Any other MCP client
{
"mcpServers": {
"ctxkeeper": {
"command": "node",
"args": ["/absolute/path/to/ctxkeeper-mcp/dist/index.js"]
}
}
}Step-by-step configs for Claude Code, Claude Desktop, Cursor, VS Code, and Windsurf: docs/clients.md.
Make the agent actually use it
Different clients weight server instructions differently. Add a hard rule to your AGENTS.md / CLAUDE.md:
## Project memory (ctxkeeper)
- At the start of every session, call `ctxkeeper_project_brief` before reading files or grepping.
- To locate code, call `ctxkeeper_context_pack` with a concrete question, then read only the cited `path:line` ranges.
- Save confirmed decisions and gotchas with `ctxkeeper_remember`; track multi-step work with `ctxkeeper_todo`.
- Before finishing, call `ctxkeeper_log_work` with what changed, files touched, and next steps.
- Never store secrets, tokens, or full source files in memories.A real project_brief
Abridged output from this repository after a day of work:
# Project brief: ctxkeeper-mcp
D:\mcp\ctxkeeper · no git · 2026-11-02 13:44
stack: TypeScript 88% · JavaScript 12% · 17 files · ~2.9k LOC
read first: `src/index.ts`, `README.md`
## Commands
- build: `npm run build`
- test: `npm run test`
- demo: `npm run demo`
## Open TODOs (2)
- [m_mvzb4ptlyn1kf] **Add an incremental file index** — avoid a full scan on every pack
- [m_mvzb4pug8vf7k] **Compact the event log** — snapshot + tail after tens of thousands of events
## Decisions (4)
- [m_mvzb7yweonhbc] **Bridge Chinese questions to English code** — memories contribute file paths and identifiers
- [m_mvzb4psxlo7qq] **Read-only code access, skip sensitive files** — no arbitrary shell; redact high-confidence secrets
- [m_mvzb4ps1k9vm8] **Never truncate a code block mid-line** — fall back to the best window or skip
## Gotchas (1)
- [m_mvzb4prdcpo9j] **The user's home directory is a git repo** — never adopt home/temp as the project root
## Recent work
- 2026-11-02 [success] Shipped ctxkeeper: event-sourced memory, brief, context pack, 11 e2e tests
· next: incremental index; event-log compaction; one-week field testThat is the entire onboarding for a new session.
Measured on this repo
Small repo, Windows 11, Node 22.23 — a pipeline check, not a benchmark:
Operation | Latency | Output |
| ~10 ms | 0.5–1.2k tokens |
| ~8–10 ms | ~1.0k tokens, 2–4 cited windows |
Reading | — | ~3.5–4k tokens |
The gap grows with file size: context_pack returns the 30 lines around the answer, not the 430-line file.
How memory is stored
project/
├─ src/
├─ package.json
└─ .ctxkeeper/ # created automatically
├─ .gitignore # contains "*" — memories are not committed
└─ events.jsonl # append-only event logEvery write is an event: memory.add, memory.archive, memory.unarchive, todo.set, worklog.add. Reads replay the log. This avoids native dependencies, survives crashes, lets multiple clients append safely, and makes archiving and completion reversible.
Global memories (cross-project preferences) live in ~/.ctxkeeper/global/.
Security and privacy
No network calls. No accounts, keys, telemetry, or cloud storage.
Read boundary: only text files inside the detected project root; skip
node_modules,.git,dist,build,target, virtualenvs, and similar.Sensitive files:
.env*,*.pem,*.key,id_rsa*,credentials,secrets.*are excluded from code search.Redaction: private key blocks,
sk-…,ghp_…,AKIA…,xox…are redacted from output.No arbitrary execution. The only subprocess is read-only
gitwith fixed arguments.Caveat: the store is plain text. Do not save secrets. Treat repository content as untrusted data, not instructions.
See SECURITY.md for reporting.
Configuration
Environment variable | Default | Purpose |
| auto-detected | Force the project root (absolute path) |
|
| Project memory directory |
|
| Global memory directory |
|
| Max size of a file read into context |
| unset | Set to |
Root detection order: CTXKEEPER_ROOT → nearest .ctxkeeper or project manifest (package.json, pyproject.toml, Cargo.toml, go.mod, …) → nearest .git (home and temp directories are never adopted) → cwd.
Limitations
Retrieval is lexical (identifiers + CJK bigrams), not embeddings. Try different keywords if
recallmisses.Large repositories are capped at 6,000 files / 24 MB per scan.
The event log does not compact itself yet.
No team sync, encryption, or per-user permissions. Built for individuals and small teams.
Memory quality depends on write quality: short titles, concrete content, file paths.
Roadmap: incremental index → event-log compaction → optional local embeddings with lexical fallback → “recently changed files → related memories” in the brief.
See docs/alternatives.md for an honest comparison with AGENTS.md, the official Memory server, mem0/Letta, Graphify/Serena, and Context7. See docs/research.md for the full 2026 MCP landscape and why this layer is underserved. docs/architecture.md explains the event log, retrieval pipeline, and extension points.
FAQ
Does it work with Claude Code / Cursor / Windsurf? Any client that supports local stdio MCP servers can run it. The examples use OpenCode, but the server itself has no client-specific code.
Does it replace AGENTS.md / CLAUDE.md?
No. Those are static instructions you maintain by hand. ctxkeeper adds dynamic project state (decisions, gotchas, TODOs, recent work) and retrieves only the relevant parts.
Does my code leave the machine? No. There are no network calls, no accounts, and no telemetry. Code excerpts are read locally and returned to the client you already use.
Why not embeddings? v0.1 deliberately trades semantic recall for zero install friction and offline operation. Lexical retrieval plus identifier/CJK tokenization covers concrete questions; an optional local embedding backend is on the roadmap.
Is the memory committed to git?
No. .ctxkeeper/.gitignore contains *, so the store stays local by default. Delete that file if you want to commit curated memories.
How large a repo can it handle? Scans are capped at 6,000 files / 24 MB per call. Small and medium repositories are fine; very large monorepos need the incremental index on the roadmap.
Contributing
Issues and PRs are welcome. Start with CONTRIBUTING.md. The invariants are: local-first, no native deps, read-only code access, token-aware output, reversible writes.
If ctxkeeper saves you a few thousand tokens today, star the repo — it helps other developers find it.
License
MIT © 2026 Sixian Deng
Available Tools
8 toolscontext_packPack relevant contextARead-onlyIdempotent
Given a concrete question, return a token-budgeted pack of the most relevant code excerpts (with path:line citations) plus matching project memories. Use this BEFORE broad greps or reading whole files; it cuts token use and round trips.
Inputs: query (required), max_files, budget_tokens, include_memories.
forgetArchive or restore a memoryADestructiveIdempotent
Archive a memory by ID so it stops appearing in briefs and recall. Archive is reversible: pass restore=true with the same ID. Use when a decision is superseded or a note is wrong.
Inputs: id (required), scope, restore.
log_workLog completed workA
Append a short, timestamped work-log entry (what changed, which files, commands, outcome, next steps). Call this before ending a session so the next agent can resume without re-reading everything.
Inputs: summary (required), files, outcome, commands, +2 more.
project_briefProject brief (call first)ARead-onlyIdempotent
Start here. Returns a token-budgeted brief for this project: detected stack, run/test commands, files to read first, git state, open TODOs, decisions, gotchas, and recent work logs. Replaces exploratory file reads at session start.
Inputs: refresh, budget_tokens.
recallRecall project memoryARead-onlyIdempotent
Search saved memories with keyword/CJK-aware ranking (title, tags, files, content; importance and recency weighted). Filter by type, tag, or scope. Use before asking the user to repeat context.
Inputs: tags, limit, query, scope, +3 more.
rememberRemember a durable factAIdempotent
Persist a decision, gotcha, fact, command, todo, or note to the local project store (or global store). Use this whenever the user states a preference, you make a non-obvious choice, or you discover something future sessions should know. Identical entries are deduplicated.
Inputs: type (required), title (required), content (required), tags, +5 more.
statusServer and store statusARead-onlyIdempotent
Show the detected project root, store paths, memory/todo/worklog counts, git state, and limits. Use when setting up the server or debugging why nothing is recalled.
Inputs: no named parameters.
todoProject todosB
Manage the durable project todo list. action=add needs title; action=list shows open items (set include_done=true for all); action=done/reopen needs id. Todos survive sessions and appear in project_brief.
Inputs: action (required), id, tags, limit, +4 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 8 tools
Most tools have distinct roles: remember/recall/forget form a clear memory lifecycle, todo manages a separate list, and log_work and status are unambiguous. project_brief and context_pack both return token-budgeted context, but their scopes (session-start overview vs question-specific excerpts) are described well enough to distinguish them.
The set mixes simple verbs (remember, recall, forget), noun-like names (todo, status), and compound names (project_brief, log_work, context_pack). No single predictable convention is followed, though all names are readable and mostly snake_case.
Eight tools is well-scoped for a project-context memory server, with each tool covering a distinct operation. There is no obvious bloat or missing essential capability at this count.
The surface covers memory creation, search, archival with restore, todos, work logs, briefs, status, and context packing, providing solid lifecycle coverage. Minor gaps exist, such as no direct memory-edit operation or bulk cleanup beyond archiving by ID.
Maintenance
Related MCP Connectors
Shared memory for coding agents. Stop re-explaining your codebase every session.
One shared project memory for your AI coding tools: recall, save and brief decisions anywhere.
Shared, scoped, reviewable team memory for AI coding agents.
Shared project memory that keeps teammates and AI agents aligned across sessions.
Related MCP Servers
- AlicenseAqualityDmaintenanceLong-term memory for AI coding assistants. Remembers context once and recalls it across sessions.724MIT
- FlicenseNot gradedqualityAmaintenanceProvides AI coding agents with a local-first persistent memory layer they can read and write during sessions, storing decisions, preferences, error patterns, and research per project or globally. Enables semantic and keyword search, formatted context recall, and cross-project guideline surfacing without API keys or cloud storage.-
- FlicenseNot gradedqualityAmaintenanceEnables AI coding agents to read and write persistent project-scoped and cross-project memory during sessions, using local semantic search to surface relevant decisions, preferences, error patterns, and guidelines across sessions. It also optionally exposes an autonomous task queue that draws on that same stored context.-
- AlicenseNot gradedqualityAmaintenanceEnables AI coding assistants to persistently save, search, and restore project context across sessions, including decisions, progress, file caches, checkpoints, and channel-based memory. It supports git-aware organization, batch operations, and shared memory across parallel sessions.150 npmMIT