Docanchor Guide 0.5.0
Home Docanchor source on GitHub

G-100Start

Install it, run setup, keep working.

Five minutes from nothing to a handbook that tells you when it is out of date.

Install

Claude Code

Run these inside Claude Code. Choose user scope, so Docanchor works in every project.

/plugin marketplace add docanchor/docanchor
/plugin install docanchor@docanchor
/docanchor:setup

Codex, Cursor, Copilot, Gemini CLI, OpenCode, and others

Install the portable Agent Skill in the project folder. Replace codex with your agent.

npx skills@1.7.6 add docanchor/docanchor --skill docanchor --agent codex --copy --yes

Then ask your agent:

Use the Docanchor skill to set up architecture documentation for this project.

Needs Python 3.9+ on PATH for the hooks and checks. The macOS system Python works. No API key, server, or Node for the plugin.

First run

Setup starts small: the system boundary, the main units, and one important journey. It grows by risk, not by file count.

No docs yet: setup new

docs/architecture/
  README.md            Reading path and known gaps
  context.md           Users and external systems
  runtime/             Flows, failures, recovery
  data.md              Ownership and lifecycle
  decisions/ADR-*.md   Why, with alternatives
  glossary.md          One term per concept
  map.json             Which code each page covers

Docs exist: setup adopt (default)

