On this page#
What changes when an agent does this#
Documentation stops being primarily a writing task and becomes a verification task. An agent can inspect the repository, trace behavior, and draft explanations quickly; the bottleneck moves to proving that its claims match the code, preserve the repository’s invariants, and describe supported behavior without turning implementation details into accidental promises.
Claude Code is an AI coding agent that works with a codebase and follows instructions to perform development tasks. That repository access makes it useful for documentation, but access is not understanding. It can find a branch in the code and still misunderstand whether that branch represents a public guarantee, a migration path, or a defensive fallback.
The workflow therefore changes from:
- Read code.
- Write documentation.
- Edit for clarity.
To:
- Define the documentation contract.
- Gather evidence from the repository.
- Draft from that evidence.
- Review every behavioral claim.
- Accept or reject the patch as a whole.
- Roll back cleanly if the evidence does not hold.
The important word is contract: the set of claims a reader should be able to rely on after reading the page. A generated paragraph that sounds accurate but overstates this contract is worse than missing documentation because it creates a false interface.
This is also why “ask the agent to document the feature” is the wrong prompt. It combines discovery, interpretation, drafting, and validation into one opaque step. The official Claude Code overview explains the agent and its coding workflow; it does not remove the need to separate those decisions.
Photo by Christina Morillo on Pexels.
The prompt chain#
Use a chain of constrained prompts, not one ambitious request. Each phase should produce an inspectable artifact and narrow the next phase: first scope, then evidence, then claims, then prose, and finally a review report. The agent may move quickly, but it should never silently decide what the repository promises.
1. Establish scope and invariants#
We need to document
[feature or workflow]. Do not edit files yet. Identify the relevant implementation, tests, configuration, existing documentation, and public interfaces. List the repository invariants this documentation must not contradict. Separate confirmed facts from unresolved questions.
This prompt blocks premature drafting. “Relevant” code is not enough; the agent must also find tests, configuration, and existing docs that constrain what the implementation means.
The confirmed-versus-unresolved split matters because fluent prose hides uncertainty. If the agent cannot establish a claim before writing, that claim should remain visible as a question rather than being smoothed into a sentence. The Claude Code documentation is the authority for operating the tool, while the repository remains the authority for the behavior being documented.
2. Build an evidence map#
Create an evidence map for the proposed documentation. For each potential claim, provide: the claim, the supporting repository location, whether it is public behavior or an implementation detail, and what could make the claim misleading. Do not draft documentation.
An evidence map forces traceability. It also catches the most common category error: treating a current code path as a stable user-facing guarantee.
Use a compact table:
| Proposed claim | Evidence | Status | Risk | |---|---|---|---| | User-visible behavior | Implementation and tests | Confirmed or unresolved | Overstatement | | Configuration rule | Schema or validation path | Confirmed or unresolved | Missing exception | | Failure behavior | Error path and tests | Confirmed or unresolved | Confusing fallback with guarantee |
Do not accept “the code suggests” as confirmation. A branch may be unreachable, retained for compatibility, or guarded by configuration the draft has not mentioned.
3. Draft within the evidence#
Draft the documentation using only confirmed claims from the evidence map. Explain prerequisites before procedures. Include failure behavior and recovery where supported. Do not infer defaults, compatibility, guarantees, or supported use cases. Mark any required but unsupported statement as
[NEEDS HUMAN DECISION].
This prompt turns uncertainty into an explicit review item. The marker is intentionally ugly: unresolved product decisions should interrupt the document rather than disappear inside polished copy.
Ask for the smallest useful patch. Documentation generation becomes harder to review when the agent also reorganizes navigation, rewrites adjacent pages, normalizes terminology across the repository, and “cleans up” examples. Those may be worthwhile changes, but they are separate changes.
For a broader progression from scoped drafting to controlled repair, use the free PairFoundry foundations track. The point is not more prompting technique; it is learning where human judgment must remain visible.
4. Run an adversarial review#
Review the draft against the evidence map and repository. List every sentence that states behavior, defaults, requirements, compatibility, security properties, or failure handling. For each sentence, classify it as supported, overstated, ambiguous, or unsupported. Do not edit yet.
This is the highest-value prompt in the chain. Ordinary copyediting rewards confidence and flow; adversarial review rewards boundaries.
Only after reviewing the report should you ask:
Revise only the overstated, ambiguous, or unsupported sentences approved below. Preserve unrelated wording and structure. Return a concise summary of changed claims and remaining human decisions.
The PairFoundry Review and Repair pack is the natural next step when this review gate needs to become a repeatable team practice. The other available workflows are listed in the PairFoundry packs overview.
The gate#
The gate is a human review of claims, not a quick reading of the prose. Stop before accepting the patch and inspect every statement about behavior, configuration, defaults, failure handling, compatibility, and guarantees. If a reviewer cannot point from a claim to evidence, that claim does not ship.
Review in this order:
- Scope: Does the page document the intended interface rather than everything the agent discovered?
- Behavior: Does each procedural step match the actual control flow?
- Boundaries: Does the draft distinguish supported behavior from implementation detail?
- Failure: Does it explain what the user sees when the happy path breaks?
- Examples: Are names and values illustrative, or could readers mistake them for defaults?
- Diff: Did the agent touch anything outside the approved documentation scope?
Do not start with grammar. A beautifully edited false claim is still false.
The reviewer should reject the patch when unresolved markers remain, evidence is indirect, or the document promotes incidental behavior into a promise. The official overview can clarify what Claude Code is designed to do, but it cannot validate the semantics of your repository. That responsibility stays inside the gate.
Photo by Lukas Blazek on Pexels.
What it gets wrong#
Claude Code most often fails here by producing a coherent explanation from incomplete evidence. The warning sign is not awkward prose; it is prose that removes distinctions the code preserves—optional versus required, current versus guaranteed, recoverable versus fatal, or internal versus public.
Watch for these failure modes:
- Implementation becomes contract. A current function or flag is described as a supported interface. Check whether tests and existing public documentation establish that status.
- Defaults appear from examples. A sample value becomes “the default” without evidence from configuration or validation.
- The happy path consumes the page. Setup is detailed, but partial failure, retries, cleanup, and recovery are absent.
- Nearby systems are merged. Similar commands, modes, or configuration layers are described as interchangeable.
- Negative behavior is invented. The draft says something “will never,” “cannot,” or “always” happens when the code proves only one positive path.
- Scope expands during cleanup. The documentation patch quietly changes terminology or structure outside the feature under review.
Recognition is mechanical: underline every absolute term, every default, every requirement, and every claim about errors. Then demand evidence. If the evidence map cannot support the sentence, weaken it, remove it, or escalate it to a human decision.
More workflow patterns belong in the PairFoundry workflows hub, but the governing rule remains simple: an agent may propose the contract; it cannot authorize the contract.
Rollback#
Rollback should restore the exact pre-documentation state without reconstructing edits by hand. Keep the documentation change isolated, inspect the final diff before acceptance, and discard or revert the complete patch when its claims cannot be validated. Partial rescue is appropriate only after the trustworthy lines have been identified independently.
Use this sequence:
- Record the starting state before the agent edits.
- Keep generated changes limited to the approved files.
- Review the complete diff, including navigation and configuration.
- If the gate fails, return to the recorded state using the repository’s normal version-control workflow.
- Re-run the chain with narrower scope and explicit rejected claims.
- Accept salvaged text only after it passes the same evidence review.
Do not ask the agent to “undo the bad parts” while leaving it to decide which parts were bad. That repeats the original failure inside the recovery step.
Rollback is also a documentation-quality signal. If a generated change is too entangled to remove cleanly, the scope was too broad. The operational guidance in the Claude Code documentation can support tool usage, but clean reversibility must be designed into your repository workflow.
Photo by Digital Buggu on Pexels.
Related reading#
- Claude Code security, with the guardrails that keep it honest
- GitHub Copilot planning: the prompt chain we actually run
FAQ#
Can Claude Code do documentation?#
Yes. Claude Code can inspect repository context and draft or revise documentation, but the safe workflow separates evidence collection, writing, and claim review. Treat its output as a proposed patch, not an approved description of system behavior.
Can Claude Code produce documents?#
Yes, when the requested document can be created within the available working context and permissions. For repository documentation, give it an explicit audience, scope, evidence standard, output location, and list of claims it must not infer.
Is Claude Code good at writing documentation?#
It is good at turning structured evidence into clear prose. It is not reliable enough to decide by itself which implementation details are public guarantees. Its strongest use is accelerated drafting behind a human claim-validation gate.
What documents can Claude Code read?#
It can work with relevant content made available in its environment and permitted context. Do not assume access merely because a document exists somewhere. Confirm that the source is available, readable, current, and authoritative before allowing the agent to use it as evidence.