codebase → context engine

The minimum code an LLM needs to review a git diff.

Instead of pasting whole files, diffctx walks the dependency graph from the changed lines outward — and stops as soon as additional context stops paying for itself. Every trade-off optimized for comprehension-per-token.

watch it work ↓
0
tokens — changed files pasted whole
0
tokens — diffctx selection, same review
denser signal
imports · callers · types · config · docs
01

Five stages, one pass.

This is a live model of the pipeline — a toy repository of 18 fragments, scored and selected in your browser with the same rules the engine uses: relevance decays with graph distance, selection is greedy, and the budget is a hard wall. Step through the stages, then drag the dials.

diffctx · toy-repo stage 1 — diff
context
0 tokens · 0 fragments
stdout yaml · o200k_base
02

Six ways code is related.

A diff rarely lives inside one file. Each edge family is a separate builder; their weighted union is the graph relevance flows across.

03

Three scoring modes.

Pick one with --scoring. All three feed the same greedy selector.

ego

--scoring ego

Bounded ego-network expansion around the changed nodes. Fast, predictable radius, natural decay with distance.

ppr

--scoring ppr --alpha 0.6

Personalized PageRank with damping α. Global view, smoother decay, catches long-range structure — at a cost in speed.

bm25

--scoring bm25

Lexical retrieval of fragments against the diff hunks. The honest baseline — and the fallback when the graph is sparse.

04

Thirty seconds.

$ uvx diffctx . --diff HEAD~1zero-install, run once via uv
$ pipx install diffctxrecommended — isolated CLI
$ pipx install 'diffctx[mcp]'+ MCP server for Claude Code / Cursor / Zed
$ diffctx . --diff main..feature -cbranch context → clipboard → any LLM
$ diffctx graph . --summarycycles, hotspots, coupling

Free, local, offline. Works with any LLM. Python API and standalone binaries included. Theory: Context-Selection for Git Diff (Zenodo, 2026).