Magic Tools
AI PromptsBy CooconApril 22, 2026336 views4 min read

Best Free AI Prompt Templates for Developers (2025)

Most developers get bad results from AI not because the model is dumb, but because the prompt is vague. "Fix this code" or "write tests for this" gives you generic garbage. Specific prompts give you specific, useful output. Here are five templates you can copy right now.


1. Code Review

Use this when you want a real critique, not just "looks good."

You are a senior software engineer doing a code review. Review the following [language] code for:
- Logic bugs
- Edge cases that aren't handled
- Performance issues
- Readability problems

Be direct. If something is wrong, say it clearly. Suggest fixes with code examples.

Code:
[paste your code here]

Real example: Paste a 40-line Python function that processes user input. Instead of "this looks fine," you'll get specific notes like "this doesn't handle empty strings" and "this loop runs O(n²) — here's how to fix it."


2. Write Code Comments

Use this when your code is clear to you but no one else on the team.

Add clear, concise comments to the following [language] code. Follow these rules:
- Comment the "why," not the "what"
- Use inline comments for tricky logic
- Add a JSDoc/docstring block at the top of each function
- Don't state the obvious

Code:
[paste your code here]

3. Write Unit Tests

Use this when you know you need tests but hate writing boilerplate.

Write unit tests for the following [language] function using [Jest / pytest / Go testing].

Include tests for:
- Happy path (normal valid input)
- Edge cases (empty input, null, boundary values)
- Error cases (invalid types, values out of range)

Use descriptive test names. Mock external dependencies if needed.

Function:
[paste your function here]

Real example: Paste a Node.js email validator. You get tests for a valid email, missing @, empty string, null value, and a string with spaces. Copy, paste, done.


4. Explain Code

Use this when you inherit someone else's code and have no idea what it does.

Explain the following [language] code to me like I'm a developer who knows [language] but hasn't worked with [specific library/pattern].

- Start with a one-sentence summary
- Walk through the logic step by step
- Flag anything that's non-obvious or could cause bugs
- Don't define basic syntax

Code:
[paste your code here]

5. Refactor Code

Use this when the code works but you know it's a mess.

Refactor the following [language] code. Goals:
- Improve readability without changing behavior
- Remove duplication
- Break large functions into smaller, well-named ones

Do not add new features. Keep the same inputs and outputs.

Show the refactored code, then list what you changed and why.

Code:
[paste your code here]

Real example: Paste a 100-line controller with three nested if-else blocks. You get it split into four focused functions, nesting flattened with early returns, and a bullet list explaining each change.


3 Rules for Writing Better Developer Prompts

1. Specify the language and framework. "Fix this code" is weak. "Fix this TypeScript function using React hooks" is actionable.

2. Tell it what NOT to do. "Don't change the function signature." "Don't use external libraries." Constraints cut down on surprises.

3. Ask for the reasoning, not just the output. Add "explain what you changed and why" at the end of any refactor or fix prompt. You'll learn something, and you can catch it if the model went in the wrong direction.


FAQ

Do these templates work with any AI model?

Yes. These prompts work with ChatGPT, Claude, Gemini, Copilot, and any other LLM. The structure matters more than which model you pick.

How long should my prompt be?

Long enough to be specific, short enough to stay focused. For most code tasks, 100–400 words is the sweet spot. Too short is vague. Too long buries the important parts.

Should I paste my entire codebase?

No. Paste only the relevant function, class, or file. Dumping 2,000 lines usually gets you a surface-level response because the model has to spread attention across too much.

What if the AI gives me wrong or hallucinated output?

Always read the output before you run it. Treat AI like a junior developer who works fast but sometimes makes things up. If something looks off, paste the wrong output back and say "this is incorrect — the function should do X instead."

Can I save and reuse these templates?

Absolutely. Keep them in a plain text file, a Notion page, or a snippet manager. Some developers keep a /prompts folder in their projects with .md files for different tasks. Whatever gets you to copy-paste in under 10 seconds is the right setup.


Prompt length matters more than most people think. If you want to check how long your prompts are, MagicTools Word Counter gives you a quick word and character count — paste your prompt in and see where you land.

Related Articles

Blocking rm -rf in Claude Code: A Deny Rule Stopped 14 Deletes in Two Weeks, 7 Other Spellings Still Get Through, and a Hook That Closes the Gap

To keep Claude Code from deleting things by accident, I added a deny rule, Bash(rm -rf *), to my global settings. Across my sessions from October 7 to 21 it blocked 14 deletes. After each denial the model picked a new directory name 8 times and dropped the delete 6 times. It never tried another spelling. Then I replayed 22 delete commands verbatim against Claude Code 2.1.285 through a stub. rm -fr, rm -r -f, rm -Rf and rm -r deleted the directory in manual, auto and bypass mode alike. /bin/rm, find -delete and bash -c deleted it in manual and bypass mode. In auto mode, rm -fr inside the working directory skips the classifier because it 'would be allowed in acceptEdits mode'. A second, built-in dangerous-rm check fires on targets like $D/*, even in bypass mode, but loses track of a variable assignment when a heredoc comes earlier in the same command. The post ends with a PreToolUse hook that blocks every recursive spelling in all three modes and tells the model what to do instead.

claude-codehooks+5
pitfallsOct 21, 20268 min
208

The Self-Reinforcing Flywheel Is Harder Than It Looks: 40 Days of an LLM Auto-Tuning Loop

We ran an 'LLM proposes, code decides' auto-tuning loop on a daily WeChat newsletter for 40 days: 18 versions, 8 rollbacks. Three of those rollbacks overturned decisions a human had made, and one version whose knobs were identical to its parent still got rolled back. Using our real numbers, telling apart a 20% difference needs about 25,000 reads per version. At 60 reads a day, that is more than 400 days. This postmortem covers five reasons the flywheel never turned, and what actually moved the numbers.

wechatpostmortem+4
pitfallsOct 21, 20268 min
133

Dev Breakfast · 2026-10-21

Today's headline: A single "bonsoir, Elliot" makes the model leak its .env: a backdoor for under $50. Plus 4 more: DeepSeek open-sources its inference engine: V4.1 Flash only, and KV cache still missing; TorchTPU goes open source: PyTorch models can run directly on TPU; and more.

daily-intelOct 21, 20268 min
446

Dev Breakfast · 2026-10-20

Today's headline: Should You Merge AI Code You Don't Understand: Settle the Abstraction Layer Yourself First. Plus 4 more: tmux as a Remote Control: Multi-Session Claude Code and send-keys; headroom Goes Open Source: 95% Token Savings on JSON, Only 20% for Coding Agents; and more.

daily-intelOct 20, 20265 min
415

Published by Magic Tools