The full upstream README, mirrored here for reference. Install config, tool schemas, adoption signals, and an original overview live on the Codemesh listing page.
Intelligent code knowledge graph for AI coding agents
71% cheaper, 72% faster, 82% fewer tool calls vs baseline Grep+Read
on 6 real-world repos (Sonnet 4.6) — from a single codemesh index.
Benchmarks · Quick Start · Integrations · Write-Back · How It Works · API Reference · Full Results
AI coding agents waste 40-80% of their tokens on discovery — grepping through files, reading irrelevant code, and rebuilding context they've already seen in previous sessions.
On a 600-file codebase, a typical exploration task involves 10+ file reads before the agent even knows what's relevant.
Codemesh is an MCP server that gives agents a persistent, queryable knowledge graph. The graph gets smarter over time: agents write back what they learn, so the next session starts informed.
Benchmarked on 6 real-world codebases (Alamofire, Excalidraw, VS Code, Swift Compiler, pydantic-validators, pydantic-basemodel) with Claude Sonnet 4.6, compared alongside baseline and graph-based approaches for context.
Full methodology, per-repo breakdowns, and pairwise comparisons: docs/benchmark-results.md | Early pydantic evals
| Mode | Alamofire | Excalidraw | VS Code | Swift Compiler1 | pydantic-validators | pydantic-basemodel | Avg |
|---|---|---|---|---|---|---|---|
| Baseline | $0.54 | $0.89 | $0.21 | $0.83 | $1.32 | $0.78 | $0.76 |
| Codemesh MCP | $0.25 | $0.21 | $0.16 | $0.23 | $0.33 | $0.13 | $0.22 |
| Codemesh CLI | $0.67 | $0.51 | $0.16 | $0.83 | $1.00 | $0.18 | $0.56 |
| Codegraph | $0.37 | $0.56 | $0.57 | $0.74 | $0.29 | $0.19 | $0.45 |
| Mode | Alamofire | Excalidraw | VS Code | Swift1 | pydantic-v | pydantic-b | Avg |
|---|---|---|---|---|---|---|---|
| Baseline | 180s | 191s | 87s | 199s | 352s | 232s | 207s |
| Codemesh MCP | 78s | 45s | 35s | 87s | 72s | 32s | 58s |
| Codemesh CLI | 226s | 177s | 62s | 227s | 235s | 51s | 163s |
| Codegraph | 134s | 180s | 192s | 199s | 75s | 60s | 140s |
| Mode | Alamofire | Excalidraw | VS Code | Swift1 | pydantic-v | pydantic-b | Avg |
|---|---|---|---|---|---|---|---|
| Baseline | 31 | 48 | 12 | 29 | 84 | 65 | 45 |
| Codemesh MCP | 9 | 5 | 3 | 14 | 14 | 3 | 8 |
| Codemesh CLI | 30 | 32 | 12 | 56 | 64 | 9 | 34 |
| Codegraph | 31 | 35 | 44 | 44 | 20 | 12 | 31 |
| Mode | Alamofire2 | Excalidraw | VS Code | Swift Compiler | pydantic-validators | pydantic-basemodel | Avg |
|---|---|---|---|---|---|---|---|
| Baseline | n/a | 9 | 8 | 7 | 2 | 9 | 7.0 |
| Codemesh MCP | 9 | 9 | 7 | 8 | 7 | 7.8 | 7.9 |
| Codemesh CLI | 9 | 7 | 7 | 9 | 1 | 8.4 | 6.9 |
| Codegraph | 8 | 9 | 8.7 | 8 | 8 | 9 | 8.4 |
| Repo | Baseline | Codemesh MCP | Cost saved | Time saved |
|---|---|---|---|---|
| Alamofire | $0.54 | $0.25 | −54% | −57% (180s → 78s) |
| Excalidraw | $0.89 | $0.21 | −76% | −76% (191s → 45s) |
| VS Code | $0.21 | $0.16 | −24% | −60% (87s → 35s) |
| Swift Compiler1 | $0.83 | $0.23 | −72% | −56% (199s → 87s) |
| pydantic-validators | $1.32 | $0.33 | −75% | −79% (352s → 72s) |
| pydantic-basemodel | $0.78 | $0.13 | −83% | −86% (232s → 32s) |
| Average | $0.76 | $0.22 | −71% | −72% |
[!NOTE] Codemesh MCP achieves the lowest cost and fastest time of any mode tested — 71% cheaper and 72% faster than baseline on average across 6 repos, using 82% fewer tool calls (8 vs 45). Quality is comparable to baseline (7.9 vs 7.0); Codegraph edges Codemesh on quality (8.4) but at roughly double the cost ($0.45 vs $0.22). Every repo shows cost and time savings — including the comprehension-heavy queries (Excalidraw, pydantic-basemodel) that regressed in prior builds of codemesh.
Or run directly without installing:
Verify the install:
codemesh --versionshould print the package version.
Codemesh offers two ways to integrate with AI agents:
Add to your Claude Code MCP config (~/.claude/mcp-servers.json or project .mcp.json):
The agent gets native MCP tools:
codemesh_answer — one-call question answering (PRIMARY)codemesh_explore — search, context (multi-target), impactcodemesh_trace — follow call chainscodemesh_enrich / codemesh_workflow — write backcodemesh_status — health checkBest for: Opus, structured workflows, enrichment/write-back
No MCP config needed. The agent calls codemesh directly via Bash:
All commands return JSON to stdout. No MCP server process, no protocol overhead.
Best for: Sonnet/Haiku, speed-sensitive workflows, simpler setup
| MCP Server | CLI Mode | |
|---|---|---|
| Setup | MCP config file | Just export CODEMESH_PROJECT_ROOT |
| Overhead | MCP protocol per call | Zero — direct subprocess |
| Enrichment | Native codemesh_enrich tool | Via Bash("codemesh enrich ...") |
| Best model | Opus (follows MCP well) | Sonnet (55% cheaper, 61% faster than baseline) |
| Recommended | Complex codebases | Default choice |
The agent now has 6 new tools. Query the graph before reading code:
Codemesh speaks the Model Context Protocol, so any MCP-compatible client can use it. Paste one of the snippets below, restart the client, and the six codemesh_* tools show up in the agent's toolbox.
Add to ~/.claude/mcp-servers.json (user-wide) or .mcp.json (project-local):
Edit claude_desktop_config.json:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.jsonRestart Claude Desktop. Codemesh's tools will appear in the tool picker (hammer icon).
Cursor reads .cursor/mcp.json per project (or ~/.cursor/mcp.json for all projects):
Open Settings → MCP, confirm codemesh is green, then mention it in a prompt (@codemesh how does auth work?) to nudge the agent toward graph queries instead of recursive Grep.
Add to ~/.continue/config.json under experimental.modelContextProtocolServers:
Every other code-intelligence tool indexes your repo once and hands the agent a read-only view. Codemesh lets the agent teach the graph as it works — summaries, workflows, and cross-concept links persist across sessions and survive re-indexing.
The graph now knows things no static analyzer could infer: why a file matters, which files move together, what a maintainer called a concept. Re-indexing rebuilds the structural layer (files, symbols, imports, calls) but preserves every enrichment — entries only go stale when their referenced files change.
See codemesh_enrich and codemesh_workflow under MCP Tools.
Structural layer (automatic) — Tree-sitter parses your code into files, symbols (functions, classes, methods), and relationships (imports, calls, extends). Rebuilt on each index.
Semantic layer (agent-built) — As agents work with your code, they write back summaries and workflow paths. These survive re-indexing and accumulate across sessions. Invalidated when referenced files change.
| Tool | Purpose | Example |
|---|---|---|
codemesh_answer | One-call context assembly — returns all relevant files, call chains, hotspots, suggested reads | codemesh_answer({ question: "How does auth work?" }) |
codemesh_explore | Search, context (multi-target), impact analysis | codemesh_explore({ action: "search", query: "auth" }) |
codemesh_trace | Follow call chains with source code | codemesh_trace({ symbol: "login", depth: 5 }) |
codemesh_enrich | Write back what you learned for future sessions | codemesh_enrich({ path: "src/auth.py", summary: "..." }) |
codemesh_workflow | Record multi-file workflow paths | codemesh_workflow({ name: "login flow", files: [...] }) |
codemesh_status | Graph health check | codemesh_status() |
Copy skills/codemesh.md to ~/.claude/skills/ or your project's .claude/skills/.
The skill instructs agents to query the graph before using Grep/Read, and to write back via codemesh_enrich after reading code.
Add to .claude/settings.json:
| TypeScript | JavaScript | Python | Go | Rust | Java | C# |
| Ruby | PHP | C | C++ | Swift | Kotlin | Dart |
Any language with a tree-sitter grammar can be added.
| Type | Source | Key Fields |
|---|---|---|
file | Static (tree-sitter) | path, hash, last_indexed_at |
symbol | Static (tree-sitter) | name, kind, file_path, line_start, line_end, signature |
concept | Agent-written | summary, last_updated_by, stale |
workflow | Agent-written | description, file_sequence, last_walked_at |
| Type | Direction | Source |
|---|---|---|
contains | file → symbol | Static |
imports | file → file | Static |
calls | symbol → symbol | Static |
extends | symbol → symbol | Static |
describes | concept → file/symbol | Agent |
related_to | concept → concept | Agent |
traverses | workflow → file | Agent |
Storage is backend-agnostic. The StorageBackend interface abstracts all persistence. v1 uses SQLite with FTS5 for zero-dependency local operation. The interface supports swapping to Memgraph, Neo4j, or other graph databases.
Reproducible evaluation harness with LLM-as-judge scoring:
See docs/benchmark-results.md for full methodology and results. Early pydantic evals are archived in docs/experiments/.
| Feature | CodeGraph | Graphify | Axon | Codemesh |
|---|---|---|---|---|
| Structural indexing | Yes | Yes | Yes | Yes |
| FTS search | Yes | — | Yes | Yes |
| Agent write-back | — | — | — | Yes |
| Workflow memory | — | — | — | Yes |
| Hook interception | — | — | — | Yes |
| Backend-swappable | — | — | — | Yes |
| Eval framework | — | — | — | Yes |
| Published benchmarks | — | — | — | Yes |
Contributions welcome. Areas for improvement:
StorageBackendMIT
https://github.com/pyalwin/codemesh/blob/HEAD/Swift Compiler's codemesh index failed to complete (indexer regression on 30k+ file codebases — see known issues). The codemesh numbers above reflect agent behavior with an empty retrieval graph, falling back to Read + LSP — still ahead of baseline, but unrepresentative of codemesh's capability on a properly-indexed Swift repo. ↩ ↩2 ↩3 ↩4
https://github.com/pyalwin/codemesh/blob/HEAD/Baseline for Alamofire hit a judge error (score recorded as 0 but not meaningful); excluded from the Baseline average. ↩