Skip to content
·7 min read

Prompting AI for Documentation That Future You Will Thank You For

How to get AI to write useful READMEs, meaningful code comments, and API documentation that helps instead of clutters

Share

AI can draft a README, suggest a comment or turn an API definition into an example. The useful part comes when you compare the draft with the project and check that another person can follow it. Start with one small piece of documentation you can verify yourself.

Use only project material you are allowed to share with the tool. Leave out credentials, private customer records and raw production logs. Use invented examples when the draft needs names, addresses or sample account details.

README Generation That Actually Helps

The default README prompt most people try is something like "write a README for this project." The result is a generic template with placeholder text that you will need to rewrite anyway. That defeats the entire purpose.

Instead, give the AI your project context and tell it what a new person needs to know. Here is a prompt pattern that produces READMEs people actually read.

Use the approved setup files I provide. Write a README that answers these questions:

1. What does this project do, in one paragraph a non-technical person would understand?
2. What do I need installed before I can run it? (exact versions if they matter)
3. What are the step-by-step commands to get it running locally?
4. Which environment variable names are required, and where should a teammate get access? Leave all secret values out.
5. What does the folder structure look like, and what lives where?

Focus on the steps someone needs to get started. Flag anything the source does not establish.

Before running the setup steps in a test copy, confirm it can write only to a test database and test file storage and verify that outgoing email, payments or other actions are disabled or use test services. If you cannot verify those connections, inspect the setup files and configuration without running the steps. Note what still needs a test. Ask the tool for a table of environment variable names, required or optional status, and where an authorized teammate should get access. Confirm each entry against the project.

Key Takeaway

The best documentation prompt is not "write docs for this." It is a list of specific questions that a new person would ask. Ask the questions your reader needs answered. Check the draft against the project, including anything the tool marked as uncertain.

When to Comment Code and What to Say

Here is where most people get documentation wrong with AI. They ask the AI to "add comments to this code" and end up with something like this:

// Set the user's name
const userName = user.name;

// Check if the user is an admin
if (user.role === "admin") {
  // Show the admin panel
  showAdminPanel();
}

Every single comment restates what the code already says. This is documentation bloat. It makes the file harder to read, not easier. The code was already clear. The comments added noise, not signal.

The rule is simple: comments should explain why, not what. The code tells you what is happening. Comments should tell you why it is happening that way.

Here is a prompt that produces useful comments:

Review this code and add comments only where the WHY is not obvious.
Explain business logic decisions, workarounds, and non-obvious choices.
Do NOT comment on what the code does if the code is self-explanatory.
If a section needs no comment, leave it alone.

For example, suppose your team checked the code and confirmed why the admin branch comes first:

const userName = user.name;

// Admin check happens before data fetch because admin users
// see a different dataset and we avoid loading regular data
// only to discard it
if (user.role === "admin") {
  showAdminPanel();
}

One comment that explains a real decision is worth more than twenty that restate the obvious. When you prompt AI for comments, always emphasize the why-not-what rule, or you will spend more time deleting useless comments than you saved generating them.

Good code comments explain decisions and tradeoffs, not what the code already tells you.

API Documentation With Real Examples

An API endpoint is an address another program uses to ask your app for something. Give the tool one approved endpoint definition or a small excerpt of its implementation. Ask it to flag anything it cannot establish.

Use the approved endpoint definition I provide to draft these sections:
- Address and request method
- Required fields and which ones are optional
- Authentication requirements, with no real credentials
- One fictional request and its expected success response
- An error the endpoint actually returns and how the caller can respond

Use an invented example such as alex@example.com. Mark unknowns.

Compare the request and response with the API definition. If you test them, use a disposable app instance with sample records and verify that it has no live connections or outgoing actions. Check a successful request and a relevant failure. If you cannot run the example safely, label what you checked against the definition and leave the runtime result unverified.

Once the example is checked, compare documentation tools for sharing it. A README can explain setup to developers, while a customer help site can publish instructions for people who never open your repository.

The "Explain This to a New Developer" Prompt

This is the single most useful documentation prompt you will ever learn. When you have a file, function, or system that is hard to understand, use this:

Explain this code as if you are onboarding a new developer who has
never seen this project. Cover what it does, why it exists, what
calls it, and what would break if someone changed it carelessly.

The prompt asks for purpose, callers and consequences. Use it on one file or function you are allowed to share. Check the explanation against its callers and tests. If the draft guesses why someone made a choice, ask the teammate who made it or mark the reason as unknown.

The explain-to-a-new-developer prompt produces documentation that covers context, purpose, and dependencies in one pass.

Avoiding Documentation Bloat

Keep the detail a reader needs for the next task. In a README, lead with setup and how to confirm the app started. In a code comment, explain a choice that would be hard to infer. In API documentation, include the failures people need to recognize and what to do about them.

Set a clear boundary in the prompt. For example, ask for setup and one check, then compare each instruction with the actual project. When setup, permissions or the API changes, revisit the affected instructions and repeat the check.

What This Means For You

Start with the instruction someone is most likely to need next. Give it one task, one checked example and a clear place to live. If it describes a decision, include enough context for someone else to verify it.

Try the README prompt on a small part of your project. Have someone follow the setup in a test copy and note where they stop. That is the next thing to improve.

PJ
Pranay Joshi

20+ years building products at scale. VP of Product & Engineering, startup founder, and AI coach. Helping dreamers turn ideas into reality with vibe coding.