Skip to main content

Prompting Strategy

The difference between people who get great results from Claude Code and those who don't comes down to prompt quality. The same task can produce wildly different results depending on how you ask. This chapter covers proven, advanced prompting techniques.

Core Principle: Clarity > Brevityโ€‹

Beginners assume shorter requests are better. In practice, specific and clear requests produce better results.

# Bad
> Build me a login

# Good
> Build a JWT-based login API.
- POST /auth/login endpoint
- Request: { email, password }
- Success response: { accessToken, refreshToken, user }
- Failures: 401 error (wrong password), 404 error (account not found)
- Verify passwords with bcrypt
- Reuse the existing User model in src/users/user.model.ts

Technique 1: Role Promptingโ€‹

Give Claude a specific role and it responds from that field's perspective:

> Review this code from the perspective of a senior Node.js developer,
especially for scalability and maintainability.

> As a security expert, find the vulnerabilities in this auth code.

> Pretend you're a user of this system and evaluate, from a UX
perspective, whether the API response structure makes sense.

Technique 2: Stating Constraintsโ€‹

The more constraints you state, the closer the result gets to what you want:

> Implement OAuth2 social login. However:
- Don't use passport.js (implement it directly)
- Comply with TypeScript strict mode
- Use Node.js fetch, no external HTTP libraries
- Extend the existing AuthService class
- Include test code

Technique 3: Example-Based Requests (Few-shot)โ€‹

Show an example of the pattern you want and Claude follows the same pattern:

> Build a Product service following this pattern:

// User service example (follow this pattern):
export class UserService {
constructor(private readonly db: Database) {}

async findById(id: number): Promise<User | null> {
return this.db.users.findUnique({ where: { id } });
}

async create(data: CreateUserDto): Promise<User> {
return this.db.users.create({ data });
}
}

// Build ProductService with the same structure.
// Methods: findById, findAll, create, update, delete

Technique 4: Chain of Thoughtโ€‹

For complex problems, guide Claude to think step by step:

> Fix this performance problem.
Before making changes:
1. Analyze where the bottleneck is
2. List 3 possible solutions
3. Compare the pros and cons of each
4. Pick the best approach and implement it
> Analyze this code's security vulnerabilities step by step:
1. Input validation issues
2. Authentication/authorization issues
3. Data exposure issues
4. How to fix each issue

Technique 5: Negative Instructionsโ€‹

Making "what not to do" explicit helps you avoid unwanted results:

