Coding Templates
Copy-paste prompt templates for the most common coding tasks. Each template is structured to give Claude the context it needs to produce useful, production-quality output rather than generic examples.
Debug Template
Use when code is throwing an error or producing unexpected output:
Language/framework: [e.g. "Python 3.11 / FastAPI"]
Error message (exact): [paste the full error including stack trace]
What I expected: [what the code should do]
What is happening instead: [what the code actually does]
What I've already tried: [steps you've taken to diagnose]
Relevant code:
```[language]
[paste the relevant code — include the function and any called helpers]
```
The "what I've already tried" field prevents Claude from suggesting the same things you've already ruled out.
Explain Template
Use when you need to understand what a piece of code does:
Explain what the following [language] code does.
My level: [e.g. "I understand basic Python but not async patterns"]
Focus on: [e.g. "the data flow through the function" / "why the async/await is needed here" / "what could go wrong at runtime"]
```[language]
[paste the code]
```
The "focus on" field prevents Claude from explaining things you already understand and directs it to the part you actually want to learn.
Refactor Template
Use when code works but needs improvement:
Refactor the following [language] code to [specific goal, e.g. "improve readability" / "reduce duplication" / "extract the database logic into a separate function"].
Constraints:
- Preserve the existing public API (function signatures must not change)
- [Any other must-not-change constraints]
Do not change: [anything that's working well and should stay the same]
```[language]
[paste the code]
```
Always specify what must not change — refactor prompts without constraints often produce code that works differently even if it looks cleaner.
Test Template
Use when you need unit or integration tests for existing code:
Write [unit/integration] tests for the following [language] function using [test framework, e.g. "pytest" / "Jest" / "go test"].
Coverage requirements:
- Happy path: [expected normal behaviour]
- Edge cases: [e.g. "empty input, null values, maximum length"]
- Error cases: [e.g. "what should throw or return an error"]
Mocking: [e.g. "mock the database calls using [library]" / "use real database — this is an integration test"]
```[language]
[paste the function to test]
```
Review Template
Use for a targeted code review:
Review the following [language] code for [focus area: "security vulnerabilities" / "performance issues" / "readability and maintainability"].
Context: [e.g. "this runs on a public-facing API server" / "this is called thousands of times per second"]
For each issue found: describe the problem, rate severity (high/medium/low), and suggest a fix.
```[language]
[paste the code]
```
Run separate reviews for each focus area — one combined review produces a mixed list that's harder to prioritise.
Write New Code Template
Use when starting a new function or module:
Write a [language] [function/class/module] that [does what].
Signature: [function name + parameters + return type]
Edge cases to handle: [list specific edge cases]
Dependencies available: [libraries/modules it can import]
Style: [e.g. "include type hints" / "use async/await" / "follow Google Python style guide"]
Example input/output: [optional — but greatly improves accuracy for complex functions]
Checklist: Do You Understand This?
- Debug: always include the exact error message, what you expected, what happened, and what you've tried
- Explain: specify your level and what to focus on — prevents explanations of things you already know
- Refactor: always specify what must not change (public API, behaviour) alongside what to improve
- Test: list happy path + edge cases + error cases explicitly — and specify mocking strategy
- Review: run separate reviews by focus area (security / performance / readability) for actionable findings