| name | doc-audit |
|---|---|
| description | Audit and maintain codebase documentation. Run in a dedicated session, never during development. Invoked when you need a documentation refresh, a codebase audit, or annotation sync. Produces annotations, updates CLAUDE.md manifests, never touches application code. |
Dedicated session. You don't code, you don't fix, you don't refactor. You read and you document.
Four annotations. No more. Every .go file (non-generated, non-test) starts with a contiguous block:
// CLAUDE:SUMMARY One sentence. Single responsibility of the file.
// CLAUDE:DEPENDS pkg/path1, pkg/path2
// CLAUDE:EXPORTS PublicName1, PublicName2CLAUDE:WARN is different. It goes above each dangerous function, not at file head:
// CLAUDE:WARN takes mu.Lock — blocks all Search. Mutates: flatVecs, cache, centroid, nextID
func (idx *Index) Insert(vecs [][]float32, ids [][]byte) error {A WARN documents what the code doesn't say obviously:
- Locks taken and their scope (what other functions are blocked)
- State mutated beyond the function's return values
- Silent errors (return without log, without error returned)
- Startup order or runtime dependencies
- Deployment constraints (shared ports, restart sequences)
- Counter-intuitive decisions (why 2*R and not R)
A WARN is NOT: a TODO, an optimization idea, a godoc comment, a rephrasing of what the code already says.
# Discover active directories dynamically
Glob "**/go.mod" # all Go modules in the monorepo
# Exclude: archives/, dead code dirs
# For each active directory:
Read <dir>/CLAUDE.md
Grep "CLAUDE:SUMMARY" <dir>/ --include="*.go"
Identify gaps: .go files without SUMMARY.
# Go files (non-test, non-generated)
Glob "<dir>/**/*.go" # exclude *_test.go, *.pb.go, *_templ.go
# Compare with Grep "CLAUDE:SUMMARY" results to find gaps
For each file without SUMMARY or with stale SUMMARY:
Grep "^func " <file>— list public functionsRead <file> [1, 10]— see imports and package- Write the SUMMARY + DEPENDS + EXPORTS block
Rules:
- SUMMARY = one sentence, not two. Starts with a verb or noun.
- DEPENDS = local imports (not stdlib, not third-party). Path relative to module.
- EXPORTS = public names actually used by other packages. Not everything exported — what's imported. When in doubt:
Grep "PublicName" ../ --include="*.go"excluding current dir.
For each file, Grep "^func " <file> then read each function.
Add a WARN above if the function:
- Takes a lock (mu.Lock, mu.RLock, rebuildMu)
- Mutates state beyond its parameters (struct fields, globals, cache)
- Does a silent return on error (no log, no error returned)
- Launches a goroutine
- Has a constrained call order (must be called after X)
- Touches network, filesystem, or a shared port
- Contains a counter-intuitive decision that would be "fixed" by a naive developer
Do NOT add a WARN if the function is a pure getter, a side-effect-free helper, or if the behavior is obvious from the signature.
Check each active directory's CLAUDE.md:
- Are the listed invariants still true? (
Grepto verify) - Is there a trap discovered during phases 2-3 that's missing?
- Is the build/test still correct? (
make testif Makefile present) - Do the listed dependencies match the
CLAUDE:DEPENDS?
A local CLAUDE.md is 40-60 lines max. If it's longer, something drifted.
The documentation system has a defined format. Content outside the format isn't necessarily useless — it's often a previous Claude session that documented something in the wrong place or format.
Principle: sort, migrate, then clean. Never delete without migrating useful information.
In .go files — only these CLAUDE: annotations are legitimate:
// CLAUDE:SUMMARY— one per file, line 1, one sentence// CLAUDE:DEPENDS— one per file, after SUMMARY// CLAUDE:EXPORTS— one per file, after DEPENDS// CLAUDE:WARN— above a function, never at file head
# Find any non-standard CLAUDE: annotation
Grep "CLAUDE:" <dir>/ --include="*.go"
# Filter out CLAUDE:SUMMARY, CLAUDE:DEPENDS, CLAUDE:EXPORTS, CLAUDE:WARN
For each result:
- Read the content — is it useful information in the wrong format?
- If yes: migrate to the right annotation (WARN if it's a trap, SUMMARY if it's a description) or to the local CLAUDE.md (if it's a package invariant)
- Only after migration: delete the non-standard annotation
In CLAUDE.md files — manifest format:
- Responsibility (one sentence)
- Dependencies and dependents
- Key files / key types
- Build / test / deploy
- Invariants and known traps
For each out-of-section content:
- Is it a trap or invariant? → migrate to "Invariants and known traps"
- Is it build/deploy info? → migrate to "Build / test / deploy"
- Is it a discovery about a specific function? → migrate to
CLAUDE:WARNon the function in the.gofile - Is it noise without information? → delete
- If in doubt → flag to user, don't delete
Credentials and secrets — mandatory check before any commit:
# Tokens, keys, passwords in documentation and source files — keep as Bash (complex pipe)
grep -rn "Bearer \|sk-\|password\|secret\|token\|api.key\|JWT_SECRET\|SMTP_PASSWORD" --include="*.md" --include="*.go" <dir>/ | grep -vi "variable\|example\|documentation\|placeholder\|change-me" | grep -v "_test.go"A secret found outside test contexts is an emergency:
- Remove immediately from the file
- Flag to user — the secret is in git history, rotation needed
- Do NOT continue the audit before user confirmation
./scripts/generate-index.sh
go test ./conformity-tests/ -vIf conformity tests fail, fix the annotations — not the test.
The user can target:
audit pkg/auth→ single packageaudit service/→ entire servicefull audit→ whole monorepo (expect several hours)
For large scope, process one directory at a time. Don't load the entire INDEX.map.
- Modify application code (logic, control flow, signatures)
- Add features or fix bugs
- Touch functional tests
- Create
.gofiles - Refactor code
- Add godoc comments beyond
CLAUDE:*annotations - Add a WARN on a function with no real trap
- Non-standard
CLAUDE:annotations — AFTER migrating useful information - Duplicate annotations in the same file — keep the most complete
- CLAUDE.md content without information (empty phrases, code rephrasing)
- Credentials and secrets — immediate deletion, user notification
Absolute rule: never delete information without migration. If a previous Claude wrote something, it had a reason. Find it, migrate to the right place, then clean up.
When in doubt: flag, don't delete.