> Implement a user deletion feature.
- Use soft delete (don't actually delete from the DB)
- Don't touch related data
- Don't modify the existing deleteUser function; add a new one
- Don't touch the error handling code

Technique 6: Specifying Output Formatโ€‹

State exactly what output format you want:

> Report the results of this codebase analysis in the following format:
## Strengths
[list]

## Areas needing improvement
[list by priority]

## Needs immediate fixing
[critical issues]

> Write the code review results as GitHub PR comments,
including file names and line numbers.

Technique 7: Including Verification Requestsโ€‹

Ask for verification along with implementation:

> Implement a discount calculation function.
After implementing:
1. Write a list of edge cases
2. Run tests for each edge case
3. Confirm all tests pass before finishing

> Implement this API.
When done, verify these yourself:
- No TypeScript compile errors
- No lint errors
- Related tests pass
Skipping verification means using only half the value

Claude Code's value isn't producing a perfect result in one shot โ€” it's the speed of reaching 80% fast and then pushing to 99% through verification. Requesting only the implementation and skipping verification means capturing only half of that speed advantage. Always follow implementation requests with a verification step like "check it", "run the tests", or "compare them".

Technique 8: Iterative Improvementโ€‹

Don't expect a perfect result in one shot โ€” improve in stages:

# Step 1: Function first
> Implement a working version quickly for now.
We'll improve code quality later.

# Step 2: Review
> Give me 3 improvements for the code you just implemented.

# Step 3: Improve
> Improve [the most important one] first.

# Step 4: Test
> Now add tests.

Context-Setting Patternsโ€‹

Providing Context at the Start of Workโ€‹

> We're going to implement the [feature name] feature.
Background:
- Currently: [current state]
- Goal: [end goal]
- Constraints: [constraints]

Start with [first task] first.

Reconfirming Direction Midwayโ€‹

> Summarize what we've implemented so far.
I want to confirm what the next step is.

Requesting a Review at the Endโ€‹

> Look back over all the code we worked on today.
Let me know if anything is inconsistent or could be improved.

Effective Prompt Patterns by Domainโ€‹

Bug Fixingโ€‹

> Bug: [describe the symptom]
Conditions: [when it occurs]
Error message: [error content]
Expected behavior: [correct behavior]
Actual behavior: [what actually happens]

Find the cause, then fix it.
Explain the reasoning behind the fix too.

Performance Optimizationโ€‹

> Improve this code's performance.
Current problem: [what performance issue]
Goal: [target performance number or direction of improvement]
Constraints: [things that must not change]

Explain each improvement and its expected impact as you go.

Code Reviewโ€‹

> Review this code like a senior developer.
From these perspectives:
1. Correctness (potential bugs)
2. Readability (ease of maintenance)
3. Performance (room for optimization)
4. Security (vulnerabilities)

Classify each issue as [severity: high/medium/low].

Documentationโ€‹

> Write technical documentation for this module.
Target audience: a junior developer who just joined this system
Include:
- The module's purpose
- Key classes/functions and their roles
- Common usage examples (with code)
- Caveats

Using Plan Modeโ€‹

For complex work, you can have Claude explore first, form a plan, get approval, and only then implement instead of editing code right away. This is Plan Mode.

What Is Plan Mode?โ€‹

Normal mode:  request โ†’ implement immediately
Plan Mode: request โ†’ explore codebase โ†’ form a plan โ†’ user approval โ†’ implement

In Plan Mode, Claude operates read-only. It reads files, searches, and maps the structure, but modifies nothing. Implementation starts only after the plan is approved.

When to Use Itโ€‹

  • Large changes spanning multiple files
  • Feature additions that require architecture decisions
  • Complex work with multiple possible approaches
  • When you need to understand the existing code structure before working

How to Use Itโ€‹

Just ask in natural language:

> I want to migrate the auth system to OAuth2. Make a plan first.

> Do this refactoring in plan mode.

> Before modifying any code, map out the current structure and propose an approach.

How It Flowsโ€‹

  1. Explore: read the relevant files and map the structure
  2. Plan: lay out the files to change, the approach, and considerations
  3. User approval: present the plan and incorporate feedback
  4. Implement: modify the code according to the approved plan

Practical Exampleโ€‹

> I want to add OAuth2 social login. Proceed in plan mode.

Claude:
[Exploring] Mapping the current auth structure...
- src/auth/auth.service.ts โ€” JWT-based authentication
- src/auth/auth.controller.ts โ€” login/signup endpoints
- src/users/user.model.ts โ€” User schema

[Plan]
1. Create src/auth/oauth.service.ts โ€” handle Google/GitHub OAuth
2. Modify src/auth/auth.controller.ts โ€” add /auth/google, /auth/github endpoints
3. Modify src/users/user.model.ts โ€” add socialProvider field
4. Add environment variables โ€” GOOGLE_CLIENT_ID, GITHUB_CLIENT_ID, etc.

Shall I proceed with this plan?
Plan Mode + CLAUDE.md combo

Write "always use plan mode for complex features" in your CLAUDE.md, and Claude gets in the habit of planning first automatically.

Prompt Quality Self-Checklistโ€‹

Check before you ask:

  • What: is the deliverable clear?
  • How: are there constraints on the approach?
  • Where: is the scope of impact specified?
  • Why: is the purpose provided? (optional)
  • Examples: is there a pattern or example to reference?
  • Verification: are the completion criteria clear?

Level 3 Complete!โ€‹

Finishing this level means you can use Claude Code at an intermediate level. Hooks automation, MCP extensions, cost optimization, CI/CD integration, large-codebase management, and advanced prompting โ€” you now have skills you can use in production right away.