Private beta formingJoin the list

Writing Better Prompts for Code

Stay lazy, code smarter

New tutorials and tips straight to your inbox

Writing Better Prompts for Code

February 1, 20252:30

Tips for writing prompts that get better results from Claude Code. Specificity, context, and examples matter.

The Prompt Quality Spectrum

There's a direct correlation between prompt quality and output quality. A vague prompt gives you generic code. A specific prompt gives you exactly what you need.

Bad vs. Good Prompts

Bad: "Add authentication"

Good: "Add email/password authentication using NextAuth.js with the Credentials provider. Store sessions in a JWT. Add a /login page with a form that validates email format client-side. On success, redirect to /dashboard."

The second prompt is 4x longer but saves 10x the back-and-forth.

The Three Components

Every effective prompt has three parts:

1. Context — What Exists

"The app uses Next.js 14 with App Router. There's already a User model
in prisma/schema.prisma with email and passwordHash fields."

2. Task — What You Want

"Add a POST /api/auth/login endpoint that validates credentials
and returns a JWT token."

3. Constraints — How You Want It

"Use bcrypt for password comparison. Return 401 for invalid
credentials with a generic error message. Token should expire in 7 days."

Prompt Patterns That Work

"Follow the pattern in X" — Point Claude at existing code:

"Add a DELETE endpoint for posts. Follow the same pattern as the existing DELETE endpoint in src/app/api/videos/[id]/route.ts."

"Don't change X" — Set explicit boundaries:

"Refactor the auth middleware to use JWT instead of sessions. Don't change any of the route handlers that consume the middleware."

"Here's an example of what I want" — Show, don't tell:

"Generate a config file like this:

name: deploy
on: push
jobs:
  build:
    runs-on: ubuntu-latest

But for a Node.js app with pnpm, running tests before deploy."

When to Be Vague (On Purpose)

Sometimes you want Claude to make decisions:

  • "What's the best way to handle caching here?" — Get Claude's recommendation before committing to an approach
  • "Review this function for bugs" — Let Claude find issues you haven't thought of
  • "Refactor this to be more readable" — Trust Claude's judgment on code style

Common Mistakes

  1. Too many tasks in one prompt — Break complex features into phases
  2. Assuming Claude remembers — Each prompt should be self-contained with enough context
  3. Not specifying file paths — "Add a component" is worse than "Add a component at src/components/user-card.tsx"
  4. Forgetting to mention constraints — If you care about the approach, say so upfront

Stay lazy.

Get bite-sized AI coding tips delivered to your inbox every week. No spam, unsubscribe anytime.