Skip to main content

ctxmem banner

ctxmem

Git-native, shareable project memory for AI coding agents — fully local, no cloud.

Test Lint License: MIT Python Dependencies MCP


ctxmem gives your project a permanent, searchable memory that lives inside the repo. AI agents (and you) store decisions and recall relevant context on demand, so nothing is forgotten when a chat exceeds the model's context window.

  • 🧠 Remembers — decisions, notes, sessions + your code, in a searchable index.
  • 🔎 Self-checkingctxmem ask tells the agent whether memory already knows (HIT / WEAK / MISS) before it answers.
  • ♻️ Self-correcting — supersede an outdated decision (--supersedes); recall demotes and flags it (⚠ SUPERSEDED / ⚠ STALE).
  • 🤝 Shareable — the memory is a text file committed to git. Commit, your colleague pulls, they get your exact context. Branch-aware for free.
  • 📦 Works as a git packagepip install git+https://…, zero required deps.
  • 🔒 Fully local — SQLite files in your repo. No cloud, no API keys, no servers.
  • 🔍 Search modeskeyword (built-in, default) plus semantic / hybrid (local embeddings, no cloud).

ctxmem demo: init, remember, sync, recall

How it works, in one line: a committed, human-readable memory.jsonl is the source of truth; a local, gitignored SQLite index makes it (and your code) instantly searchable. For the full design, see docs/ARCHITECTURE.md.


Install

pip install "git+https://github.com/DoppiaG93/ctxmem.git"   # as a git package
# or, from a clone:  pip install -e .

# optional extras
pip install "ctxmem[mcp]"        # AI-agent server (MCP)
pip install "ctxmem[semantic]"   # semantic search (needs Ollama too)
pip install "ctxmem[all]"        # everything

Requires Python 3.8+ with FTS5 (bundled in virtually every sqlite3 build). The base install has zero third-party dependencies.

Quick start

cd your-project

ctxmem init                                   # creates .ctxmem/
ctxmem hook install                           # auto-sync the index on every commit
ctxmem remember --type decision \
  --title "Auth via JWT" --tags auth,security \
  "We chose stateless JWT over server sessions for horizontal scaling."

ctxmem sync                                   # index memory + your code
ctxmem ask "how do we handle authentication"      # verdict: HIT / WEAK / MISS
ctxmem recall "how do we handle authentication"   # ask in plain language
ctxmem recall "cart" --type symbol            # search only code symbols

Then commit the memory so it's shared:

git add .ctxmem/memory.jsonl .ctxmem/config.json
git commit -m "chore: seed project memory"

Your colleague just git pulls and runs ctxmem recall — the index rebuilds itself from memory.jsonl. For the full onboarding story (agent wiring, handing memory to a teammate), see docs/GUIDE.md.

Commands

Command What it does
ctxmem init [--mode M] Create .ctxmem/ and pick a search mode.
ctxmem remember "text" [--type --title --tags --path --supersedes ID] Store a memory (→ memory.jsonl); prints the new record's id. Types: note, decision, session, todo. --supersedes ID corrects/replaces an earlier memory.
ctxmem recall "query" [--limit --type --mode] Search memory + code. Superseded records are demoted + flagged ⚠ SUPERSEDED; memories pointing at a missing file are flagged ⚠ STALE.
ctxmem ask "question" [--limit --type --mode] Recall plus a ranked verdict: HIT for a relevant active answer memory, WEAK for related code/maps/low-overlap memories, or MISS.
ctxmem sync Rebuild index.db from memory.jsonl + code (+ embeddings if enabled).
ctxmem map Save a structure + Python import map into memory (--type map). Great first step so agents know the layout.
ctxmem mode [M] Show, or switch to, keyword / semantic / hybrid.
ctxmem log [--limit] List recent memories.
ctxmem status Branch/commit, mode, and counts of indexed items.
ctxmem doctor Check the semantic (Ollama) backend end to end, with fix-it hints.
ctxmem hook install/uninstall Add/remove a git post-commit auto-sync hook.
ctxmem agent-init [--agent copilot|codex|all] [--mcp] [--force] Wire up agents: write the memory protocol into instruction files (+ .vscode/mcp.json with --mcp).
ctxmem update-instructions [--mcp] Refresh the managed instruction block(s) after upgrading ctxmem.
ctxmem bench "query" [--baseline files|memory|repo] Measure token and premium-request savings. Add --suite FILE --report DIR for a full report with charts.
ctxmem --root PATH … Run against a repo other than the current directory.

Use it from an AI agent

Wire an agent (Codex, GitHub Copilot) to the memory in one command:

