Skip to content
AI Primer
release

Graft adds repo context cache for Claude Code

Graft scans a repo into linked markdown and plugs into Claude Code hooks so the agent can reuse codebase context. Its 162-run benchmark claims 46% fewer tool calls, up to 4x fewer tokens, and 60% less time.

5 min read
Graft adds repo context cache for Claude Code
Graft adds repo context cache for Claude Code

TL;DR

  • Graft turns repo orientation into a reusable code map: hasantoxr says a 20-tool-call orientation pass becomes one file read, while the GitHub README describes linked markdown nodes plus a deterministic wiring graph.
  • Claude Code gets the useful integration, not just instructions: hasantoxr's hooks post says Graft rides through hooks automatically, and Anthropic's hooks guide describes hooks as lifecycle commands that can inject context and automate actions.
  • The benchmark claim is split across two tests: hasantoxr's benchmark post reports 46% fewer tool calls, up to 4x fewer tokens, and 60% less time, while the README benchmark section lists 42% fewer input tokens in the controlled run.
  • Setup is two commands, npm install -g @nanonets/graft and graft init, according to hasantoxr's setup post; hasantoxr's repo post points to an MIT-licensed GitHub project.

The GitHub README has the buried caveats: graft/ is a local regenerable cache, the deep LLM pass is optional, and the structural graph runs with no key. Anthropic's Claude Code hooks guide explains the adoption trick: hooks can run before prompts, after tools, and at session start. The Graft homepage frames the product as a context layer for large codebases, with a statusline for graph size, enrichment, sync state, and stale warnings.

Linked markdown cache

hasantoxr described Graft as a repo scan that writes linked markdown so the agent reads the map before touching source files. The README is more specific: graft build creates graft/, adds it to .gitignore, and treats the graph as a local cache; the shared artifact is the .claude/ wiring from graft init, then each teammate generates their own graph.

Graft builds that cache in layers, according to the GitHub README:

  • Tree-sitter wiring: graft build creates graft/.graph/wiring.json and per-file wiring cards without a model call.
  • File summaries: graft build --deep summarizes source files through the user's configured provider.
  • Grouped nodes: summaries become markdown nodes for systems, APIs, files, and concepts.
  • Typed links: nodes use relationships such as depends_on, part_of, uses, implements, and produces.
  • Preserved notes: user-written notes stay below the generated block across regeneration.

The sharp bit is not the markdown. It is that the agent can grep, open, and follow the graph like normal repo files.

Claude Code hooks

The integration lands in Claude Code's lifecycle instead of a command the user has to remember. The README says graft init drops a statusline and hooks into .claude/, then pulls matching nodes into prompts and rebuilds the structural graph after edits.

Claude's hooks guide lists the pieces Graft is leaning on: UserPromptSubmit fires before Claude processes a prompt, PostToolUse fires after successful tool calls, and SessionStart can inject context when a session begins or resumes.

Graft's Claude Code integration includes:

  • Live statusline: graph size, enrichment percentage, and stale warnings.
  • Auto-sync: structural rebuilds after edits at the end of the turn, with no LLM call.
  • Context on tap: prompts pull relevant nodes, edited files surface blast radius, and new sessions start with the repo map.

Benchmark claims

The thread compresses the win into agent-run numbers. The README benchmark section splits the evidence into a controlled benchmark and a separate real-repo sweep.

162-run controlled benchmark

  • Same Claude Sonnet 5 agent, same file tools, two repos, single-file and multi-file questions.
  • Variants: cold exploration, Graft context pushed up front, and pull mode through graft_ask and graft_skeleton.
  • Cost: $0.0429 cold to $0.0292 with Graft, down 32%.
  • Uncached input tokens: 8,070 cold to 4,650 with Graft, down 42%.
  • Tool calls: 4.2 cold to 2.3 with Graft, down 46%.
  • Latency: 39.8 seconds cold to 15.8 seconds with Graft, down 60%.
  • Correctness: 93% cold and 93% with Graft.
  • Pull mode reached 98% correctness, with a speed tradeoff.

Real-repo sweep

  • Repos: PocketBase, ollama, and Excalidraw.
  • Tasks: 15 per repo, split into 10 developer questions and 5 implementation tasks.
  • Best single-task wins: up to 4x cheaper and 3x faster, according to the README.
  • PocketBase is the thread's concrete example: hasantoxr says Graft reproduced the same files maintainers changed on five already-merged PRs.

The token headline changed shape between the thread and README. hasantoxr's post says up to 4x fewer tokens; the README table says 42% fewer input tokens for the controlled benchmark and reserves the 4x figure for biggest single-task cost wins.

Two-command setup

The happy path is deliberately small:

The README adds an npx @nanonets/graft init path for no global install. graft init --dry-run prints every file it would touch, --agents claude wires Claude Code alone, and --no-mcp, --no-hooks, or --no-global skip specific integration layers.

For non-TTY runs such as CI, init writes nothing unless the run is made explicit with flags like --agents or --yes, according to the README.

Six MCP tools

The GitHub project is MIT licensed and exposes more than a Claude Code hook bundle. The README says graft init can register an MCP server so agents can call six tools directly:

  • graft_ask: ranked nodes with file lines and inlined source.
  • graft_skeleton: signatures for a file without bodies.
  • graft_callers: incoming or outgoing symbol dependencies.
  • graft_grep: regex hits grouped by enclosing symbol.
  • graft_map: directory clusters, hubs, and hotspots for first-pass orientation.
  • graft_check: drift detection between graph and code.

The same README says structural commands such as graft build, graft check, and graft ask run locally with no key and no network. The LLM-written layer uses the user's configured provider, including Anthropic, OpenAI-compatible endpoints, OpenRouter, Fireworks, Groq, LiteLLM, or local models.

Further reading

Discussion across the web

Where this story is being discussed, in original context.

On X· 1 thread
Linked markdown cache1 post
Share on X