
Codemesh
io.github.pyalwinPublished by GitHub account pyalwinv0.1.2Updated Oct 24, 2026
Intelligent code knowledge graph for AI coding agents — 71% cheaper, 72% faster
Overview
Codemesh builds a local code knowledge graph for a project so an AI coding agent can answer questions, trace call chains and reuse notes instead of grepping and
- What you can do
- Answer codebase questions in one call, returning relevant files, call chains, hotspots and suggested reads (codemesh_answer).
- When to use it
- Use it on larger or unfamiliar codebases where an agent would otherwise spend many turns grepping and reading files, and where you want knowledge from earlier sessions to carry over.
- Requirements
- Runs as a local stdio process from the npm package @pyalwin/codemesh, so Node.js is needed; the CODEMESH_PROJECT_ROOT environment variable must point at the absolute path of the codebase to index. The project must be indexed first (codemesh index), optionally with embeddings, which downloads a local model of roughly 80MB. No authentication is declared.
Installation
In SourceWeft
- Open Codemesh in the dashboard and add it to a workspace.
- Enable the server for the chats that should use its tools.
Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.
Other MCP clients
Follow the launch instructions in the repository.
README
Codemesh
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.
[npm] [Tests] [License] [TypeScript] [MCP]
Benchmarks · Quick Start · Integrations · Write-Back · How It Works · API Reference · Full Results
The Problem
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.
Benchmarks
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
These historical runs used the earlier answer-first workflow. The map-first navigation workflow described below is evaluated in an exploratory Pydantic pilot; the figures in this section should not be read as its measured performance.
Cost
Time
Tool calls (agent turns)
Quality (1–10, LLM-as-judge)
Cost savings: Codemesh MCP vs Baseline
[!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.
Quick Start
1. Install
Or run directly without installing:
Build from source
Verify the install:
codemesh --versionshould print the package version.
2. Index your project
The default index and retrieval path uses one SQLite database in .codemesh/.
It does not generate embeddings or require a vector database. Existing vector
artifacts from older runs are left untouched but are not used by this path.
3. Choose your mode
Codemesh offers two ways to integrate with AI agents:
Option A: MCP Server (structured tool calls)
Add to your Claude Code MCP config (~/.claude/mcp-servers.json or project .mcp.json):
The agent gets native MCP tools:
codemesh_map— browse one level of the indexed repository or follow a linkcodemesh_source— read a revision-checked source view by symbol ID;ifHashavoids repeat deliverycodemesh_inspect— inspect an exact symbol and its direct calls with bounded, exact source blockscodemesh_hydrate— verify saved symbol references and reopen exact source after a handoffcodemesh_answer— optional ranked context assemblycodemesh_explore— search, context (multi-target), impactcodemesh_trace— follow call chainscodemesh_enrich/codemesh_workflow— write backcodemesh_recall— retrieve notes and workflows with freshness statuscodemesh_status— health check
Best for: Opus, structured workflows, enrichment/write-back
Option B: CLI Mode (via Bash — zero MCP overhead)
No MCP config needed. The agent calls codemesh directly via Bash:
Exploration and write commands return JSON to stdout. No MCP server process is required.
Best for: Sonnet/Haiku, speed-sensitive workflows, simpler setup
Which mode should I use?
4. Use it
The agent can choose a path through the persistent graph before reading code:
Client Integrations
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 codemesh_* tools show up in the agent's toolbox.
Claude Code (CLI)
Add to ~/.claude/mcp-servers.json (user-wide) or .mcp.json (project-local):
Claude Desktop (macOS / Windows app)
Edit claude_desktop_config.json:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
Restart Claude Desktop. Codemesh's tools will appear in the tool picker (hammer icon).
Cursor — stop the agent from wandering your codebase
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.
Windsurf / VS Code (Continue)
Add to ~/.continue/config.json under experimental.modelContextProtocolServers:
Agent Write-Back: the graph that gets smarter
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.
How It Works
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.
MCP Tools
CLI
--compact is available for map, search, source, recall, inspect, and hydrate. It removes
repeated metadata from CLI JSON; source still includes the exact requested code
and a content hash. Navigation maps, search, inspect, and hydrate emit bounded JSON without
pretty printing; their compact form preserves exact source and freshness hashes.
hydrate also accepts --references-file PATH for a JSON array saved on disk.
Bounded responses omit the extra project-root wrapper so the final JSON stays
within the requested budget. Other commands retain their existing response format.
For handoffs, save a symbol's exact ID and bodyHash from a fresh source result.
codemesh_hydrate checks that hash against live source before returning full code.
If a saved hash came from fold or preview, include its mode; that hash
checks only the rendered view, so include bodyHash to verify the whole symbol.
Inspect and hydrate report omitted blocks explicitly when a budget is reached.
Both default to four source blocks and a 24 KiB JSON response budget. inspect
follows at most one hop of conservatively resolved local Python functions and
imports. Use --direction incoming or both to inspect candidate callers too;
--max-candidates bounds caller verification (default 32, maximum 128). Indexed
edges are hints: each delivered caller is checked against its current Python
binding. Incoming discovery is explicitly incomplete when edges are missing;
an empty result never proves that a symbol has no callers. Dynamic receivers,
ambiguous names, and uncertain bindings remain
explicitly unresolved; other languages expose unverified graph candidates.
These are static bindings, not guarantees about runtime behavior. Hydration
returns live-checked code; clients decide when to invoke it after a handoff and
which evidence to retain in their model context.
--mode auto is an explicit navigation view: symbols up to 120 lines and 12KiB
are returned in full; larger symbols return a bounded preview with omitted ranges
and a hint to map their members. Explicit --mode full always returns exact source.
Search ranks exact identifiers and exact qualified/leaf names first, then query
term coverage and lexical relevance, with popularity used only to break ties.
For an opt-in structural hint, --exact-tie-break path-depth prefers shallower
paths before popularity on equally ranked exact-name/leaf matches. MCP exposes
the same exactTieBreak option on codemesh_explore. Explicit IDs and path
filters still select deeper implementations; depth does not establish which
implementation is canonical. The default remains pagerank.
--path restricts candidates to a file or directory before SQLite result caps;
src does not match src-other. Compact search includes signatures and spans.
Search and navigation default to an 8192-byte JSON budget; --max-bytes accepts
512..65536. Omitted results are explicit. Navigation's cursor always points at
the first unreturned entry; if that entry alone exceeds the budget, increase
--max-bytes and reuse the cursor. Source code remains behind source/inspect.
The deterministic Graphify follow-up documents the single-agent design and focused context policy. Context replacement belongs to the harness: MCP/CLI tools cannot remove earlier client messages. The controlled next iteration documents lean eval instructions, optional search ranking, and two multi-file handoff fixtures.
Source retrieval also accepts a unique symbol name, such as MyType.myMethod.
An ambiguous name returns exact candidate IDs and spans; it never guesses an
overload from its size. Exact IDs remain the preferred reference across sessions.
adapt reads a native tool observation from stdin. Search folding preserves every
match and falls back for unsupported formats. Read outlining requires a complete
byte-exact match with a fresh indexed file and explicit navigation intent; edit
reads and partial reads pass through unchanged. --json reports the route and
reason instead of emitting only the adapted observation.
Optional: Hooks & Skills
Skill — teaches agents the graph-first workflow
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.
Hooks — automatic pre-read context injection
Add to .claude/settings.json:
- Pre-read — Adds a cached summary marked non-stale alongside the pending Read result
- Post-read — Nudges the agent to enrich after reading unfamiliar files
Supported Languages
Any language with a tree-sitter grammar can be added.
Graph Data Model
Nodes
Edges
Architecture
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.
Eval Framework
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/.
The SQLite-only CLI has a separate vNext contract and agent workflow eval on a pinned Pydantic checkout. Its correctness checks and model cost/quality comparison are reported separately from the historical benchmarks. The vNext Pydantic results record the first full paired run.
vs. Existing Tools
Development
Contributing
Contributions welcome. Areas for improvement:
- More languages — Add tree-sitter grammars and language-specific extractors
- AST-diff invalidation — Function-level instead of file-level staleness detection
- Graph backends — Memgraph/Neo4j adapters for
StorageBackend - Semantic search — Embedding columns alongside FTS5
- Agent adoption — Better patterns for agents to prefer graph tools naturally
License
MIT
Footnotes
-
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
-
Baseline for Alamofire hit a judge error (score recorded as 0 but not meaningful); excluded from the Baseline average. ↩
Source: README.md at commit 11c7776
Tools
0Version history
1- v0.1.2LatestSep 16, 2026
Score
50% of the applicable checks met
How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.
- Reached in the last 30 days25 pts
Keep the endpoint answering the MCP handshake; SourceWeft probes it every 30 days.
- Auth declared10 pts
Declare the credential headers in the registry entry, or keep the endpoint answering the probe so its auth can be classified.
- Tools listed15 pts
Answer tools/list without a credential, or ship a package that starts in a sandbox without one.
- DescriptionRequired15 pts
- Logo10 pts
- Documentation15 pts
- License10 pts