# Graft

> Build your codebase's knowledge graph once, feed it to every coding agent

- Category: Retrieval & Knowledge (RAG) / Code Indexing & Search
- Language: TypeScript
- Licence: MIT
- Repository: https://github.com/trailhq/Trail-Code
- Website: https://trailhq.com/graft
- Canonical page: https://ai-tldr.dev/tools/graft/

## In short

Graft attacks a specific waste in agentic coding: every task starts with the agent grepping and reading its way around the repository again, paying for the same exploration over and over. It sits in the Code Indexing & Search category of the Retrieval & Knowledge (RAG) tools and is open-source, written in TypeScript and licensed MIT.

## Overview

Graft attacks a specific waste in agentic coding: every task starts with the agent grepping and reading its way around the repository again, paying for the same exploration over and over. Graft does that work once and writes the result into the repo as a folder of linked markdown files — one node per system, API or concept — that agents read instead.

It builds the graph in two passes. The first is structural and deterministic: Tree-sitter extracts symbols, calls and imports, with no model and no API key required. The second is optional LLM enrichment, which adds summaries and groups related code across files using whichever provider you configure. Because the output is plain markdown, you can read and correct it yourself, and because it is a cache it is regenerable like `node_modules` — the README's recommendation is to gitignore it.

Graft is agent-agnostic. It wires into Claude Code, Cursor, Codex, Gemini, OpenCode and Copilot through a shared `AGENTS.md` instruction file plus agent-specific rule files, and also exposes an MCP server with native tools such as `graft_find_code`, `graft_file_api` and `graft_trace_calls`. The project reports up to 4× lower cost, 3× faster runs, 42% token savings, 46% fewer tool calls and +12 points on SWE-bench Verified; treat those as the maintainers' own published figures.

## What it does

- Two-pass indexing: deterministic Tree-sitter parsing first, optional LLM enrichment second
- Output is a folder of linked markdown nodes — human-readable, correctable and regenerable
- Auto-detects and configures your agents during graft init, with no daemon or background service
- Claude Code integration adds a freshness statusline, auto-sync before queries, context injection and blast-radius warnings on edits
- MCP server exposing six native tools including graft_find_code, graft_file_api and graft_trace_calls
- 23 languages supported, including TypeScript, Python, Go, Java, Rust and C++
- Optional language servers (rust-analyzer, clangd, pyright) for compiler-grade precision

## Getting started

Graft is a global npm CLI. Installing and initialising it in a repository is the whole setup — init detects your agents and writes their configuration for you.

1. Install the CLI

```bash
npm install -g @nanonets/graft
```

2. Initialise it in your repository

   Run this from the repo root. It performs the structural pass, writes the graph, and configures the agents it finds.

```bash
graft init
```

3. Add a provider key for enrichment (optional)

   The structural pass needs no key. For summaries and cross-file grouping, configure a key for OpenAI, Anthropic, OpenRouter, Fireworks, Groq, or point it at a local model.

4. Keep the graph out of git

   The graph is a regenerable cache, not source. Add its folder to .gitignore and let each machine rebuild it.

## When to use it

- Reach for it on a large repository where agents burn most of their budget rediscovering structure before they change anything
- Reach for it when several different agents work on the same codebase and you want them to share one understanding of it
- Reach for it to get blast-radius warnings — which subsystems a file touches — before an agent edits something central
- Reach for it when you want the agent's map of your code to be something you can read and fix, not an opaque vector index
