A-000 Living architecture docs for Claude Code and AI coding agents
Architecture docs that stay in sync with your code.
A local script flags the page when the code it cites changes. Your agent updates that page in the same commit. No server, no extra tokens to detect drift.
- Claude Code
- Codex
- Cursor
- Copilot
- Gemini CLI
- OpenCode
Sourceorder_service.py
def submit_order(connection, request_key, sku, quantity): if not isinstance(request_key, str) or not request_key.strip(): raise ValueError("request_key must be a non-empty string") if not isinstance(sku, str) or not sku.strip(): raise ValueError("sku must be a non-empty string") if type(quantity) is not int or quantity <= 0: raise ValueError("quantity must be a positive integer") if type(quantity) is not int or not 1 <= quantity <= 100: raise ValueError("quantity must be an integer from 1 to 100") with connection: connection.execute( "INSERT INTO orders (request_key, sku, quantity) VALUES (?, ?, ?) " "ON CONFLICT(request_key) DO NOTHING", (request_key, sku, quantity), ) order_id, existing_sku, existing_quantity = connection.execute( "SELECT id, sku, quantity FROM orders WHERE request_key = ?", (request_key,) ).fetchone() if (existing_sku, existing_quantity) != (sku, quantity): raise RequestConflict("request_key already identifies different order data") return order_id
Pagedocs/architecture/runtime/submit-order.md
What happens when the caller submits an order?
The library validates the input before it starts a write. It creates an order or finds the order with the same request key. It rejects a repeated key whose SKU or quantity differs.
| Rule order | Condition | Result | Side effect |
|---|---|---|---|
| 1 | Empty or non-string key | ValueError | None |
| 2 | Empty or non-string SKU | ValueError | None |
| 3 | Quantity is not a positive integer | ValueError | None |
| 4 | Existing key has different data | RequestConflict | Transaction rolls back |
| 5 | New key or matching repeated key | Order ID | New record commits, or existing record remains |
Page mapwhat the agent sees at session start
## Architecture handbook (Docanchor) Pages live in `docs/architecture/` (6 pages, 0 stale). Use them to find the right code fast and to learn why it is built this way. Pages summarize; source is authoritative: confirm names, limits, and behavior in the linked source before you answer or change code. STALE means evidence the page cites changed after the last doc sync. After an architectural change, update the affected pages. - `README.md` Understand the order example: The library stores an order and returns its ID. [covers order_service.py] - `context.md` What are the main parts?: The caller runs in the same process as the order library. [covers order_service.py] - `runtime/submit-order.md` What happens when the caller submits an order?: The library validates the input before it starts a write. [covers order_service.py] - `data.md` Where does order data go?: The caller supplies the input. [covers order_service.py] - `glossary.md` Glossary: These are local project definitions, not an official STE vocabulary. - `decisions/ADR-001.md` ADR-001: Identify repeated submissions with a request key [covers order_service.py]
contextBudgetstatus 6 pages, 0 stale. Click Edit the code or the marked lines 25–26.
Real files and real checker output from the order example. The quantity limit is a hypothetical edit, simulated in your browser.
A-101Why
Docs rot in a week. Agents start cold every session.
Docanchor ties each page to the code it cites, so a script can tell which page drifted and your agent knows where to look.
-
The page knows when its code changed
Each page cites functions and line ranges. A changed rule flags that page, even after the commit.
226 of 226 real changes caught
-
Links follow moved code
Code that only moved, or a renamed file, gets its links rewritten. No model, no tokens.
81 of 81 moves followed exactly
-
Your agent starts with a map
One line per page loads at session start. The agent opens the right file first.
405 tokens for this whole repository
-
Claims point at source
Pages link every important claim to code, tests, or a decision. Unknowns stay unknown.
0.04 wrong claims per answer
Already have docs?
It adopts them where they live.
Setup maps your existing ARCHITECTURE.md and decision records, fixes what the code contradicts, and adds pages only for real gaps. Nothing moves.
- 16existing docs adopted
- 3real errors fixed in them
- 4.6minto change, test, and commit a rule with its docs
A-201How
A script finds the drift. Your agent fixes only that.
Detecting drift costs no tokens. Prose is rewritten once per commit, and the docs land in the same commit as the code.
Five steps
- Session start. A hook prints the page map, with stale flags.
- Agent works. Open a documented file and the hook names its page and section.
- Commit gate. A script compares cited code with its baseline. Moved links are rewritten. A commit that would leave pages stale waits once.
- Update. An isolated task reviews only the stale pages.
- Sync. The reviewed pages get a new baseline. Code and docs commit together.
Double-lined boxes are local scripts: no model tokens.
No churn while code is still changing
Three turns that each change cited code, then one commit.
auto
- turn
- update
- turn
- update
- turn
- update
- commit
commit
- turn
- turn
- turn
- held once
- update
- commit
Six commands
/docanchor:setupWrite a handbook, or adopt your docs/docanchor:updateRefresh stale pages/docanchor:checkAudit links, evidence, diagrams/docanchor:explainTrace one flow with a diagram/docanchor:decideDraft a decision record/docanchor:learnTour, quiz, or ask the codebase
Five run in an isolated task, so exploration never fills your conversation. Command guide
A-301Try
Poke it. Every answer below is real output.
Three things Docanchor does that you can test here: judge an edit, find one section, and teach you the code.
A page cites order_service.py#L20-L38. Pick an edit and see what the checker says.
Sourceorder_service.py
def submit_order(connection, request_key, sku, quantity): if not isinstance(request_key, str) or not request_key.strip(): raise ValueError("request_key must be a non-empty string") if type(quantity) is not int or quantity <= 0: raise ValueError("quantity must be a positive integer") with connection:
Fresh
The page matches its baseline.
6 fresh, 0 stale, 0 review, 0 unsynced.
Verdicts are the real output of Docanchor 0.5.0 for each edit on the order example. Lines 23–24 are left out of the excerpt.
Ask the handbook. query returns the section and its line range, so the agent reads a few lines, not a whole page.
What gets loaded
Real output of docanchor.py query on the Docanchor repository at 0.5.0. Word match only: no model and no embeddings.
/docanchor:learn tutors you from the handbook: ask a question, take a tour, or quiz yourself.
Illustration · scripted in this page, not a live model
you/docanchor:learn quiz data flow
Question 1 of 3
A caller submits request key request-1 twice, both times with SKU BOOK and quantity 2. What does the second call return?
- A new order ID
- The same order ID as the first call
- It raises
RequestConflict - It raises
ValueError
Show the graded answer
B. The insert uses ON CONFLICT(request_key) DO NOTHING, then reads the row for that key. The data matches, so the function returns the existing ID. See runtime/submit-order.md, rule 5.
learn <question>A direct answer with source linkslearn tourOne stop per turn, diagram firstlearn quizFive questions, graded against the codelearn changesWhat your branch changed, and why it matters
A-401Proof
Measured, with the failures left in.
Three benchmarks need no model and rerun from the repository. One uses 72 real Claude Code sessions.
Drift accuracy: 420 harmless edits, 226 real ones
0harmless edits flagged
226 / 226real changes caught
One dot is one harmless edit to cited code: a new comment, a moved function, added blank lines. Red dots were flagged as changes. Measured on a real handbook with 81 citations.
Hook time per call
Bash call
Read or Edit
Turn end
0.4.0 0.5.0
Median of nine real processes on a 22-page handbook. Python alone takes 10 ms to start.
With an agent: 72 Claude Code sessions, graded blind
31%
fewer input tokens
26%
fewer turns
32%
lower cost per answer
27%
less time per answer
Key-fact recall, with 95% confidence intervals
The intervals overlap. With 24 answers per condition, differences below about 8 points are noise.
How it compares with other tools
| Docanchor | OpenWiki | deepwiki-skill | DeepWiki | |
|---|---|---|---|---|
| Drift detection | Cited symbols and line ranges, no model | Claim evidence, skips the model when clean | Model-driven update | Hosted regeneration |
| Moved code | Links rewritten automatically | Not stated | Not stated | Not applicable |
| Always-loaded cost | 180 B, plus a map of at most 3 KB | AGENTS.md block, size not stated | About 526 B, plus up to 70 KB per task | MCP tools |
| Published benchmark | Yes, with a failed run | Claim-accuracy replay | None | None |
| Runs | Locally, MIT, no telemetry | Locally, MIT | Locally, MIT | Hosted |
From each project's published documentation on 8 November 2026, not from measurement. OpenWiki and repowise have far larger communities, and code-graph tools answer "who calls this" better. Full survey
Limits of this evidence
- The agent benchmark covers one small repository and 24 answers per condition. Recall differences under 8 points are noise.
- The first version of the map made agents worse (80% recall). That run is published too.
- The drift benchmark makes one edit at a time. It tests citations, not whether a page's prose is right.
- A stale flag means "check this page". It does not prove the prose is wrong.
I-501Install
Three lines in Claude Code. One line everywhere else.
No server, no API key, no telemetry. Python 3.9+ enables the hooks and checks.
- 1InstallAdd the plugin, or the portable skill.
- 2Set upIt writes a small handbook, or adopts your docs.
- 3Keep workingStale pages update when your agent commits.
Claude Code plugin
Run these inside Claude Code. Choose user scope when asked, so Docanchor works in every project.
/plugin marketplace add docanchor/docanchor
/plugin install docanchor@docanchor
/docanchor:setupThat is all. If the project already has architecture docs, setup adopts them where they live (/docanchor:setup adopt, the default then). Otherwise, or with /docanchor:setup new, it writes a handbook under docs/architecture/. It records a freshness baseline. From then on the docs update once per commit, in the same commit as the code. You add nothing to CLAUDE.md.
Codex, Cursor, Copilot, Gemini CLI, and others
The portable Agent Skill installs with skills.sh. In the project directory, with Node.js 22.20+ and Git:
npx skills@1.7.6 add docanchor/docanchor --skill docanchor --agent codex --copy --yesReplace codex with cursor, github-copilot, gemini-cli, opencode, roo, or devin, or add --global for a user-level installation. Then ask your agent:
Use the Docanchor skill to set up architecture documentation for this project.
Setup offers to write the page map into AGENTS.md, which these agents read every session. To write it yourself, set { "contextFile": "AGENTS.md" } in .docanchor.json and run:
python <skill-dir>/scripts/docanchor.py context --root . --writeGit hooks with pre-commit
Works with any editor or agent. Add Docanchor to .pre-commit-config.yaml:
repos:
- repo: https://github.com/docanchor/docanchor
rev: v0.5.0
hooks:
- id: docanchor # one gate: fix moved links, check structure, stop when cited code changedpre-commit installThe docanchor hook runs on every commit. It rewrites links to code that only moved, fails on structural errors, and fails when a staged file changes code that a page cites. Pages that were already stale do not block the commit. rev: v0.5.0 pins the latest release.
CI check on pull requests
This GitHub Actions job fails a pull request whose code changes leave pages stale. Copy docanchor.py into your repository first, for example as tools/docanchor.py, or check out the Docanchor repository in the job.
name: architecture-docs
on: pull_request
permissions:
contents: read
jobs:
freshness:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: "3.13"
- run: python tools/docanchor.py check --root . --summary
- run: python tools/docanchor.py status --root . --fail-on-stale- No serverNothing leaves your machine
- No telemetryNo network calls at all
- MITDependency-free Python
- Upgrading?Run
sync --freshonce
D-601Docs
Find the page you need.
The guide on this site covers daily use. The repository holds the full reference.
01Start
02Use
03Automate
04Reference
Q-701Questions
Questions people ask before they install.
Short answers. The guide has the detail.
What is Docanchor?
Docanchor is a Claude Code plugin and a portable Agent Skill that keeps architecture docs in sync with your code. It writes a small, source-linked handbook or adopts the docs you already have. A local script flags pages whose cited code changed, and an isolated task updates them, by default in the same commit as the code. It also gives your coding agent a page map of the project in a few hundred tokens.
How is Docanchor different from DeepWiki or OpenWiki?
DeepWiki regenerates a hosted wiki and serves it through the web and MCP. OpenWiki ties claims to line-range evidence and updates through a manual run or a scheduled CI pull request. Docanchor keeps the docs in your repository, detects drift on the exact functions and line ranges each page cites with a local script and no model, and updates only the stale pages. Its always-loaded map has a byte budget that CI enforces. The comparison on A-401 compares more tools; vendor claims there are as published.
Which coding agents does it support?
Claude Code gets the native plugin with hooks. Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Roo, Devin, and other agents get the portable Agent Skill through skills.sh, and any agent that reads AGENTS.md can get the page map. The pre-commit hooks and the CI check work with any editor or agent.
Does it need a server, an API key, or send telemetry?
No. Docanchor has no server, no telemetry, and makes no network calls. The Claude Code plugin needs no API key or Node installation; Python 3.9+ enables the hooks and checks. Your agent’s normal subscription or API usage and provider policy still apply. The skills CLI that installs the portable skill has its own telemetry; set DISABLE_TELEMETRY=1 to opt out.
What does keeping docs current cost?
Detecting drift costs no model tokens, because it is a local script. By default, prose is rewritten once per commit that leaves pages stale. In the real-project trial, an update after two real code changes took 93 seconds and $0.40 on Opus, and a whole change, test, and commit task with its docs took 4.6 minutes and $1.25. That is one trial on one repository.
Does it work with the docs I already have?
Yes. In a project with architecture docs, /docanchor:setup adopt, the default then, maps them where they live, fixes statements the code contradicts with minimal edits, adds pages only for real gaps, and uses your decision-record folder and numbering. Mapped docs get the same checks and freshness tracking as new pages.
How do I install it?
In Claude Code, run /plugin marketplace add docanchor/docanchor, then /plugin install docanchor@docanchor, then /docanchor:setup. For other agents, run npx skills@1.7.6 add docanchor/docanchor --skill docanchor --agent codex --copy --yes in the project, and replace codex with your agent.
Free, MIT-licensed, and built in the open.
If Docanchor keeps your docs honest, star the repository so other developers can find it. Bug reports and ideas are welcome.