A file-based knowledge graph
for your coding agent.

2context extracts architectural decisions, conventions, and patterns from your git history and writes them as plain Markdown files. Coding agents like Claude Code read those files directly the same way they read any other file in your repo. No MCP server, no daemon, no API.

$ npm install -g 2context
$ cd your-repo && 2context init

or run without installing: npx 2context init

What you can't write by hand.

Markdown for agent context is not new. What is new is what ends up in those files, how they stay organized, and how the agent picks them up without your prompting.

Intent extracted from commits. The why behind decisions (why this DB, why that boundary) gets reconstructed from diffs and commit messages, including reasoning that never made it into a doc anyone bothered to write.

Self-organizing graph. As items pile up, LLM clustering splits overfull category folders into subfolders and merges underfull ones. The structure stays navigable instead of decaying into a flat dump.

Auto-discovered by the agent. A ## Knowledge Context block is written into CLAUDE.md / AGENTS.md instructing the agent to read the index before any task. No prompt engineering required.

Validated, not just appended. Items are tied to source provenance (commits, files). When the underlying code disappears, 2context validate drops the stale item so the graph does not drift from reality.

The ingest pipeline

Run 2context ingest after merges (or in CI) to keep the graph current. State is tracked per source, so each run only processes commits added since the last cursor.

1

Fetch new commits

Reads commits since the last cursor (full history on first run). Skips merges, dependency bumps, and formatting-only changes.

2

Cluster and extract

An LLM groups related commits into feature units, then reads the diffs and extracts knowledge items with category, summary, content, and source provenance.

3

Write to disk

Items are written to co-located KNOWLEDGE.md files next to the code they describe, and to the central graph at .2context/graph/{category}/.

4

Rebalance and validate

Overfull category folders get split into subcategories via LLM clustering. Underfull folders get merged. 2context validate drops items whose source has disappeared.

5

Update agent file

A ## Knowledge Context section is written into CLAUDE.md or AGENTS.md instructing the agent to read .2context/KNOWLEDGE_GRAPH.md before starting any task.

What lands in your repo

Two output planes: co-located files next to the code they describe, and a central graph indexed by a single entry point at .2context/KNOWLEDGE_GRAPH.md.

your-repo/
├── .2context/
│ ├── KNOWLEDGE_GRAPH.md   # index the agent reads first
│ ├── graph/
│ │ ├── architecture/   # split into subfolders when full
│ │ ├── convention/
│ │ ├── decision/
│ │ └── pattern/
│ └── sources/git-commits/state.json   # cursor (gitignored)
├── src/auth/KNOWLEDGE.md   # co-located items
├── src/db/KNOWLEDGE.md
└── CLAUDE.md   # auto-updated Knowledge Context section
architecture

Structural decisions

Module boundaries, data flow, layer responsibilities.

convention

Code style rules

Naming, file organization, error handling, import patterns.

decision

Technical choices

Why this library, why not that approach, with context intact.

pattern

Reusable solutions

Recurring implementation approaches across the codebase.

Git today, more later.

The current build ships with one adapter: git-commits. The pipeline is built around a generic adapter interface, so additional sources can feed the same graph without changing how it is consumed.

shipping

git-commits

Reads commits, groups them into feature units, extracts items with traceable source refs (commit SHA, files touched).

planned

pull requests

Capture review discussions, rejected approaches, and the decisions that landed in PR descriptions.

planned

issues & ADRs

Pull existing architecture docs, ADRs, and issue threads into the same graph the agent already reads.

planned

your sources

The adapter contract is small. Anything that can produce material units with provenance can plug in.

Bring your own model

Configure via env vars or the interactive wizard on first run. Keys stored in ~/.2context/keys.json (chmod 600).

Anthropic
claude-sonnet-4
claude-haiku-4-5
claude-opus-4
OpenAI
gpt-4o
gpt-4o-mini
o3-mini
Google
gemini-2.5-flash
gemini-2.5-pro
gemini-2.0-flash

Install and run

Works in any git repository. Node.js ≥ 22 required.

$ npm install -g 2context
$ cd your-repo && 2context init

Full docs on GitHub  ·  npm  ·  report an issue