# Sync docs: find and fix drift

Find and fix drift between the code and what the project says about it, in a scope you name: uncommitted work, a branch, a pull request or the whole app. Surfaces: docs, the README, AGENTS.md or CLAUDE.md (or the guidelines they are built from), docblocks, site copy, and comments about problems already solved. Read-only until the user says go, then edit-scoped fix rounds.

Your agent loads it when the work comes up, or ask for `sync-docs` by name. Use when the user says 'sync docs', 'are the docs still true', 'check the docs for this change', 'audit the docs', or when a change altered behaviour that a doc describes.

A sweep so a fresh session, an agent and a visitor read only what's true today. It hunts drift, meaning a claim that stopped matching the code, and residue that narrates how something changed. Every claim resolves to a file, a migration, a route, a config key, a test or a dated measurement.

## Scope

Settle the scope first, and ask when it isn't clear from the request:

- **Uncommitted:** the docs the working tree's diff makes false, and the docs it should have touched.
- **A branch:** `git diff <base>...HEAD`, the same way.
- **A pull request:** its diff, read on its branch.
- **The whole app:** every surface, area by area.

A narrow scope still follows a changed name, route or setting to every doc that cites it (`grep` for it), however far away.

## Surfaces

What counts as a doc, unless the project says otherwise:

- Docs folders and the README.
- The agent guidance: `AGENTS.md` or `CLAUDE.md`, or the source they are generated from (`.ai/guidelines`, `.ai/rules`). A generated file is never edited by hand; its finding goes against the source.
- Docblocks and comments.
- Site copy, mails, route and tool descriptions, legal pages.
- **Comments about solved problems:** a `TODO`, `FIXME`, `HACK` or 'temporary' note whose work is done, a workaround for a bug the dependency fixed, a comment that names an issue now closed. Check each against the code and the tracker; a finished one is residue.

`.ai/sync-docs.md`, when the project has one, overrides this list: its Surfaces, Areas (one row per area: the docs it owns and the truth it is checked against), Ground truth, Rounds (what a round ends with: regenerating generated files, a build, the formatter, the tests), Checks and Work log. It's optional; without it, infer the surfaces from the layout and say what you took. Commands it doesn't give come from 'Done means' in the project's guidelines; when there are none, ask.

## Where the work lives

Findings and the fix plan go where the Work log section says: one entry per pass, one section per fix round. Without a Work log, keep them in a scratch file outside the repo, such as `~/.config/altitude/sync-docs/<repo>-<YYYY-MM-DD>.md`, so a later session can resume a pass and nothing lands in a commit by accident. A narrow scope needs no file: the findings go in the reply.

## What every project holds the same

- A file the Surfaces section marks as generated is never edited by hand. A finding in one is filed against its source.
- Code vendored from another repo is read, never edited there. A finding in it is filed against that repo.
- `.ai/sync-docs.md` is a doc like any other, audited by the area that owns the setup files.

## Method: audit, then act

Separate investigation from edits so findings stay reviewable. A requested audit stays read-only. If the user already authorized fixes, including a run from the `finish` skill, apply mechanical doc corrections after the investigation without asking again. Product, legal or scope decisions remain with the user.

