diffctx — smart diff context for LLM code review
diffctx selects the minimum code an LLM needs to review a git diff. Instead of pasting whole files, it walks the dependency graph outward from the changed lines and stops once more context stops paying for itself.
Coming from
treemapper? That name is deprecated. Every command, flag, and API call works unchanged:treemapper→diffctx,treemapper-mcp→diffctx-mcp.
Why not just use tree or repomix?
tree |
repomix | Claude Code Review | diffctx | |
|---|---|---|---|---|
| Primary use case | directory listing | full repo export | automated PR review | diff context for code review |
| Smart diff context | ✗ | ✗ | ✓ | ✓ |
| Works with any LLM | ✓ | ✓ | Claude only | ✓ |
| Free / local / offline | ✓ | ✓ | $15–25/review | ✓ |
| GitHub required | ✗ | ✗ | ✓ | ✗ |
| Multiple output formats | ✗ | limited | — | YAML/JSON/MD/txt |
| Python API | ✗ | ✗ | ✗ | ✓ |
| MCP server | ✗ | ✗ | ✗ | ✓ |
Install
Without Python:
The image runs as a non-root user (uid 10001) and writes to stdout — the
native binary has no -o flag, so redirect to capture: ... --diff HEAD~1 > context.yaml.
Prebuilt binaries for linux (x86_64/aarch64), macOS (arm64) and Windows (x64)
are attached to every release.
The native binary covers diff mode with YAML/JSON output; tree mode, Markdown
output, the graph subcommand and the MCP server live in the Python package.
cargo add diffctx embeds the pipeline in a Rust project — the library is
imported as _diffctx (use _diffctx::pipeline::build_diff_context), since
the crate doubles as the Python extension module
(docs.rs).
Quick start

diffctx . --diff HEAD~1 selects only the fragments an LLM needs to review the
last commit, instead of dumping every changed file in full.
Diff context mode
Finds the minimal set of fragments needed to understand a change — imports,
callers, type definitions, config dependencies — across 50+ file types. It
builds a code graph (imports, co-changes, type refs), propagates relevance
outward from the changed lines, and stops when relevance drops below --tau or
the --budget token cap is hit.
| Flag | Default | Description |
|---|---|---|
--scoring |
ego |
ego = bounded expansion around changed nodes (fast, predictable radius); ppr = Personalized PageRank (global, smoother decay, slower); bm25 = lexical retrieval against the diff hunks (baseline for sparse graphs) |
--budget |
auto | Hard token cap: N enforces a fixed cap, -1 disables it, 0 is a strict-zero floor (empty selection; use --full for changed files only) |
--alpha |
0.60 | PPR damping; higher = context clusters tighter around changes (--scoring ppr only) |
--tau |
0.12 | Relevance threshold for full fragment content; lower-scoring fragments are stubbed or dropped (lower = more context) |
--full |
false | Only the changed files, every fragment, no related-code context |
--timeout |
300 | Wall-clock deadline in seconds; on expiry diffctx exits 124 instead of hanging |
Calibration of --alpha, --tau, and the edge-weight priors:
docs/engineering/parameter-strategy.md.
Theory:
diffctx: Budgeted Typed-Graph Retrieval for Diff-Aware Code Context
Selection (Zenodo, 2026).
graph subcommand
Explore the underlying dependency graph directly, without a diff:
Usage
# full codebase export:
# diff context mode (requires git repo):
Every run reports token count and size on stderr — 12,847 tokens (o200k_base), 52.3 KB (tiktoken, the GPT-4o tokenizer; ~-prefixed above
1 MB). -c/--copy copies output via pbcopy (macOS), clip (Windows), or
wl-copy/xclip/xsel (Linux). Unreadable files become placeholders like
<binary file: N bytes>, <file too large: N bytes>, or
<unreadable content: not utf-8>.
Python API
=
=
MCP server
diffctx includes an MCP server that lets AI
assistants (Claude Code, Cursor, Windsurf, etc.) call diff context analysis
automatically during code review. Install with pip install 'diffctx[mcp]',
then register it — for Claude Code:
The server exposes three tools — get_diff_context, get_tree_map, and
get_file_context — that assistants call when reviewing PRs, explaining
changes, or investigating broken tests. Tool reference and configs for
Cursor, Continue, Windsurf, and Zed:
src/diffctx/mcp/README.md.
Ignore patterns
Respects .gitignore and .diffctx/ignore automatically — hierarchically at
every directory level, with full gitignore semantics (negation !important.log,
anchored /root_only.txt). .diffctx/whitelist acts as an include-only filter,
and the output file is always auto-ignored. --no-default-ignores disables the
built-in patterns; --no-ignores disables all ignore rules (tree mode only).
Token cache
Diff mode caches per-blob tokenization under
~/Library/Caches/diffctx/token-cache (macOS),
$XDG_CACHE_HOME/diffctx/token-cache (Linux) or
%LOCALAPPDATA%\diffctx\token-cache (Windows). It is a pure speedup: deleting
it only costs one cold run.
| Variable | Effect |
|---|---|
DIFFCTX_TOKEN_CACHE_DIR |
Relocate the cache |
DIFFCTX_TOKEN_CACHE_MAX_BYTES |
Size cap, default 536870912 (512 MB); 0 disables eviction |
Eviction is amortized: each run trims one of the cache's 256 shards back under its share of the cap, oldest entries first.
Exit codes
| Code | Meaning |
|---|---|
0 |
Success — output contains content |
1 |
Runtime error (bad path, permission denied, etc.) |
2 |
Usage error (invalid flags/arguments) |
3 |
Environment error (--diff outside a git repo, git not installed, no commits yet) |
4 |
--diff produced no semantic context (clean tree, binary-only, everything filtered); output is still emitted. Deletion/rename/lockfile-only diffs list deleted_files/renamed_files/lockfile_changes and exit 0 |
124 |
--diff exceeded the --timeout wall-clock deadline |
130 |
Interrupted (Ctrl-C) |
141 |
Broken pipe (e.g. piping into head) |
Repository layout
Rust product code lives in crates/diffctx-native/; the Python CLI and MCP
package live in src/diffctx/. Evaluation code, immutable datasets, and paper
artifacts are intentionally separated under eval/, datasets/, and paper/.
See repository ownership boundaries
for the lifecycle and entry point of each area.
License
Apache 2.0
- Documentation site — the pipeline end to end: diff → fragments → graph → relevance → selection
- Changelog
- Security policy — threat model and vulnerability reporting
- Parameter strategy — how
--alpha,--tau, and edge weights are calibrated