ctxmem agent-init --agent all        # write the memory protocol into AGENTS.md + copilot-instructions.md
ctxmem agent-init --agent all --mcp  # also drop a .vscode/mcp.json (MCP server)

This injects a Project Memory Protocol that tells the agent to recall before a task, remember decisions, and sync after changing code — so the memory grows by itself. Full details (CLI vs MCP, requirements, tips) in docs/GUIDE.md → Use it from an AI agent.

Semantic search (Ollama)

Keyword mode is the stable, zero-setup default. Optional semantic and hybrid modes match by meaning using a fully-local embedding model:

pip install "ctxmem[semantic]"
# Option A: install Ollama on the host, then:
ollama pull nomic-embed-text
ctxmem mode semantic
ctxmem doctor                        # verify the whole chain end to end

# Option B: run Ollama in an isolated Lima VM:
cd ollama && task enable             # brings the VM up + switches to semantic

If the backend isn't available, ctxmem automatically falls back to keyword. Setup options, the Lima VM, and ctxmem doctor output are documented in docs/GUIDE.md → Semantic backend.

Why it saves tokens

Instead of pasting whole files into the model, you inject only the relevant recall snippets. Measured on the Django source tree:

Metric Without ctxmem With ctxmem Improvement
Context tokens (13 questions) 272,354 14,028 19.4× smaller
Premium requests (round-trips) 49 13 3.8× fewer

Full methodology and reproducible steps: docs/ARCHITECTURE.md → Benchmark.

Documentation

  • docs/ARCHITECTURE.md — the problem, the data model, the retrieval pipeline, project structure, search-mode internals, and the benchmark.
  • docs/GUIDE.md — full walkthrough, team sharing, the git hook, AI-agent integration (CLI + MCP), and the semantic/Ollama backend.

FAQ

Is my data sent anywhere? No. Everything is local: SQLite files in your repo and, if you enable semantic mode, a local Ollama.

Do I have to use embeddings? No. keyword mode needs nothing and is the default. Semantic is opt-in.

Should I commit index.db? No — it's derived and gitignored. Commit memory.jsonl and config.json.

What if a teammate doesn't have Ollama? ctxmem falls back to keyword automatically; the shared memory still works.

Does it scale to a big repo? Yes. The keyword index is fine for large repos, and semantic mode is incremental — embeddings are cached by content hash (.ctxmem/emb_cache.db), so a sync only re-embeds new or changed text.

Is MCP proprietary? No. MCP is an open protocol with MIT-licensed SDKs; the server runs locally and reads only your repo.

Contributing

Contributions are currently invite-only. The project is developed by a small set of invited collaborators, so unsolicited pull requests are not accepted right now — but bug reports and feature requests are always welcome via GitHub issues. To contribute code, reach out to @DoppiaG93 to be added as a collaborator.

Invited collaborators follow the Git Flow branching model; see the Contributing guide for branch naming, commit conventions, and the release process. Please also review our Code of Conduct. To report a security issue, follow the Security Policy.

License

Released under the MIT License.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ctxmem-2.0.3.tar.gz (40.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ctxmem-2.0.3-py3-none-any.whl (34.3 kB view details)

Uploaded Python 3

File details

Details for the file ctxmem-2.0.3.tar.gz.

File metadata

  • Download URL: ctxmem-2.0.3.tar.gz
  • Upload date:
  • Size: 40.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for ctxmem-2.0.3.tar.gz
Algorithm Hash digest
SHA256 882eb0ffdc9ae743521c01c5af0aa3a6b7fa901e995a7a15166f7cb8d3388caa
MD5 039d366fbec283699b246241b9975cc2
BLAKE2b-256 05d9cca610ed688568fd57a28989412aaad86c569f474f988714b18a871b6f31

See more details on using hashes here.

Provenance

The following attestation bundles were made for ctxmem-2.0.3.tar.gz:

Publisher: publish.yml on DoppiaG93/ctxmem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ctxmem-2.0.3-py3-none-any.whl.

File metadata

  • Download URL: ctxmem-2.0.3-py3-none-any.whl
  • Upload date:
  • Size: 34.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for ctxmem-2.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0b1dd16afb568d72d05748bb22ea14c90c1a98d6df56dd1e628ba1642caa04aa
MD5 843c3dbfd4e7c0fa84cf702a08726226
BLAKE2b-256 4d302b1c61b9b3f7eb9fef7c9dc197eb413320d33f2ff04e9e9ed3a3fb4ecc89

See more details on using hashes here.

Provenance

The following attestation bundles were made for ctxmem-2.0.3-py3-none-any.whl:

Publisher: publish.yml on DoppiaG93/ctxmem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

2.1.0

2 files

This release

2.0.3 This release

2 files

2.0.1

2 files

2.0.0

2 files

1.4.3

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page