A shared workspace memory a team's AI agents ask first and teach back: fewer model requests at the same accuracy.
pip install model-d==0.5.1 Copy PIP instructions
AI on your codebase, with a bill that flattens as your team works.
Every AI coding agent on a team pays to search the same code again, and each search step is a paid model request. Model D is a deterministic kit fused with the Claude API you already use:
Where the saving comes from. On Django's real 2022 year (285 paired fixes) it was 2.09x, with a 95% interval of 1.84x–2.39x:
Memory makes repeated questions cheap. It does not make Model D better at brand-new questions. modeld cover, which teaches it the whole codebase once, is what does that.
uv tool install "model-d[claude]" # or: pipx / pip install "model-d[claude]"; plain model-d skips the Claude SDK modeld install # wires it into Claude Code, Codex, Gemini CLI and Kiro modeld build . --cache ~/.cache/modeld/embed.sqlite # maps this repository; rebuilds embed only what changed modeld cover # optional: teaches it the whole codebase once (about $1 per 24k pieces) Test it on your own repository first (no API key, nothing leaves your machine) cd your-repo modeld forecast . # from your git history alone: how much of your fix work repeats, and the bill it predicts modeld prove . # replays your last 50 bug fixes against the code right before each one: does Model D find the # file and the lines the fix really changed? Side by side with a grep-first look. Zero tokens. Both commands read your repository locally. prove downloads the embedding model once (about 440 MB) and embeds your code on your machine: the first build takes minutes on a large repository, the rest take seconds.
Every plan was hashed before it ran, and python evidence/verify.py recomputes every number from the raw rows.
Model D adds no model cost of its own. It cuts the API bill you already pay. For a team server, Docker and offline installs, see DEPLOY.md. To get the most out of it, see GUIDE.md.
Ten years of Django, 5,333 real fixes, touched only 650 files. After the first thousand fixes, 96–99% landed in a file already fixed before. The files a team touches grow like the square root of its work (Heaps' law, fitted: D(n) = 12·n^0.48). So the search for where to look should be paid once. The learning law says how much that saves: S = A / ((1 − ν)·E + ν·K), where ν is the share of new work, E one learned read ($0.0004) and K a first exploration with the kit. On Django's 2022 it forecast each quarter's saving from the earlier ones within 14%.
uv tool install model-d # or pipx install model-d, or pip install model-d; from a clone: pip install -e . This installs the modeld command (and modeld-mcp), with numpy, torch and transformers. python -m ocm runs the same commands. The embedding model (bge-base-en-v1.5) downloads once on the first build; after that you can set OCM_OFFLINE=1.
modeld build ~/code/our-api ~/code/our-web ~/code/our-docs --out ~/ocm-workspace What gets kept: every code and doc file under the folders you pass. Code is cut into blocks and docs into sentences, and each becomes a 1,024-bit fingerprint, computed on your machine. What is skipped: .env files, keys, certificates, credential files, lockfiles, dependency and build folders, and anything over 512 KB. Also indexed: build files with no extension (Dockerfile, Makefile and the like), .conf, .mjml, .vscode. Doc sentences keep their line numbers. Device: a GPU is used automatically when present (CUDA, or Apple silicon); --device cpu forces the CPU. Rebuilding after code changes? Carry what the team taught into the new workspace:
uv tool install "model-d[claude]" # cover calls Claude Haiku through the Anthropic SDK export ANTHROPIC_API_KEY=... # or OCM_VERTEX_PROJECT for Claude on Vertex AI modeld cover --workspace ~/ocm-workspace What it does: Claude Haiku writes one question for every piece of non-test code, 25 pieces per request. Each question is taught onto the code it was written from, as a pointer: nothing is stored as an answer. An asked question is pointed at code, and the agent reads that code. What it costs: it shows an estimate and asks before spending (--yes skips the prompt, --cap sets a limit). For Django's 23,976 pieces it cost $0.97, and teaching took 10 minutes on a laptop. What it did: on 288 real Django fix questions it had never seen, the right file came first 142 times against 111 cold (p = 0.0035) (evidence/team-year/coverage). In 0.5.1, a taught pointer no longer hides the rest of the readout, and the top 5 rose to 219, against 197 cold. A learned pointer is right about half the time, so the agent still checks the code it is pointed at. After a rebuild: pointers carry like any taught question. Running modeld cover again writes questions only for code that is new or changed. 3. Serve it to the team modeld serve ~/ocm-workspace --port 7700 # just you modeld serve ~/ocm-workspace --port 7700 --host 0.0.0.0 # your team, on your network Run one server per team; everyone's agents share it. Every call is logged to /calls.jsonl.
For a bug report, or any question whose answer is in code, ask with "scope": "code". Documentation (.md, .rst, .txt and the like) then stays out of the ranking. In a full repository, release notes and reference pages can otherwise fill much of the readout. OCM_SCOPE=code makes it the server's default; the MCP tools take scope too.
One command per agent. ocm init writes the right config into a repository. It merges into existing files, keeps your other settings, and is safe to run again:
modeld init claude ~/code/our-api --url http://ws.internal:7700 # Claude Code: two hooks + a CLAUDE.md note modeld init kiro ~/code/our-api --url http://ws.internal:7700 # Kiro: .kiro/settings/mcp.json + .kiro/steering/ocm.md modeld init codex ~/code/our-api --url http://ws.internal:7700 # OpenAI Codex: .codex/config.toml + AGENTS.md modeld init gemini ~/code/our-api --url http://ws.internal:7700 # Gemini CLI: .gemini/settings.json + GEMINI.md modeld init all ~/code/our-api --url http://ws.internal:7700 # all four What each writes, by hand, follows.
Claude Code (recommended): two hooks, nothing for the model to call. Add this to the project's .claude/settings.json, and point OCM_URL at the team's server if it is not local:
{"env": {"OCM_URL": "http://127.0.0.1:7700"}, "hooks": { "UserPromptSubmit": [{"hooks": [{"type": "command", "command": "modeld hook prompt"}]}], "Stop": [{"hooks": [{"type": "command", "command": "modeld hook stop"}]}] }} Before each request, the prompt hook adds the code its laws rank for the question: the code a taught question's vector points to (and then the router's next readout), or the nearest code and docs by meaning and keyword. The model answers from them when they answer the question, searches when they do not, and ends its reply with TEACH: | : , the line its answer is on. After the reply, the stop hook teaches those lines on your machine, at no model cost: each question's vector becomes a cue on the code holding that line. No answer text is stored. Between tasks, run /clear. The next task starts from the workspace, not from the old transcript. Cursor and other MCP clients: as tools. Add this to .mcp.json (Cursor: .cursor/mcp.json), and add pilot/AGENT_INSTRUCTIONS.md to the agent's rules:
{"mcpServers": {"ocm": {"command": "modeld", "args": ["mcp"], "env": {"OCM_URL": "http://127.0.0.1:7700"}}}} This costs a round trip per question, and in our team proof it did not save requests on its own (section 6). Use the hooks where you can.
Kiro, OpenAI Codex, Gemini CLI: as MCP tools. ocm init kiro|codex|gemini registers the same four tools in each tool's own MCP config, and puts the instructions where that agent reads them (.kiro/steering/, AGENTS.md, GEMINI.md).
Any other agent loop: call ocm.loop.prefetch(question) before the model call, put the result in the prompt, and call ocm.loop.teach_from_reply(reply) after it.
ocm hybrid runs a question through the hybrid. The kit's laws make every decision, at no model cost, and a model is called only for one of two jobs:
export OCM_URL=http://ws.internal:7700 modeld hybrid "What stops a deploy with placeholder secrets?" --provider claude # ANTHROPIC_API_KEY modeld hybrid "..." --provider openai # OPENAI_API_KEY (pip install openai) modeld hybrid "..." --provider gemini # GEMINI_API_KEY, or a Vertex project Provider Reads with Teaches with Keys claude (Anthropic SDK) Claude Haiku 5.5 Claude Sonnet 5.5 ANTHROPIC_API_KEY, or OCM_VERTEX_PROJECT for Claude on Vertex AI openai (OpenAI SDK) --reader, default gpt-5.6-terra --teacher, same default OPENAI_API_KEY gemini (REST) gemini-2.5-flash gemini-2.5-flash GEMINI_API_KEY, or OCM_VERTEX_PROJECT In code: from ocm.hybrid import run, provider, Workspace, then run(question, provider("claude"), Workspace("http://ws.internal:7700")). It returns the path taken (read or teach), the answer, the line taught, and the number of model requests. Measured so far (gemini-2.5-flash): one read was right on 90/90 taught questions, and on 30/30 with Claude Haiku 5.5. The Gemini adapter has been run live end to end. The Claude and OpenAI adapters are covered by the offline tests, but have not yet been run against their live APIs.
modeld calc --repeat 0.5 --deep 0.3 --questions-per-month 16800 # an estimate for your mix modeld measure compare ~/before-transcripts ~/after-transcripts # the real thing, from your agents' transcripts pilot/PILOT.md is a two-to-four-week plan for a fair before-and-after; fix it before you start (pilot/PREREGISTRATION.md). Run the kit's tests with python -m pytest -q tests.
What we measured with this kit on a MacBook (Apple silicon; its GPU was picked automatically):
The workspace is a CMLM: vectors and laws, not a store of text.
Teaching trains the CMLM on your machine, at no model cost. A TEACH line names a question and the line its answer is on. The question's vector becomes a cue on the unit holding that line, so a later question near it in meaning is drawn to that code (vector generalisation), and it is an example for the learned law.
It is ranking math. The readout is ranked, not verified, so the model is told to use it only if it answers the question.
Everything runs on your machines. Only the embedding model is downloaded, once; your code and questions never leave your network.
Model D's retrieval is compared with Graphify on LOCOMO and on finding the file a fix changed. On 285 SWE-bench Lite issues in 12 full repositories, with the code scope and the test plan fixed before it ran, Model D listed the fixed file in its first five 176 times (issue titles) and 183 times (title + 400 characters), against 131 and 122 for Graphify 0.9.87, with about 2.4x fewer tokens (evidence/swe-bench-lite/). The study is reproducible, and the Claude Code plugin is in the same repository: https://github.com/devkancheti4-design/model-d-graphify
Kancheti, D. (2026). Optimal Context Mapping (Model D): a shared, learning retrieval layer for AI coding agents (Version 0.2.1) [Computer software]. Zenodo. https://doi.org/10.5281/zenodo.23289068
CITATION.cff has the same citation, and the DOI for all versions is 10.5281/zenodo.23289067.
All 2 files in this release have provenance metadata.
ai-agents coding-agents claude mcp code-search retrieval context tokens
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
All 2 files in this release have been uploaded with provenance metadata.
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.




