Structural code context for AI coding agents — a local code knowledge graph for blast radius, impact, deps, dead code, and flow tracing
Project description
CodeCompass
A local code knowledge graph that gives AI agents a map of your codebase — so they navigate by structure instead of grepping blind, and know what's connected before they edit.
No database. No cloud. One JSON file per repo. Python, JavaScript/TypeScript, PHP, HTML/CSS.
Why it's faster
AI agents read files one at a time and grep to find their way. On a real task that means opening candidate after candidate to answer "who calls this?" or "what breaks if I change this?" CodeCompass answers those from a precomputed graph, so the agent reads only the code it actually needs.
We benchmarked it against traditional grep/read on six standard tasks (impact, blast radius, dead code, flow trace, find-and-edit, feature scoping) across four real repos, measuring tokens to a verified answer — the query output plus the code still read to trust it.
CodeCompass wins every relational and discovery task; grep only holds even on a plain textual find of a known string. The advantage grows with codebase size and name collisions. Full breakdown, per-task numbers, and honest limitations in docs/benchmark-results.md.
The workflow
The graph turns navigation into a cheap, deterministic loop:
discover → trace → read → edit
-
Discover — find the symbols you care about without opening files:
You have… Use a feature request that names a concept ("session timeout") grepthe concepta regex / name pattern grepkeywords searcha vague, nameless need map(compact index to reason over) -
Trace — a relationship around a known symbol/file:
Question Use who calls / would break if I change this? impactwhat files are affected if I edit this file? blast_radiuswhat does this file depend on? depswhat does this entry point call, step by step? flowexplain a flow to a human (diagram + narration) flow_summaryanything unused? dead_code -
Read the specific slice the graph points to (
impactgivesfile:line). -
Edit — check
impact/blast_radiusfirst so you don't miss a caller.
What makes it accurate
- Precise call graph. Nodes are file- and class-qualified, so
Command.invokeandContext.invoke(same file) stay distinct, andimpactreturns the callers of a specific method — no same-named look-alikes, no test noise. - Receiver-type resolution.
self.send()resolves to the enclosing class;x = new Adapter()/x: Adapter/x = make()(with a return type) resolve by type. Calls that can't be typed statically (dynamic dispatch) are surfaced flaggedresolved: false— never dropped, never claimed precise. - Line-anchored. Every
impactcaller carries its real call-sitefile:line, so verification reads a few lines, not a whole function.
Install
pip install codecompass-mcp
Gives you the codecompass CLI and the codecompass-mcp MCP server.
Index a project
cd /path/to/your/project
codecompass init # creates .codecompass/, writes AGENTS.md
codecompass ingest-code # parses source and builds the graph
ingest-code runs init automatically if needed. Re-ingest after refactors (or run codecompass watch to keep the graph live).
Connect an MCP client
The server speaks stdio MCP and defaults to the working directory.
Claude Desktop — ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) / %APPDATA%\Claude\claude_desktop_config.json (Windows):
{ "mcpServers": { "codecompass": { "command": "codecompass-mcp" } } }
Cline / Cursor / other — add a server with command codecompass-mcp. To query a different repo, the agent calls set_repo, or set CODECOMPASS_REPO=/path/to/project in the server env.
Queries (CLI)
# discover
codecompass query --grep "^get_" # regex over graph entities
codecompass query --search "session cookie" # keyword search
codecompass query --map # compact {file: [symbols]} index
# trace
codecompass query --impact "Session.send" # callers (disambiguated), with file:line
codecompass query --blast-radius src/app.py # what depends on this file
codecompass query --deps src/api/routes.py # what this file imports
codecompass query --flow "Session.request" # lean call-flow structure
codecompass query --flow-summary "main" # flow + mermaid + narration
codecompass query --dead-code # unreferenced candidates
codecompass query --tree # full hierarchy
Add --hops N for traversal depth (start at 1 and follow the one path you need). Add --rich for tables.
Flow: flow vs flow-summary
flow— lean structure only (node name/kind/file/depth, edge from/to/order/line). What an agent needs to navigate; no embedded source.flow-summary— the trace rendered for a human: a mermaid flowchart with prose narration (--format mermaid, default), or source-embedded JSON (--format json), or a draw.io diagram (--format drawio). Written to.codecompass/flow_<entry>.*.
MCP tools
| Tool | Returns |
|---|---|
grep(pattern, field, ignore_case) |
Regex search over graph entities |
search(query, kind) |
Keyword search, ranked |
map(include_tests) |
Compact {file: [symbols]} index |
impact(symbol, hops) |
Callers/importers, disambiguated, with resolved + line |
blast_radius(target, hops) |
Files reachable from a file or symbol |
batch_impact(targets, hops) |
Union of blast radii for a multi-file change |
deps(file_path, hops) |
What a file imports |
flow(entry_symbol, hops) |
Lean call/import flow structure |
flow_summary(entry_symbol, hops, format) |
Flow + narration (mermaid/json/drawio) |
trace(symbol, hops) |
Forward call chain |
dead_code(include_entrypoints) |
Entities with no inbound caller |
styles(element) |
CSS selectors that style an element |
tree() |
Full project hierarchy |
set_repo / get_repo / init / ingest |
Project selection & indexing |
Supported languages
| Language | Extracted |
|---|---|
| Python | functions, classes, imports, calls, inheritance, receiver/return-type inference, __all__/public exports |
| JavaScript / JSX | functions, classes, require/import, calls, receiver/return-type inference, module.exports/export |
| TypeScript / TSX | as JS, plus type annotations for receiver resolution |
| PHP | functions, classes, methods, calls, receiver/return-type inference, public/private/protected visibility |
| HTML | elements, references, includes |
| CSS / SCSS | selectors, variables, @import/@use |
.styles.ts (Lit) |
CSS-in-JS var(--token) usages and :host declarations |
Receiver capture, type inference, and export/visibility awareness apply to all call-based languages (JS/TS, Python, PHP). Node de-merge and the discovery tools are language-agnostic.
Navigation guardrail (optional, installed by init)
AGENTS.md guides any agent through the discover→trace→read→edit loop. For
Claude Code and pi, init also installs a PreToolUse hook
that blocks code search (grep/rg, the Grep/Glob tools) and
whole-file cat, routing discovery through the graph — while leaving
targeted reads free (the Read tool, sed -n, head/tail). The point is
to change the default reflex to graph-first, not to remove reads. Both pick the
files up after a one-time trust prompt (they execute shell commands). The hook
is a plain file under .claude/hooks/ — edit or delete it to adjust.
How it works
Source files
▼ hierarchy_builder walks repo → Project / Folder / File skeleton
▼ code_parser tree-sitter extraction (no API calls) → typed CodeTriples
▼ graph.json NetworkX MultiDiGraph as JSON; file+class-qualified nodes,
typed edges (CALLS/IMPORTS/INHERITS/STYLES/…), resolved calls
▼ code_query_cli traversal: grep / search / map / impact / blast-radius /
deps / flow / dead-code / tree
Everything runs locally, in-process. No network, no database, no API keys.
Inside each indexed project:
your-project/
├── .codecompass/graph.json the code knowledge graph (auto-generated)
└── AGENTS.md discovery guide for agents (auto-updated)
Limitations
- Structure, not semantics — the graph knows what calls what, not what it means.
- Static analysis — dynamic dispatch, reflection, and string-based invocation
can't be fully resolved.
impactsurfaces those flaggedresolved: false, anddead_coderesults are always candidates to verify. - No cross-repo edges — entities outside the indexed repo don't appear.
- Re-ingest after refactors — the graph doesn't auto-update unless
watchis running.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codecompass_mcp-3.2.1.tar.gz.
File metadata
- Download URL: codecompass_mcp-3.2.1.tar.gz
- Upload date:
- Size: 74.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a398559bdb97ee9222e3124dbe695092ca42b5bc79b19b94331ed65fc168f9a
|
|
| MD5 |
07ebecf915dea780cce942e379bd4b9b
|
|
| BLAKE2b-256 |
68f562b3120cefb5f7f1384a6d60a49ae48bd80f3b918ed568c9b21980f26860
|
Provenance
The following attestation bundles were made for codecompass_mcp-3.2.1.tar.gz:
Publisher:
pypi-publish.yml on mmkumar5401/CodeCompass
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codecompass_mcp-3.2.1.tar.gz -
Subject digest:
4a398559bdb97ee9222e3124dbe695092ca42b5bc79b19b94331ed65fc168f9a - Sigstore transparency entry: 2153474599
- Sigstore integration time:
-
Permalink:
mmkumar5401/CodeCompass@54126c1b17c996ac11cc279d48f073e742d306f0 -
Branch / Tag:
refs/tags/v3.2.1 - Owner: https://github.com/mmkumar5401
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@54126c1b17c996ac11cc279d48f073e742d306f0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file codecompass_mcp-3.2.1-py3-none-any.whl.
File metadata
- Download URL: codecompass_mcp-3.2.1-py3-none-any.whl
- Upload date:
- Size: 68.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46f90e63dc5e54939be4998be6acc64c925ed12cf5f4f9b131ce3cff74c448e0
|
|
| MD5 |
3cdf055bc4df055856f1995fcf85c492
|
|
| BLAKE2b-256 |
e03963423c6bb6ba051b0217c742c02905a5cf1b86f06222695d2d51216bf7f8
|
Provenance
The following attestation bundles were made for codecompass_mcp-3.2.1-py3-none-any.whl:
Publisher:
pypi-publish.yml on mmkumar5401/CodeCompass
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codecompass_mcp-3.2.1-py3-none-any.whl -
Subject digest:
46f90e63dc5e54939be4998be6acc64c925ed12cf5f4f9b131ce3cff74c448e0 - Sigstore transparency entry: 2153475434
- Sigstore integration time:
-
Permalink:
mmkumar5401/CodeCompass@54126c1b17c996ac11cc279d48f073e742d306f0 -
Branch / Tag:
refs/tags/v3.2.1 - Owner: https://github.com/mmkumar5401
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@54126c1b17c996ac11cc279d48f073e742d306f0 -
Trigger Event:
push
-
Statement type: