Skip to main content

Command Palette

Search for a command to run...

The 10 AI Prompts That Actually Improved My Code Quality

Published
3 min read

I've been using Claude and ChatGPT daily for ~2 years. Most prompts give mid results. These 10 consistently produce code I'd actually ship.


1. Senior Code Review

Review this code as a senior engineer. Prioritize:
1. Correctness > security > performance > style
2. Blockers (must-fix) vs nits (optional)
3. One ship-worthy observation

Code:
{paste your code}

This prompt works because it CONSTRAINS the LLM. Without priorities, you get a laundry list. With them, you get actionable feedback.


2. Root Cause from Stack Trace

I'm getting this stack trace:
{paste trace}

Here's the relevant code:
{paste code}

Top 3 hypotheses ranked by likelihood. For each: how to test it.

The "how to test" part is key. It forces the LLM to think about falsifiability, not just pattern-match.


3. Refactor with a Constraint

Refactor this code with this constraint: {e.g., "no mutation, pure functions only"}. Explain each change in 1 sentence.

{paste code}

Constraints produce better refactors than "make this better." Try "extract side effects to the edges" or "make each helper unit-testable without mocks."


4. Test Case Generator

Generate pytest cases for this function. Include:
- Happy path
- Edge cases (empty, single, max)
- Error cases (bad type, null, format)
- One property-based test using hypothesis

{paste function}

The hypothesis test is the sleeper. Property-based testing finds bugs your hand-written tests miss.


5. Security-Only Review

Review this code ONLY for security issues. Reference OWASP top 10. Ignore style, perf, naming.

{paste code}

For each issue: attack scenario + fix.

Scoping to "only security" gives dramatically better results than "review everything."


6. Regex from Examples

I need a regex that matches these:
{list matches}

And does NOT match these:
{list non-matches}

Give me the regex, explain each part, Python snippet to use it.

Generating regex from examples > trying to write one from spec. The LLM handles edge cases you'd forget.


7. Explain This Code (for learning)

Explain this code as if I'm a mid-level engineer new to this codebase.
Walk through it in the order the reader encounters it.

{paste code}

"In the order the reader encounters it" — this prevents the LLM from jumping around and gives you a mental model you can actually follow.


8. Error Message Improver

Here are the error messages my app throws. Rewrite each to be:
- Clear about what broke
- Specific about why
- Actionable about what to try

{paste messages}

Most error messages are written for the developer who wrote them, not the user who sees them. This prompt fixes that.


9. ADR Writer

Write an Architecture Decision Record for: {decision}
Context: {context}
Options considered: {A}, {B}, {C}

Include: context, decision, consequences (+ and -), status.

ADRs are the most underused engineering artifact. This prompt makes writing them effortless.


10. Rubber Duck (But Smart)

I'm stuck on: {problem + what I've tried}

Don't solve it immediately. Ask me clarifying questions that might reveal assumptions I'm making. After I answer, propose 2-3 approaches.

The "don't solve immediately" instruction changes everything. Forces the LLM to think before coding.


The full pack

These 10 are from my collection of 50 battle-tested prompts covering code generation, debugging, testing, review, architecture, documentation, SQL, automations, and career.

Full pack: payhip.com/b/MnF86 ($9)

Also: