Write READMEs and Code Docs with AI
- The official “Handle documentation” recipe has four steps: find code without proper JSDoc comments, generate the documentation, improve it with more context and examples, then check that it follows your project’s standards.
- Its tips: name the documentation style you want (JSDoc, docstrings and so on), ask for examples, and request documentation for public APIs, interfaces and complex logic.
- The best-practices page says to ask Claude for evidence, meaning the command it ran and its output, because “All tests pass” on its own “tells you very little”. We apply the same idea to docs: ask for the command and output behind each claim.
- The same page shows a
denypermission rule such asRead(./.env)and says it holds in every permission mode. We use it as one way to keep secrets away from Claude while it writes docs. - We read two official pages on 2026-11-05. We did not run Claude Code for this tutorial. The prompts and the checking routine are our own advice, not official rules.
What you’ll be able to do after this tutorial
Section titled “What you’ll be able to do after this tutorial”- Ask Claude to draft a README or code comments from the actual project.
- Check each statement in the docs (install steps, commands, options) against the code instead of trusting it.
- Keep passwords, keys and personal data out of the docs and out of the conversation.
- Review the result as a diff and commit it.
Concepts to know first
Section titled “Concepts to know first”Docs written by AI can sound right and still be wrong. A README that says npm run build when your project uses a different command looks fine until someone follows it. So the real work in this tutorial is checking, not writing. 1. Getting started with Claude Code shows how to start. To have a change reviewed before you commit, see Coding 15, and for the branch and commit habits, Coding 17. The “give Claude a check” idea is also used in Coding 18.
Step-by-step guide
Section titled “Step-by-step guide”-
Prepare a safe place
In your own terminal, create a branch so the docs change is easy to review or discard:
Terminal window git switch -c docs-readmegit statusMake sure no file with real secrets is committed or sitting where Claude will read it. The best-practices page shows how to block reads of such files with deny rules in
.claude/settings.json:{"permissions": {"deny": ["Read(./.env)", "Read(./.env.local)", "Read(./secrets/**)"]}}The page says deny rules hold in every permission mode, and that with this saved, asking Claude what is in
.envfails. Change the paths to match your own project. We did not test this file here. -
Find what is undocumented
The official recipe starts by asking, not editing. Try a read-only prompt:
Copy and paste this promptLook at this project. Do not edit anything. List the files and functions that have no comments or documentation, and say which ones are public (used by other code or by users). Also tell me what the existing README is missing, such as how to install, run and test.
-
Draft the README
Say what style and who the readers are, since the tips ask you to specify the style you want:
Copy and paste this promptWrite a draft README.md for this project for a new developer. Include what the project does, requirements, how to install, how to run, how to run the tests, and the main folders. Base every command on the files in this repo, and list each command you took from a file next to the file name. If you are not sure about something, write TODO instead of guessing. Use fake example values for any settings.
Asking for the source of each command and a
TODOfor gaps makes the next step easier. -
Add code docs for the important parts
The recipe’s example is
add JSDoc comments to the undocumented functions in auth.js. Use your own language’s style:Copy and paste this promptAdd doc comments in the style this project already uses (JSDoc, docstrings or similar) to the public functions in auth.js. Describe what each function does, its parameters, what it returns, and one short example. Do not change any code, only comments. Do not describe behavior you cannot see in the code.
The tips also suggest requesting docs for public APIs, interfaces and complex logic, and asking for examples.
-
Check every claim
This step is ours, applying the best-practices advice to ask for evidence. Go through the draft and test what you can in your own terminal:
What the docs say How to check Install and run commands Run them in a clean copy of the project, or mark them “not run” Test command Run it and compare the result Settings and environment variables Search the code for each name and confirm it is really used Folder descriptions Compare with lsFunction descriptions Read the function and one example call You can also ask Claude to do a first pass, then verify its report yourself:
Copy and paste this promptCheck the README against the code. For each command and setting it mentions, run or search for it and show me the command you ran and its output. List anything that does not match, and do not fix it yet.
Do not skip your own run. Claude’s report is a lead, not proof.
-
Improve and match your standards
The recipe’s last two steps are to improve the docs with more context and examples and to check them against project standards. If you have a style guide, point to it:
Copy and paste this promptImprove the README using the mismatches we found. Add one worked example of the main use case. Then check it against our docs style, which is: short sentences, commands in code blocks, no marketing language. Tell me what you changed.
-
Read the diff, then commit
Terminal window git diff # every changed linegit status # any file you did not expectLook for real keys, internal addresses, names or email addresses, and for code that changed when you asked for comments only. If it looks right:
Terminal window git add README.md auth.jsgit commit -m "Add README and doc comments"Use your own file names. If you also want a second opinion,
/code-reviewreviews the diff in a fresh subagent, according to the best-practices page.
Quick reference
Section titled “Quick reference”| Task | Where or how |
|---|---|
| Find undocumented code | Read-only prompt, “do not edit anything” |
| Pick a style | Name it in the prompt: JSDoc, docstrings and so on |
| Ask for proof | “show me the command you ran and its output” |
| Block secret files | deny rules in .claude/settings.json |
| Review the diff | git diff, or /code-review |
| Docs only, no code change | Say “only comments, do not change code” |
Common problems
Section titled “Common problems”The README has a command that does not exist
Section titled “The README has a command that does not exist”- Cause: Claude guessed from common conventions instead of reading your files.
- Fix: Ask it to cite the file for each command, replace guesses with
TODO, and run the commands yourself.
Comments describe what the code does not do
Section titled “Comments describe what the code does not do”- Cause: The comment was written from the function name, not the body.
- Fix: Tell Claude to describe only what it can see in the code. Read the function next to the comment.
The code changed when I asked for comments only
Section titled “The code changed when I asked for comments only”- Cause: The prompt did not forbid code edits.
- Fix: Check
git diff, restore the file withgit restore <file>, and ask again with “only comments”.
A real key or address appears in the docs
Section titled “A real key or address appears in the docs”- Cause: It was copied from a file Claude read.
- Fix: Remove it before committing. If it was already committed or pushed, treat it as exposed and replace it with a new one, as the key’s owner service describes.
The docs go out of date
Section titled “The docs go out of date”- Cause: The code changed after the docs were written.
- Fix: Re-run the check in step 5 whenever commands or settings change. Our suggestion: add it to your pull request checklist.
Practical tips
Section titled “Practical tips”- Practice in a throwaway project first.
- Ask for
TODOinstead of guesses. - Put fake example values in the docs, never real ones.
- Keep docs changes in their own commit so they are easy to review.
- Re-check commands against the official pages, since Claude Code changes often.
Next tutorials
Section titled “Next tutorials”Sources
Last verified: Nov 16, 2026
- Common workflows (Handle documentation) code.claude.com
- Best practices for Claude Code (verification, permission rules) code.claude.com
Prices, limits, and menu names change often. Before making an important decision, check the official pages above for the latest details.
Finished this tutorial?
Progress is saved only in this browser and never sent anywhere.