1. **Ground truth first.** For a diff scope, the diff itself. Otherwise what `.ai/sync-docs.md` lists under Ground truth, and `git log --oneline -30`: recent commits are where drift concentrates.
2. **For the whole app, fan out one read-only agent per area**, or only the area the user named; a diff scope you read yourself. Give each its row from Areas, the Surfaces table, this file, the residue checklist and the project's Checks, pasted as text: a subagent or a new thread can't load Altitude's skills or read their files. Judgement is the job, so run them on the session's own model, not the subagent default. Each returns `file:line | category | evidence | proposed action`, ranked.
3. **Verify the fan-out stayed read-only.** `git status --short` before and after must match.
4. **Synthesize into the work log**: one 'Findings' section per area; one flat 'Decisions for the user' list for anything that isn't a mechanical fix (operative text, a claim that might be a product decision, a feature a doc promises and the code lacks); one 'Bugs and dead code' list for what the sweep tripped over.
5. **Respect the requested mode.** For an audit, report and stop. For authorized fixes, continue with mechanical corrections and report any decisions that block the rest.
6. **Fix authorized work in edit-scoped rounds**, one round per concern (one guideline or rule file, docblocks in one directory, tool prose, mail copy, site copy, one docs topic), never a round that touches both a guideline and code comments. A round ends with the checklist re-run against the files it touched, then whatever the Rounds section adds for that kind of file.
7. **Verify before reporting done.** Re-grep the changed files for residue. Confirm every count against the source (`grep -c`, a route list, a migration, a query). If code changed, run the formatter from Rounds on the changed files only, never a whole-tree or dirty-files mode, since other sessions may share the tree, then the test command.

## Write the end state

Every rewrite reads as if the current state was always true. Never narrate the change.

- Banned in prose: `now`, `no longer`, `previously`, `used to`, `instead of`, `the old`, `before` where it means an earlier build. A line that teaches the reader something used to exist gets rewritten to describe only what exists.
- A reason survives the rewrite; the story of how it was learned doesn't. Keep a measurement as a dated fact about the data, and drop the narration of the build that produced it.
- A dated measurement isn't drift. 'Measured on 2026-08-20: 412 rows' stays true. It is a finding only when undated, when what it measured is gone, or when the code contradicts the conclusion drawn from it.
- A migration's docblock may describe its conversion: what the table held, what it holds after, and why. Only a false sentence in one is a finding.
- History lives in git, the work log and the project's journal where it keeps one, never in a guideline, a docblock, a tool description or site copy.

## Residue checklist

- Transition language, see above.
- Stale counts. Every undated number stated as current ('four tools', 'nine tables', '16 articles') is re-derived from source, not trusted.
- Dead pointers. Every path, class, method, command, route, config key, env var, tool, prompt, resource URI or `{@see}` a doc cites still exists under that name, and every link in site copy, docs and mails resolves.
- Comments detached from their code: a docblock above the wrong member, two stacked docblocks, a sentence split from its antecedent by a later insertion.
- Work log, brief or session references left in prose after a rewrite.
- A comment that restates the code, narrates or decorates. A comment carries what the code cannot: a reason, a trap, a constraint, a dated measurement.
- The project's writing rules, where its guidelines state them: banned words, punctuation, number format. Words a user sees match `.ai/guidelines/vocabulary.md`.

## Checks in every project

- **The same fact typed more than once.** A status list, a tool list, a limit or a lifetime stated in code, copy, docs, tool instructions and legal pages. Two statements that disagree are a finding; so is a copy that didn't need to exist because a class constant, a config key or a content file already holds the fact. The project's Checks name its facts.
- **Overclaims.** A sentence that promises more than the code keeps, such as enforceability, a review nobody did, 'nothing can be deleted' or 'every call is logged'. Check each against the code. The project's Checks name the phrases it's prone to.
- **The code isn't always the fixed side.** For each mismatch the auditor says which side should yield and why. Where the code should, it goes under bugs; where the doc should, it's a doc finding.
- **Silence is a finding.** Something that exists and no doc mentions is listed, never filled in with what a doc might say.

## Flag, don't silently fix

A drift sweep surfaces real bugs and dead code along the way. Don't fix them mid-sweep: note them in 'Bugs and dead code'. Fix only the doc mismatch itself.

## What not to do

- Treat a read-only audit as permission to edit, or ask again for fixes the user already authorized.
- Hand-edit a generated file, or edit what the Surfaces section marks as never edited in a round.
- Run one round across both a guideline and code comments.
- Cut a fact to make a comment shorter. A reason, a constraint or a dated measurement stays; prose around it goes.
- Assert a count or a claim without re-deriving it from the source.
- Commit or push. That's the user's call.
