Docanchor Rev 0.5.0
Guide Docanchor source on GitHub

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
Try it: change the code, watch the page Real files from examples/order-service

Sourceorder_service.pylines 20–38

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")
    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.mdFLOW-001

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 orderConditionResultSide effect
1Empty or non-string keyValueErrorNone
2Empty or non-string SKUValueErrorNone
3Quantity is not a positive integerValueErrorNone
4Existing key has different dataRequestConflictTransaction rolls back
5New key or matching repeated keyOrder IDNew record commits, or existing record remains
Page mapwhat the agent sees at session start1,131 bytes
## 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]
≤ 3,000 bytes · default contextBudget
1,131 B

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.

  • STALE

    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

  • #L20-L38 #L23-L41

    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.

The freshness loop Hover or focus a callout
The Docanchor freshness loop Session start loads the page map with stale flags. The agent works and edits covered code. The Stop hook flags stale pages when a turn ends, and the commit gate holds a commit that would leave pages stale. Update reviews them in an isolated task. Sync records the new baseline, code and docs commit together, and the next session starts from there. ≤ 3,000 B Session start Hook prints the page map with stale flags Agent works Opened files name their page once Commit gate Stop hook flags pages; a commit waits once Update Isolated task reviews only the stale pages Sync Records each reviewed page’s new baseline page map + stale flags turn end · git commit commit | auto verified pages code + docs commit next session local script · no model tokens agent work · uses tokens 1 2 3 4 5 The Docanchor freshness loop, vertical layout: session start, agent works, commit gate, update, sync, then code and docs commit together and the loop returns to session start. ≤ 3,000 B Session startHook prints the page mapwith stale flags Agent worksOpened files nametheir page once Commit gateStop hook flags pages;a commit waits once UpdateIsolated task reviewsonly the stale pages SyncRecords each reviewedpage’s new baseline map + stale flags turn end · commit commit | auto verified pages code + docs commit · next session local script · no tokens agent work · uses tokens 1 2 3 4 5

Five steps

  1. Session start. A hook prints the page map, with stale flags.
  2. Agent works. Open a documented file and the hook names its page and section.
  3. Commit gate. A script compares cited code with its baseline. Moved links are rewritten. A commit that would leave pages stale waits once.
  4. Update. An isolated task reviews only the stale pages.
  5. 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

  1. turn
  2. update
  3. turn
  4. update
  5. turn
  6. update
  7. commit

commit

  1. turn
  2. turn
  3. turn
  4. held once
  5. update
  6. 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.pycited: L20–L38

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.

docanchor.py status

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.

this repository's handbook


        

What gets loaded

These sections
The whole page
Every page

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.

A quiz on the order example

Illustration · scripted in this page, not a live model

you/docanchor:learn quiz data flow

docanchor

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?

  1. A new order ID
  2. The same order ID as the first call
  3. It raises RequestConflict
  4. 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 links
  • learn tourOne stop per turn, diagram first
  • learn quizFive questions, graded against the code
  • learn 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

36 ms14 ms

Read or Edit

55 ms34 ms

Turn end

218 ms103 ms

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

no handbook24,952 docanchor17,253

26%

fewer turns

no handbook4.2 docanchor3.1

32%

lower cost per answer

no handbook$0.022 docanchor$0.015

27%

less time per answer

no handbook9.6 s docanchor7.0 s

Key-fact recall, with 95% confidence intervals

The intervals overlap. With 24 answers per condition, differences below about 8 points are noise.

no handbook86% (79–94)
handbook only84% (76–92)
docanchor89% (82–95)
How it compares with other tools
DocanchorOpenWikideepwiki-skillDeepWiki
Drift detectionCited symbols and line ranges, no modelClaim evidence, skips the model when cleanModel-driven updateHosted regeneration
Moved codeLinks rewritten automaticallyNot statedNot statedNot applicable
Always-loaded cost180 B, plus a map of at most 3 KBAGENTS.md block, size not statedAbout 526 B, plus up to 70 KB per taskMCP tools
Published benchmarkYes, with a failed runClaim-accuracy replayNoneNone
RunsLocally, MIT, no telemetryLocally, MITLocally, MITHosted

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.

Method, raw data, and how to rerun every number

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.

  1. 1InstallAdd the plugin, or the portable skill.
  2. 2Set upIt writes a small handbook, or adopts your docs.
  3. 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:setup

That 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 --yes

Replace 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 . --write

Git 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 changed
pre-commit install

The 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 --fresh once

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.