Claude Code Documentation Prompt Template
You get documentation a newcomer can follow on the first try: what it is, how to install it, how to use it, with working examples. This version is set up for Claude Code: name the files, commands and tests involved. Claude Code can read files and run commands in your project, asking permission as it goes. Below you'll find the prompt, how to run it in Claude Code, a worked example and answers to common questions.
Write documentation for the code or tool below. ## What it is Name: [project or module name] What it does: [one or two sentences] Who reads this: [e.g. developers new to the project, external API users] ## Source material [paste the code, CLI help output, config options, or function signatures] ## Document type [README, API reference, docstrings, or a how-to guide] ## Instructions - Start with what it does and why someone would use it, in two sentences. - Show a working example before explaining every option. - Every command and code sample must match the source material exactly. Do not invent flags, options or defaults. - Use short sections and plain language. - If something important is unclear from the source, list it as a question at the end instead of guessing. ## Output format Markdown with: overview, install, quick start, options or API, examples, and open questions. Context - Files involved: [list the files, or reference them in the chat] - How I build and test: [e.g. npm test]
How to use this prompt
- 1
Open Claude Code
Run claude in your project directory and paste the prompt.
- 2
Give it context
Name the files, commands and tests involved. Claude Code can read files and run commands in your project, asking permission as it goes.
- 3
Review and iterate
Approve or decline each edit and command, then reply in the same session to adjust.
- 4
Save what you repeat
Put project conventions (how to run tests, style rules, folders to avoid) in a CLAUDE.md file so every session starts with them.
Working in Claude Code
- •Claude Code works in your terminal, so tell it the exact commands for building and testing.
- •Ask it to explain its plan before large edits; you can stop it if the plan is wrong.
- •Start a fresh session for an unrelated task so earlier context doesn't steer the new one.
Worked example
What you give it
Name: csvtidy What it does: a command line tool that trims whitespace from every cell in a CSV and removes empty rows. Readers: developers on my team. CLI help: csvtidy <input> [-o output] [--keep-empty] -o, --output write to a file instead of stdout --keep-empty do not remove empty rows Install: npm install -g csvtidy Type: README
What a good answer looks like (shortened)
# csvtidy csvtidy cleans CSV files by trimming whitespace in every cell and removing empty rows. Use it before importing exported spreadsheets. ## Install npm install -g csvtidy ## Quick start csvtidy contacts.csv -o contacts-clean.csv ## Options - -o, --output: write to a file instead of printing to stdout - --keep-empty: keep empty rows instead of removing them ## Examples Print the cleaned file to the terminal: csvtidy contacts.csv ## Open questions - What happens if the output file already exists? - Does it handle quoted cells that contain commas?
Tips for better results
- •Paste the actual help output or signatures into Source material. Documentation that drifts from the code is worse than none.
- •Read the open questions at the end. They are usually the gaps a new user would hit, so answer them in the doc.
- •Claude Code works in your terminal, so tell it the exact commands for building and testing.
- •Avoid this: Asking for documentation without naming the reader, which produces text that is too basic for maintainers or too dense for new users.
Get the free prompt pack
Our best coding prompts in one Markdown file, delivered by email. The templates here stay free either way — the pack just saves you the copying.
Variations
Docstrings
Change Document type to docstrings and add: Use [Google, NumPy or JSDoc] style, with params, return value and raised errors for each function.
API reference
Replace Source material with your route handlers and add: For each endpoint, show method, path, parameters, an example request and an example response.
Changelog entry
Replace Document type with: A changelog entry for version [x.y.z] from this diff [paste], grouped as Added, Changed, Fixed.
Save it as a Retext snippet
Retext is a free text expander for Mac. Save this prompt once, then type ;writedocs in any app (ChatGPT, Claude, your editor, a browser tab) and the full prompt is pasted in.
- Click Add to Retext. The prompt installs as a snippet with the trigger ;writedocs.
- Change the trigger in Retext if you prefer a different one.
- Type the trigger wherever you want the prompt, then fill in the brackets.
Frequently asked questions
How do I keep AI-written docs accurate?
Give it the real source, help text or signatures and tell it not to invent options. Then run every example yourself before publishing.
Where should I keep instructions I repeat every session?
In CLAUDE.md at the project root. Keep the prompt on this page for the specific task.
Should documentation explain every option?
Lead with a working quick start, then list options. Most readers want to run one example first and come back to the full reference only when they need it.
How do I reuse this prompt without copying it every time?
Click Add to Retext to save it as a snippet. Then type ;writedocs in any Mac app, including your AI tool, and the full prompt is pasted in.
Related Templates
Get the free prompt pack
Our best coding prompts in one Markdown file, delivered by email. The templates here stay free either way — the pack just saves you the copying.