docs/architecture/map.json
  ../ARCHITECTURE.md   Mapped where it lives
  ../adr/*.md          Your decision folder
  runtime/*.md         New pages for real gaps

Setup fixes statements the code contradicts with small edits. It does not move or restyle your documents.

Setup ends with sync. That records a baseline for every page in .docanchor-state.json. Commit the handbook and that file.

Upgrade

After you update Docanchor, record fresh pages again once. This moves their fingerprints to the current format and approves nothing new.

python3 <docanchor>/scripts/docanchor.py sync --root . --fresh

G-200Use

Six commands. One of them you rarely type.

The hooks run update for you. The rest are there when you want them.

Commands

CommandUse it toEdits
/docanchor:setupWrite a small handbook, or adopt the docs you haveDocs
/docanchor:updateFix stale pages, confirm review pages, then sync themDocs
/docanchor:checkAudit links, evidence, diagrams, and freshnessNothing
/docanchor:explain <flow>Trace one flow with a diagram and a source-linked step tableNothing
/docanchor:decide <choice>Draft a decision record with options and tradeoffsDocs
/docanchor:learnAsk, tour, quiz, or review your branchNothing

Context Five commands run in an isolated task, so exploration stays out of your conversation. learn runs inline so you can ask follow-ups. In other agents, ask for the same operation by name.

Page states

StateMeaningWhat to do
freshNothing the page covers changed since its last syncNothing
staleCode the page cites changed, or was removed or renamedCheck the page, edit it if needed, then sync it
reviewOnly other covered files changedA quick look; the page is probably right
unsyncedThe page has no baseline yetVerify it, then sync it

A comment, a blank line, or code that only moved never makes a page stale. Moved links are rewritten for you.

Remember A stale flag means "check this page". It does not prove the prose is wrong.

Query

Read one section, not a whole page. Every result has a line range to open.

FormReturns
query <words>Sections ranked by word match
query --file <path>Sections that cite the file, with the cited line ranges
query --page <page>The page outline: sections, sizes, diagram types
query --page <page> --diagramOne diagram as Mermaid source, with its text equivalent
query --page <page> --step 7The step-table row for message 7 of a sequence diagram
query --page <page> --row <text>Table rows whose first cell contains the text

Read the diagram first. It is the shortest complete view of a flow. Then ask for one step or one unit.

Learn

  • /docanchor:learn <question>A direct answer in at most 150 words, with source links
  • /docanchor:learn tourThe reading path, one stop per turn, diagram first
  • /docanchor:learn quiz [topic]Five questions about real behavior, graded against the code
  • /docanchor:learn changesWhat your branch changed, and which flow it affects

G-300Automate

Detection is free. Choose when prose is rewritten.

A local script finds drift with no model. An agent rewrites only the pages it flags.

Hooks in Claude Code

The plugin's hooks work after installation. Set autoUpdate in .docanchor.json to choose when stale pages are refreshed.

autoUpdateAfter each turnWhen Claude commitsModel use
offNothingNothingNone
remindOne message per new set of stale pagesNothingNone
commit (default)One messageHolds the commit once, updates the pages, commits code and docs togetherOne update per commit
autoRuns the updateSame as commitOne update per turn
  • Session start loads the page map, at most 3,000 bytes.
  • Read or Edit of a documented file names its page and section, once.
  • Turn end rewrites moved links and reports new stale pages.
  • Commit waits once while it would leave pages stale.

Other agents Set "contextFile": "AGENTS.md" and run context --write. The agent then sees the page map in every session.

Commit gate

One pre-commit hook for any editor or agent. It needs no model.

repos:
  - repo: https://github.com/docanchor/docanchor
    rev: v0.5.0
    hooks:
      - id: docanchor
  1. Moved codeRewrites the links, and fails once so you stage the rewrite.
  2. StructureFails on broken links, anchors, fences, and map errors.
  3. Cited code changedFails when a staged file changes code that a page cites.

Pages that were already stale do not block an unrelated commit. To report without failing, add args: [--stale, warn].

CI

Fail a pull request that leaves pages stale. Copy docanchor.py into your repository first, for example as tools/docanchor.py.

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

Never let an automated job mark pages reviewed or decisions accepted.

G-400Reference

Look it up.

The short version is here. Each part links to the full reference in the repository.

CLI

The checker is dependency-free Python. Everything is read-only except sync, fix-anchors, precommit, and context --write.

docanchor.py status --root .                 # fresh, stale, review, unsynced
docanchor.py check --root . --strict         # links, anchors, diagrams, references
docanchor.py check --root . --style          # also gate the mechanical style rate
docanchor.py query --root . retry limit      # sections with line ranges
docanchor.py cite --root . src/orders.py submit_order
docanchor.py fix-anchors --root .            # rewrite links to moved code
docanchor.py sync --root . --page FLOW-001   # record a verified page
docanchor.py precommit --root .              # the commit gate
docanchor.py context --root . --write AGENTS.md
docanchor.py impact --root . --base main     # pages a branch may affect

Full CLI reference

Configuration

Defaults work. To change them, add .docanchor.json to the project, or ~/.config/docanchor/config.json for every project.

KeyWhat it setsDefault
docsRootWhere the handbook livesdocs/architecture
autoUpdateWhen Claude refreshes stale pagescommit
contextBudgetMost bytes for the page map3000
contextFileA file that also gets the map, such as AGENTS.mdnull
sessionContextLoad the map at session starttrue
filePointersName the page for a file the agent openstrue
fixAnchorsRewrite links to code that only movedtrue
styleTargetPass rate that check --style requires0.8
maxDiagramNodesFlowchart nodes before a density note12
maxSequenceParticipantsSequence participants before a density note7

Full configuration reference

Files

FileHoldsCommit it?
map.jsonEvery page: its ID, kind, review state, and the code it coversYes
.docanchor-state.jsonThe baseline that sync records: content IDs and citation fingerprintsYes
.docanchor.jsonProject settingsYour choice

Limits

  • Code shows what happens, not why a person chose it. Decisions stay proposed until a human accepts them.
  • Python and C-family files get symbol-level fingerprints. The C-family reader is a heuristic, not a parser.
  • A cited sub-range follows its own lines. Cite the whole function to catch a new condition wrapped around it.
  • Docanchor has no server, no telemetry, and no network calls. Your agent's provider policy still applies.
  • The writing style is STE-inspired, not certified ASD-STE100.