Prompt templates — reuse AI tasks you do daily
Stop briefing the AI from scratch — code review, debugging, refactor, test, doc templates.
After a week with an AI agent you repeat the same kinds of requests daily — "review this code," "trace this bug," "write tests." Instead of re-stating context each time, reusable prompt templates save time, increase consistency, and improve output quality.
I think what a template actually does is externalize what you already know about what a good answer looks like. Not because it removes creativity, but rather because when you've seen a hundred code reviews, you know what makes a review useful — and encoding that into a template means every invocation benefits from that accumulated judgment. The template is not instructions to the model; it's a record of your own expertise.
This guide covers five daily templates (code review, debugging, refactor, test, documentation) and how to store them.
TL;DR
- Template = context + task + output format + constraints
- Storage:
~/.prompts/or chezmoi-managed - Macro tools: Raycast Snippets, Cursor
@docs, Claude Code slash commands - Four elements of a good template: role / inputs / output format / prohibitions
1. Four Elements of a Good Prompt
Placeholders shown as [...] (to avoid MDX/JSX conflicts).
You are a [role].
Context: [context]
Task: [what to do]
Output format: [how to respond]
Constraints:
- [prohibition 1]
- [prohibition 2]
Four clear sections help the model separate what to address from what to skip.
2. Template 1 — Code Review
You are a senior code reviewer for [language] projects.
Context:
- Code under review: [paste code or @file]
- Project conventions: [link or paste relevant style guide / .cursorrules]
- Reviewer focus: [correctness | security | performance | readability]
Task: Review the code. Identify:
- Bugs or logic errors (severity: critical / major / minor)
- Security issues (input validation, secrets, auth)
- Performance concerns (only if obvious O(n^2) or memory)
- Style violations against project conventions
- Suggestions for clarity
Output format: SUMMARY: [one-paragraph overall verdict] [CRITICAL] (line N): [issue] -> [fix] [MAJOR] ... [MINOR] ... [STYLE] ... [SUGGESTION] ...
Constraints:
- Do not rewrite the entire file. Point and suggest.
- Do not nitpick style if .cursorrules don't enforce it.
- If no issues found at a level, omit that section.
Usage
Cursor side chat — @code-review.md + @src/auth/login.ts + focus: security.
Claude Code: store the template at .claude/commands/review.md, invoke with /review src/auth/login.ts.
3. Template 2 — Bug Debugging
You are a debugging assistant.
Context:
- Error message: [paste full stacktrace]
- Code where it occurs: [paste minimal repro or @file]
- What I tried: [hypotheses ruled out]
- Expected behavior: [what should happen]
Task:
- Identify the most likely root cause (not just symptoms)
- Suggest a fix
- Suggest a test to prevent regression
Output format: ROOT CAUSE: [one sentence] EXPLANATION: [2-3 paragraphs of why] FIX: [patched code] REGRESSION TEST: [test code]
Constraints:
- Do not guess. If you need more info (logs, full file), ask.
- If 2+ hypotheses are equally likely, present both with discriminating signals.
- Do not just say "try X" — explain the model.
The "What I tried" section is critical — prevents the model from re-suggesting things you already eliminated.
4. Template 3 — Refactor
You are a refactoring assistant for [language].
Context:
- Current code: [paste or @file]
- Pain point: [readability | duplication | testability | performance]
- Constraints:
- Must preserve public API
- Must not break existing tests
Task: Refactor while preserving behavior. Show:
- The refactored code
- Diff vs original
- Tradeoffs of this approach vs at most 1 alternative
Output format: REFACTOR: [new code] DIFF:
- Removed: [what]
- Added: [what]
- Renamed: [old -> new] TRADEOFF: [this approach]: [pros/cons] [alternative]: [pros/cons] RECOMMENDATION: [which and why]
Constraints:
- Do not change behavior. If you think behavior should change, flag it separately.
- Keep test compatibility — show how existing tests still pass.
- Don't introduce new dependencies without explicit ask.
5. Template 4 — Test Writing
You are a test writer for [language] (Vitest, Jest, Pytest, etc.).
Context:
- Code to test: [paste or @file]
- Existing test style: [paste sample test or @file]
- Coverage focus: [happy path | edge cases | failure modes | all]
Task: Write tests that:
- Cover the happy path
- Cover at least 3 edge cases (boundary values, empty input, error cases)
- Are deterministic (no flaky time/network without mock)
- Follow the existing test style
Output format: a single test file in [language].
Constraints:
- Use the same assertion library as existing tests
- Mock external dependencies (don't hit real network/DB)
- Keep each test focused (one assertion topic per test)
- Name tests descriptively: "returns X when Y"
- Do NOT write tests that just mirror implementation. Test behavior.
6. Template 5 — Documentation
You are a technical writer.
Context:
- Code: [paste or @file]
- Audience: [beginner | intermediate | expert]
- Doc type: [README section | JSDoc | tutorial | reference]
Task: Write documentation that:
- States the purpose in 1 sentence
- Shows minimal usage example
- Lists parameters/returns with types
- Notes edge cases or gotchas (if any)
Output format: markdown or specific JSDoc/TypeDoc format.
Constraints:
- No filler. Be direct.
- Code examples must be runnable / pasteable
- If the API is complex, link to deeper reference rather than dumping
- For library/framework specifics, prefer official terminology
7. Storage / Management
Option A — Claude Code slash commands
Save templates to ~/.claude/commands/review.md. CLI: /review src/foo.ts injects the system prompt automatically.
Option B — Cursor @docs
Cursor → Settings → Features → Docs → Add → URL/local path. In chat: @my-review-template.
Option C — Raycast Snippets
Via mac/productivity's Raycast Snippets:
- Add Snippet: paste the full template
- Keyword:
!review - In any text field,
!review→ expands
Option D — Simple directory + alias
Save each template as .md in ~/.prompts/. .zshrc:
alias prompt='ls ~/.prompts'
prompt → list → cat ~/.prompts/review.md | pbcopy → paste anywhere.
chezmoi Integration
Add ~/.prompts/ to your dotfiles chezmoi tree. Available on any new machine immediately.
8. Template Evolution
Your first template is 70% quality. Improve as you use:
- Results often get too long → add "Keep under N lines" or "Output only diff"
- AI keeps drifting → strengthen Constraints (concrete prohibitions)
- Context missing → add explicit input slots like "What I tried"
- Outputs inconsistent → show an example in Output format
- Too conservative → "Recommend the best option, not all options"
Add a one-line note at the end of each phase to keep the template evolving. Over a year, those patterns solidify into a personal asset.
9. Antipatterns
Too abstract
❌ "Be a good code reviewer." ✅ "You are a senior reviewer. Identify bugs / security / style. Output in format X."
Vague goal
❌ "Make this better." ✅ "Make this more readable. Don't change behavior. Show diff."
Missing output format
Each model produces a different shape; comparison/automation suffers.
Too long — "insurance" constraints
"And also X. And maybe Y. Don't forget Z." → model loses priority. Keep 3–5 essentials.
Always Korean
Korean prompts on an English codebase are token-inefficient. If the code context is English, English prompts produce better results.
Verification
- Review the same code with vs without the template — compare consistency / completeness
- Apply chezmoi on a new machine →
~/.prompts/immediately available - Raycast
!reviewtrigger → expands anywhere - Claude Code
/review file.ts→ same response shape - After a week of use, evolve one template per week (one-line note)
Troubleshooting
AI ignores the template
- Long templates make the model forget mid-instructions. Keep under 200 lines
- Re-state the most important constraint at the end (recency bias)
- Cursor
@docsmay compress context — extract essentials
Slash command not working
- Claude Code: file name/location at
~/.claude/commands/foo.md - Cursor: slash commands depend on the model
Output format breaks
Show an explicit format example. "Use this exact format:" or similar strong wording.
Answers too long
"Maximum N lines." or "Only the diff, no explanation."
Language mixed
State both prompt and output language. "Respond in Korean." or "Respond in English."
References
- Claude Code setup — slash command registration
- Cursor setup —
@docsand .cursorrules - Multi-agent workflow — handoffs are also templates
- Dotfiles management — share templates across machines
- Anthropic Prompt Engineering
Changelog
- 2026-05-12: First draft. Five templates + four storage options + evolution + five antipatterns + five troubleshooting cases.
Keep reading
- OpenAI Codex CLI setup — comparison with Claude Code and Cursor
OpenAI's official coding-agent CLI. Install, auth, autonomy modes, and how it compares to Claude Code — all in 30 minutes.
- GitHub Copilot setup — splitting work between Copilot, Claude Code, and Cursor
30-minute setup for Copilot in VS Code and JetBrains. Plus a decision table for which jobs go to Copilot vs Claude Code/Cursor.
- Local LLMs with Ollama — Open WebUI · Continue.dev integration
Run Llama / Qwen / DeepSeek locally on Mac and Windows. Cost, privacy, offline — an alternative to cloud LLMs.