🤔 The problem, in one table
Every new chat with a coding agent starts with amnesia. To answer "where is X?" or "how do we deploy?" it greps, opens big files, reads them... and next session it does it all over again.
Median characters per task on the held-out benchmark (targeted-grep and grep-and-read baselines vs knock). Fewer characters ≠ an identical cut in your bill; see the FAQ.
⚡ Getting started
You set knock up once, then you just keep using your AI agent as usual. The agent talks to knock in the background; you never have to run knock commands day to day.
1️⃣ Connect it to Claude Code (once per project)
From inside the project you work on:
This uses uv, which downloads and runs knock for you. No uv? Run pipx install knock-mcp (or pip install knock-mcp), then claude mcp add knock -- knock serve --repo . --toolset map.
--toolset map gives the agent three tools (map, open, remember) and is the setup measured in the results below. Leave it out to get the original eight tools.
That's the whole setup. The next time you open Claude Code in that project, knock reads the project and builds its notes automatically. This takes a few seconds for a small project and a minute or two for about 5,000 files; after that it only re-reads files that changed.
[!TIP]
Add this line to your project's CLAUDE.md so the agent uses knock when it pays off:
"Before exploring the repo (how/why questions, unclear bugs, changes across modules, code you can't find with one search), call knock's map tool with your task. For small edits you can locate with one grep, skip it. Save non-obvious findings with remember."
In our recordings, knock saved money on investigations in a large codebase but added a small cost to quick edits, so this line matters.
2️⃣ Work normally
Ask your agent what you'd always ask. Here's what changes behind the scenes:
Nothing to maintain: when code changes, knock updates its notes, and flags anything that may be outdated.
🖥️ Optional: use knock yourself from the terminal
You never need these, but they're handy.
Want knock to ignore some files? List them in a .knockignore file (same format as .gitignore).
👥 Setting it up for a whole team
Commit a .mcp.json file to your repo, and every teammate's Claude Code picks up knock automatically (each person needs knock installed):
Each person's notes live on their own machine. Sharing findings across a team isn't supported yet (see Status below).
🧠 How it works
- Index: knock reads your repo without running anything in it. It writes short notes: what each module defines, what the docs say about setup and deployment, which tools and dependencies you use, why decisions were made, and which recent commits fixed bugs.
- Ask: your agent asks a question and gets a small, ranked answer with
file:line pointers, instead of reading whole files.
- Verify: before editing, the agent reads just the lines it needs. The original files are always the source of truth.
- Remember: the agent saves what it learned. If those files change later, knock marks the note stale so nobody trusts outdated info.
🧰 What your agent gets
With --toolset map (recommended):
The original 8-tool set (default without --toolset map)
👀 See a real example session (8-tool set, Flask)
On Flask, an agent is told: "sessions signed with an old key in SECRET_KEY_FALLBACKS are rejected after rotating SECRET_KEY".
get_context returns ~7.7 KB containing:
src/flask/sessions.py:317: SecureCookieSessionInterface.get_signing_serializer
tests/test_basic.py:374: test_session_secret_key_fallbacks
- related commits
fb54159861 secret key rotation: fix key list ordering and e13373f838 enable secret key rotation
- the docs sections on sessions and secret keys
get_source("src/flask/sessions.py", symbol="get_signing_serializer") returns the ~80 relevant lines, not the whole file.
record_knowledge saves the finding:
The next session gets it instantly. If sessions.py changes, the note is flagged stale.
📊 Does it actually help?
Measured with a reproducible benchmark: 12 engineering tasks per repo, covering architecture, finding a feature, deployment, bug investigation, design rationale and following conventions.
Held-out repo (full-stack-fastapi-template; knock was never tuned on it):
More numbers, and the fine print
- Flask (used during development, so optimistic): knock 12/12 with 92K chars, baselines 7/12 with 2.1M and 247K chars.
- Speed: a ~200-file repo indexes in 0.3–0.6 s; re-indexing with no changes takes ~30 ms.
- What this measures: whether the facts reached the agent, not whether the agent then solved the task. The baselines are simulations of agent behaviour.
- In real Claude Code sessions (3 runs each), the result depends on the repository and the task:
- Flask (small and well known): knock was break-even on a bug investigation and slightly more expensive on an easy edit, where its extra steps outweigh a single search.
- Saleor (4,776 files, released days before the test), with the compact
map toolset: on a multi-module investigation, knock cut the median cost from $0.49 to $0.29 and model time from 170 s to 78 s, and every knock run was cheaper. On a follow-up edit whose file one regex search found, knock cost more ($0.14 vs $0.08).
- Latest version (adds edit mode and "skip knock for easy edits" guidance), over the full investigate-then-edit scenario: Saleor's median two-day cost fell from $0.70 to $0.43 (−39%). On Flask it was $0.31 vs $0.27, within run-to-run noise. Claude followed the guidance: it used knock for every investigation and skipped it for all the Flask edits.
- Variance check (8 runs per side on the Saleor investigation): median cost $0.42 → $0.25 (−40%), 8/8 correct answers on both sides, and about half the spread. Without knock, Claude delegated to a sub-agent in 5 of 8 runs; with knock, in none.
- The full story, including the versions that lost: I recorded 87 Claude Code sessions….
- Details and caveats are in docs/benchmark.md.
- Not yet measured: real billed tokens with a live model. The harness is ready (
benchmarks/agent_bench.py) but costs API credits to run.
- Where knock missed: wording mismatches ("linters" vs "lint") and module-level variables it doesn't index yet.
Full methodology: docs/benchmark.md.
🔒 Your code stays yours
- 💻 Everything is local: one SQLite file in
~/.knock. No cloud, no telemetry, no network calls (a test enforces this).
- 🙈 Secrets are skipped:
.env files, keys and credentials are never indexed, and tokens or passwords inside code are redacted.
- 🧱 Nothing is executed: knock never runs your scripts, hooks or tests. It only reads.
- 🚧 Sandboxed reads: agents can only fetch files knock indexed, never
../../anything.
[!IMPORTANT]
Whatever your agent retrieves through knock goes into the agent's context, just as if it had read the file itself. Exclude anything sensitive with a .knockignore file. Details: docs/security.md.
❓ FAQ
So it saves tokens?
That's the goal, and the benchmark shows far less text reaching the agent. But your bill also includes system prompts, reasoning, and output, and prompt caching already discounts repeated input. Expect the biggest wins on exploration-heavy questions ("how does X work?", "where is Y?", "how do we deploy?"), and little on pure code-writing. Faster answers and memory across sessions are wins either way.
Do I need an API key or a paid model?
No. Indexing and search are fully deterministic and local. The only thing that uses an API is the optional benchmark.
Which agents work with it?
Any agent that supports MCP over stdio. Verified: Claude Code (the session at the top of this page is a real recording of Claude using knock's tools) and the official MCP Python SDK client (all 8 tools, in the test suite). Cursor, Windsurf and others should work but are untested. Setup: docs/agents.md.
Which languages and files does it understand?
Python and JavaScript/TypeScript (including JSX, React components, Vue and Svelte scripts) get the full map: line ranges, what each function calls and uses, and who calls it. Go, Rust, Java, Kotlin, C#, Ruby, PHP, Swift, C/C++ and more get their functions, classes and types. It also reads Markdown and reStructuredText docs, ADRs, package.json, pyproject.toml, go.mod, Cargo.toml, Dockerfiles, Makefiles, GitHub Actions, linter configs and git history. Full list: docs/architecture.md.
What if the docs are wrong or outdated?
Every note is labelled with where it came from (extracted from docs, recorded by an agent, git history) and how fresh it is. Agents can mark a note as wrong, and it stays hidden until the source changes. The real file is always one get_source away.
How is this different from "RAG over my repo"?
No embeddings and no vector database. knock stores small structured facts that point back to exact lines, tracks when those lines change, and lets agents add what they learn. It's closer to a team wiki that maintains itself than to a search index.
🗺️ Status
knock is an early MVP (v0.1). What works today and what's next:
🤝 Contributing
Issues and PRs are welcome. Start with CONTRIBUTING.md.
Deeper docs: Architecture · Security · Agents · Benchmark · Troubleshooting
📜 License
Apache-2.0