Graft: Open‑Source Context Layer Cuts Claude Code Token Usage by 42% and Boosts SWE‑bench Accuracy
TL;DR
Graft builds a persistent, markdown‑based code graph that agents can query instead of repeatedly grepping the repository; this cuts Claude Code token usage by 42%, reduces tool calls by 46%, speeds up runs by 60%, and raises SWE‑bench correctness from 54% to 66%.
What Graft Claims
- Efficiency gains – In a controlled 162‑run benchmark, Graft saved 42% of tokens, 46% of tool calls, and 60% of latency compared with a “cold” Claude Code session that re‑explores the repo on every task.
- Correctness improvement – On the industry‑standard SWE‑bench Verified suite (50 real GitHub issues), Graft resolved 33 instances versus 27 for the baseline, a 12‑point lift.
- Cost reduction – The same benchmark shows a 32% drop in wall‑clock time and a 19% reduction in monetary cost.
- Language support – Full‑fidelity parsing for TypeScript/JavaScript, Python, Go, Java; broader tree‑sitter support for 20 additional languages; optional LSP‑based edges for Rust, C/C++, etc.
- Zero‑runtime overhead – The structural graph (
graft build) runs locally without an API key; only the optional LLM summarisation (--deep) contacts a provider.
How Graft Works
Two‑pass graph construction
- File summarisation – Each source file is passed once to an LLM (optional) to produce a short English description.
- Node aggregation – Summaries are grouped into a curated set of markdown nodes (sub‑systems, key files, concepts) with typed wikilinks (
[[node]]).
The resulting graft/ directory is a plain‑file cache that lives alongside the code and can be committed to Git.
Node contents
| Part | Description |
|---|---|
| Summary | One‑sentence English explanation of the code’s purpose, generated by the LLM and cached. |
| Crux | The minimal set of source lines that implement the core logic, stored verbatim. |
| Sources | File paths and content hashes that back the node, enabling precise stale‑check detection. |
| Links | Typed relationships (depends_on, part_of, uses, etc.) expressed as [[wikilinks]]. |
| Notes | User‑authored free text that survives regeneration. |
Incremental refresh
- Graph rebuilds are cached by content hash; only changed files trigger LLM calls.
- A lightweight
$0structural refresh runs before everygraft ask/grep/callerscommand, ensuring the graph reflects uncommitted edits without network calls.
Integration with Coding Agents
graft initdetects supported agents (Claude Code, Cursor, Gemini, Codex, Copilot, etc.) and writes the necessary instruction or skill files. Claude Code receives a live status line, auto‑sync hooks, and a per‑session import of matching nodes.- MCP server – Registers six tool endpoints (
graft_find_code,graft_file_api,graft_trace_calls,graft_find_all,graft_repo_map,graft_check_freshness) that agents can invoke directly. - No daemon – The graph lives as regular files; no background service is required unless the user opts for the optional MCP server.
Benchmarks
Controlled 162‑run sweep
| Metric | Cold Claude Code | Claude Code + Graft |
|---|---|---|
| Cost savings ($) | 0.0429 | 0.0292 (+32%) |
| Token savings | 8,070 | 4,650 (+42%) |
| Tool‑call savings | 4.2 | 2.3 (+46%) |
| Latency (s) | 39.8 | 15.8 (+60%) |
| Correctness | 93% | 93% |
The “pull” variant (using graft tools on demand) achieved the highest correctness (98%) but sacrificed most of the speed benefit.
SWE‑bench Verified (50 real issues)
| Metric | Cold Claude Code | Claude Code + Graft |
|---|---|---|
| Correctness | 27/50 (54%) | 33/50 (66%) |
| Token savings | 142 M | 109.4 M (+23%) |
| Cost savings | $52.34 | $42.43 (+19%) |
| Tool‑call savings | 1,370 | 1,031 (+25%) |
| Wall‑clock time | 13,094 s | 8,922 s (+32%) |
The correctness lift stems from better cross‑file reasoning; baseline often patched a single file and missed dependent files.
Community Feedback on Hacker News
@seizethecheese – “The benchmark section reads like it was written by Claude/Codex; the 50‑task SWE‑bench sample is small and the p‑value (0.22) is weak. It’s easy to cherry‑pick tasks.”
The comment highlights that the published results are based on a limited sample and single runs, which limits statistical confidence.
@icodestuff – “I worry about stale graphs over long sessions. Incremental refreshes may drift silently, and merge conflicts in
graft/could be painful.”
This points out a practical risk: long‑running sessions could rely on outdated summaries, and version‑control conflicts may arise when multiple developers edit the same concepts.
@xhrpost – “Does Claude’s LSP integration already reduce grep usage? Is Graft solving a duplicate problem?”
The question clarifies that Graft’s value proposition is distinct: it provides a persistent, human‑readable knowledge graph rather than a one‑off LSP‑based symbol lookup.
@gabosarmiento – “What’s the benchmark against Graphify?”
No direct comparison is provided in the repository; the claim remains unverified.
Overall, commenters appreciate the idea but request more rigorous, larger‑scale evaluations and tooling for conflict resolution.
Practical Usage
Quick start (npm)
npm install -g @nanonets/graft # install CLI
graft init # select agents, build `graft/`, wire Claude Code
graft init --dry-runshows files that would be written.graft buildcreates the graph without LLM calls;graft build --deepadds LLM‑generated summaries (requires API key).
Core CLI commands
| Command | Purpose |
|---|---|
graft ask "<task>" |
Rank nodes that answer a natural‑language query (no LLM needed). |
graft grep "<regex>" |
Exhaustive regex search, grouped by enclosing symbol. |
graft map |
Token‑budgeted repo orientation (directory clusters, hubs, hotspots). |
graft callers <symbol> |
Show inbound/outbound call graph for a symbol. |
graft viz |
Launch an interactive web viewer of the markdown and code graphs. |
All commands accept --no-refresh to skip the automatic structural update, and the environment variable GRAFT_NO_REFRESH=1 disables it globally.
Limitations & Open Questions
- Statistical robustness – Benchmarks are based on 162 runs and 50 SWE‑bench instances; larger, multi‑seed studies would strengthen claims.
- Graph staleness – Incremental refreshes are structural only; LLM‑generated summaries may become outdated if source code changes without a rebuild.
- Merge conflicts –
graft/lives in the repository; simultaneous edits to the same node can cause Git conflicts that require manual resolution. - Comparative baselines – No public comparison to other code‑graph tools (e.g., Graphify, Repowise) is provided.
Conclusion
Graft demonstrates that a deterministic, markdown‑based code graph can dramatically reduce the token and tool‑call overhead of LLM‑driven coding agents while improving real‑world correctness on SWE‑bench. The approach is attractive because it requires no daemon, works with any LLM provider, and integrates with multiple agents via a simple CLI. However, the current evidence rests on modest benchmark sizes, and long‑term stability of the generated knowledge graph remains an open engineering challenge.
Sources
関連
- プロジェクト
- Dispatch
- プロジェクト
- Dispatch
- プロジェクト