The Plan-Execute-Review Loop
Every interaction with Claude Code follows a fundamental loop: Plan what needs to happen, Execute the changes, and Review the output. The key to being effective is knowing when to let Claude run autonomously and when to intervene with guidance.
For simple tasks, you can collapse this into a single prompt. For complex tasks, you should explicitly use plan mode first, review the plan, then let Claude execute.
# Simple task: collapsed loop (one prompt does it all)
> Fix the typo in the footer component. It says "Copyrigth" instead of "Copyright".
# Complex task: explicit plan-execute-review
> /plan
> I need to add user authentication to this Next.js app. We should use
NextAuth.js with GitHub and Google providers. Plan the implementation
including all files that need to change.
# Claude creates a detailed plan. You review it.
# Then you say:
> This plan looks good. Go ahead and implement it.
# Claude executes. You review each file change.
Workflow 1: Bug Fixing
Bug fixing is where Claude Code shines brightest. You provide the symptoms, Claude traces the cause and fixes it. The key is giving enough context for accurate diagnosis.
What to Include in a Bug Report to Claude
- Error message: The exact error text, stack trace, or console output
- Expected behavior: What should happen
- Actual behavior: What actually happens
- Reproduction steps: How to trigger the bug
- Relevant file: Where you think the bug might be (if you know)
# Effective bug fix prompt
> The checkout page crashes when a user has an empty cart.
Error: "TypeError: Cannot read properties of undefined (reading 'map')"
Stack trace points to app/checkout/page.tsx line 42.
The cart items come from the useCart() hook.
Expected: show an empty cart message. Actual: white screen crash.
Fix this bug and add a guard for empty/undefined cart state.
# Claude will:
# 1. Read app/checkout/page.tsx
# 2. Read the useCart hook
# 3. Identify the missing null check
# 4. Add proper empty state handling
# 5. May also check other pages for the same pattern
Workflow 2: Feature Implementation
For features, the key is describing what you want, not how to build it. Give Claude the behavior and constraints. Let it figure out the implementation details.
# Bad prompt (too prescriptive)
> Create a function called filterUsers that takes an array of User objects
and a string query. Loop through the array with a for loop, check if
the user.name includes the query using toLowerCase(), and push matching
items to a results array. Return the results array.
# Good prompt (describes behavior, not implementation)
> Add search functionality to the Users page. Users should be able to
type in a search box and see the user list filter in real-time by name
or email. Follow the existing patterns in this codebase for form inputs
and list filtering. Make sure it handles empty states and is debounced
to avoid excessive re-renders.
# Great prompt (adds context and constraints)
> Add search functionality to the Users page (app/users/page.tsx).
Requirements:
- Real-time filtering by name or email as the user types
- Debounced input (300ms) to avoid excessive re-renders
- Show "No users found" empty state
- Preserve existing URL params when searching
- Follow the same pattern used in app/products/page.tsx which
already has search implemented
- Add tests for the search functionality
Workflow 3: Refactoring
Refactoring is Claude Code's superpower. Tasks that would take hours of careful, mechanical work — renaming across files, extracting components, migrating patterns — take minutes.
# Extract a shared component
> I notice that app/dashboard/page.tsx and app/analytics/page.tsx both
have very similar chart card components with titles, descriptions, and
chart containers. Extract a shared ChartCard component into
app/components/ChartCard.tsx and refactor both pages to use it.
# Rename across codebase
> Rename the "subscription" concept to "membership" across the entire
codebase. This includes file names, component names, variable names,
database field references, and user-facing text. Show me the plan
before executing.
# Migration pattern
> Migrate all class components in the app/legacy/ directory to functional
components with hooks. Preserve all existing behavior and prop types.
Convert class state to useState, lifecycle methods to useEffect,
and class methods to regular functions.
Workflow 4: Code Review
Use Claude Code as a first-pass reviewer before human review. It catches bugs, security issues, and style violations that humans often miss during cursory review.
# Review a PR
> /review-pr
# Or review specific files
> Review the changes I made today. Look for:
- Potential bugs or edge cases
- Security issues (SQL injection, XSS, etc.)
- Performance problems
- Deviations from our coding conventions
- Missing error handling
- Missing tests
# Review before committing
> Look at my staged changes (git diff --staged) and review them
for any issues before I commit.
Workflow 5: Test Writing
AI-generated tests are one of the highest-ROI uses of Claude Code. The key is reviewing the tests for correctness — AI is great at test structure but can sometimes assert the wrong behavior.
# Generate tests for a specific file
> Write comprehensive tests for app/lib/pricing.ts. Include:
- Unit tests for each exported function
- Edge cases: zero values, negative numbers, currency rounding
- Test the discount calculation logic thoroughly
- Use our existing test patterns (Vitest + testing conventions from
other test files in this project)
# Generate tests and run them
> Write tests for the UserProfile component, then run them and fix
any failures. I want passing tests when you are done.
# Test coverage improvement
> Check which files in app/lib/ have no test coverage. Write tests
for the 3 most critical uncovered files. Focus on the business
logic functions, not simple utility helpers.
Workflow 6: Documentation
# Generate API documentation
> Generate JSDoc comments for all exported functions in app/lib/api.ts.
Include parameter descriptions, return types, and usage examples.
# Explain complex code
> Explain what the reconciliation algorithm in app/lib/reconciler.ts does.
Walk me through it step by step. I need to understand this before
making changes.
# Create architecture docs
> Create an ARCHITECTURE.md that documents:
- High-level system architecture
- Data flow between components
- Key design decisions and rationale
- Directory structure explanation
Base it on the actual code, not assumptions.
Context Management: When Claude Needs More
Claude Code reads files as needed, but sometimes you need to guide it to the right context. Here are signals that Claude needs more information:
| Signal | What is Happening | What to Do |
|---|---|---|
| Generic/boilerplate output | Claude does not see your existing patterns | Point to a reference file: "Follow the pattern in X" |
| Wrong assumptions about architecture | Claude has not read the right files yet | Tell it where things live: "The auth logic is in app/lib/auth/" |
| Missing dependencies/imports | Claude does not know what is installed | Reference package.json or say "we already use X library" |
| Inconsistent style | No CLAUDE.md or conventions file | Add conventions to CLAUDE.md |
| Keeps asking for clarification | Task is genuinely ambiguous | Provide more specific requirements |
The /compact Command
Long sessions can exhaust Claude's context window. When you notice Claude starting to forget earlier parts of the conversation or producing lower quality output, use /compact to summarize the conversation and free up context space. This is especially important during large refactoring sessions that involve many files. Make it a habit to compact after every major task within a session.
Task Tracking with TodoWrite
For complex multi-step tasks, Claude Code uses an internal task tracker to stay organized. You can see this in action when Claude breaks down a large request into subtasks and checks them off as it progresses. You can also explicitly ask for task tracking:
# Ask Claude to break down and track a complex task
> I need to add internationalization (i18n) to this app. Break this into
subtasks, track your progress, and implement each one:
1. Install and configure next-intl
2. Extract all hardcoded strings from components
3. Create English and Spanish translation files
4. Update the layout to support locale routing
5. Add a language switcher component
# Claude will create internal todos and work through them systematically
Real-World Session Example
Here is what a productive 30-minute Claude Code session looks like for a typical feature:
# 1. Start session and orient (2 min)
> I need to add a notifications system. Users should see a bell icon
in the header with unread count, and a dropdown showing recent
notifications. We use Supabase for the backend.
# 2. Review the plan Claude creates (3 min)
# Claude proposes: DB table, API route, hook, components, real-time sub
# You review and adjust: "Skip real-time for now, just polling every 30s"
# 3. Let Claude implement (5 min)
# Claude creates 6-8 files, you approve each change
# 4. Review the diff (10 min)
> Show me a summary of all files you changed
# 5. Test it (5 min)
> Run the tests. If any fail, fix them.
# 6. Polish (5 min)
> The dropdown looks good but add an "empty state" when there are
no notifications. Also add aria-labels for accessibility.
# Total: 30 minutes for a feature that would take 3-4 hours manually
Workflow Summary
The six core workflows — bug fixing, feature implementation, refactoring, code review, test writing, and documentation — cover 90% of daily engineering work. Master the prompting patterns for each one, learn to review AI output critically, and you will see an immediate productivity boost. The next lesson dives deep into the configuration file that makes all of these workflows dramatically more effective: CLAUDE.md.