Code Comment Generator Prompt Template
Generate clear, useful inline comments and JSDoc/docstring documentation for any function or class.
The Prompt
Make it specific to you
PromptITIN asks a few questions and builds a version tailored to your use case.
How to use this template
Copy the template
Click the copy button to grab the full prompt text.
Fill in the placeholders
Replace anything in [BRACKETS] with your specific details.
Paste into any AI tool
Works with ChatGPT, Claude, Gemini, Cursor, and more.
Or enhance with AI
Sign in to PromptITIN and let AI tailor the prompt to your exact situation in seconds.
Why this prompt works
The WHY not WHAT rule is the most important distinction in commenting practice — AI defaults to explaining what code does because that's easy to derive from the syntax. Forcing WHY commentary requires the AI to reason about intent, which produces far more valuable documentation.
Tips for best results
- Add 'flag any code that has no tests with [UNTESTED:]' to the RULES — it turns documentation into a test coverage audit simultaneously
- For legacy codebases, run this on the most confusing file first — the [REVIEW:] flags often surface genuine bugs or design issues that have been living there unnoticed
- After generating, remove any comment that just restates the code in English ('// loop over array' above a forEach call) — these add noise, not signal
- Ask the AI to generate the documentation separately from the code so you can diff what was added — easier to review than a fully mixed file