Claude Code: Coding Plan
Last updated: 2026-08-31
Coding Plan makes Claude Code go from "doing whatever comes to mind" to "thinking clearly first" — output a plan before executing complex tasks, confirm then proceed.
💡 Tip: Coding Plan essentially makes Claude Code output a plan before acting, including steps, impact scope, and risk assessment. You confirm before execution, avoiding "halfway through and heading wrong direction" waste.
📋 Prerequisites: Chapter 24 - Agent SDK
1. What You'll Learn
- Coding Plan mechanism
- Trigger and usage methods
- Plan review and modification
- Plan execution and verification
- Best practices
2. Coding Plan Mechanism
(1) When to Use
| Scenario | Need Plan? | Reason |
|---|---|---|
| Multi-file refactoring | ✅ Yes | Large impact scope |
| Architecture changes | ✅ Yes | Irreversible direction |
| Data migration | ✅ Yes | Data risk high |
| Simple bug fix | ❌ No | Small impact |
| Single file addition | ❌ No | Low risk |
▶ Example 1: Trigger Coding Plan
TEXT
📖 Display only
# Method 1: /plan command
> /plan Migrate auth from Session to JWT
# Method 2: Include "plan first" in instruction
> Migrate auth from Session to JWT, plan first then execute
# Method 3: Auto-trigger (large tasks)
> Refactor entire project's error handling
3. Plan Generation
(1) Plan Structure
TEXT
📖 Display only
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Coding Plan: Session → JWT Auth Migration
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
## Goal
Migrate authentication from Session to JWT
## Impact Scope
- Modified files: 12
- New files: 3
- Deleted files: 2
- DB changes: None
## Execution Steps
### Step 1: Create JWT utility module
- New src/auth/jwt.ts
- Implement token generation, verification, refresh
- Write unit tests
### Step 2: Modify auth middleware
- Modify src/middleware/auth.ts
- Change from Session to JWT verification
- Keep interface unchanged
### Step 3: Modify login/register routes
- Modify src/routes/auth.ts
- Return JWT token instead of setting Session
### Step 4: Modify protected routes
- Modify 8 route files
- Adjust auth check method
### Step 5: Clean up Session code
- Delete session config
- Remove express-session dependency
## Risk Assessment
- 🔴 High: Middleware migration may affect all logged-in users
- 🟡 Medium: Token refresh logic needs careful design
- 🟢 Low: Utility module independent, doesn't affect existing code
## Estimate
- Tokens: ~80K
- Time: ~15 min
- Cost: ~$1.60
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Confirm execution? [y/n/modify]
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
▶ Example 2: Review and Modify Plan
TEXT
📖 Display only
> Step 5 doesn't need Session deletion, keep compatibility for 2 weeks
Claude Code:
Updated plan:
Step 5: Keep Session compatibility
- Don't delete express-session
- Add dual auth support (Session + JWT)
- Clean up Session code after 2 weeks
Confirm? [y/n/modify] y
Starting execution...
4. Plan Execution and Verification
(1) Step-by-Step Execution
TEXT
📖 Display only
[Step 1/5] Create JWT utility module
→ Creating src/auth/jwt.ts
→ Running: npm test -- jwt.test.ts
✅ Step 1 complete
/checkpoint "jwt-module-complete"
[Step 2/5] Modify auth middleware
→ Modifying src/middleware/auth.ts
→ Running: npm test -- auth.test.ts
✅ Step 2 complete
[Step 3/5] Modify login/register routes
✅ Step 3 complete
(2) Handling Problems
TEXT
📖 Display only
[Step 4/5] Modify protected routes
→ Running: npm test
❌ 3 tests failed
→ Root cause: Some routes depend on req.session
→ Fix: Map JWT payload to req.user in middleware
→ Re-running: npm test ✅
5. Best Practices
(1) Plan Review Checklist
| Check Item | Description |
|---|---|
| Impact scope | Which files modified/added/deleted? |
| Risk assessment | What are high/medium/low risk points? |
| Rollback plan | Can each step be rolled back? |
| Dependencies | Are steps sequential or parallel? |
| Test strategy | How to verify each step? |
| Token estimate | Total consumption within budget? |
(2) Execution Discipline
| Rule | Description |
|---|---|
| Step-by-step confirm | Check each step before continuing |
| Checkpoints | Create checkpoint after key steps |
| Test first | Run tests to verify each step |
| Adjust timely | Modify plan when issues arise |
| Cost monitoring | Check /cost each step |
6. Comprehensive Example: Large Migration with Plan
TEXT
📖 Display only
> /plan Migrate entire microservice project from JavaScript to TypeScript
Claude Code generates detailed plan:
## Phase 1: Infrastructure (1-2 hours)
Step 1: Install TypeScript and type definitions
Step 2: Create tsconfig.json (loose mode first)
Step 3: Configure build scripts
## Phase 2: Shared Modules (2-3 hours)
Step 4: Migrate shared/types/ (5 files)
Step 5: Migrate shared/utils/ (8 files)
## Phase 3: Service Modules (3-4 hours, parallelizable)
Step 6: Migrate user-service/ (12 files)
Step 7: Migrate order-service/ (15 files)
Step 8: Migrate payment-service/ (10 files)
## Phase 4: Strict Mode (1-2 hours)
Step 9: Enable strict mode
Step 10: Fix all type errors
Step 11: Full test verification
Total: Modify 53 files, New 8 files
Estimate: ~200K tokens, ~$4.00
> Execute by Phase, /checkpoint after each Phase
[Phase 1 complete] /checkpoint "ts-infra"
[Phase 2 complete] /checkpoint "shared-modules"
[Phase 3 complete] /checkpoint "services"
[Phase 4 complete] /checkpoint "strict-mode"
✅ All tests passed, migration complete!
❓ FAQ
Q How many extra Tokens does Coding Plan consume?
A About 10-20% more for the planning step. But avoids wrong-direction waste, actually saves overall.
Q Can plans be saved?
A Yes. Plans output in Markdown; copy to file for reference.
Q Small tasks need Plans?
A No. Simple bug fixes and single-file additions are more efficient without plans. Plans suit large-impact tasks.
Q Must follow the plan exactly?
A No. You can modify, skip, or reorder steps. Plans guide, not constrain.
Q Can I generate multiple plans to compare?
A Yes. Ask Claude Code "generate 2-3 approaches and compare", choose the best.
Q Plan vs Skill difference?
A Plans are task-specific temporary planning; Skills are reusable standard workflows. One-time big tasks use Plans; repetitive workflows use Skills.
📖 Summary
- Coding Plan plans before executing, avoiding wrong direction
- Trigger:
/plan, request plan in instruction, auto-trigger for large tasks - Plan includes: steps, impact scope, risk assessment, Token estimate
- Execution discipline: step-by-step confirm, checkpoints, test verification, adjust timely
- Multi-step tasks recommend Plan + Checkpoint combination
📝 Exercises
- Basic (⭐): Use
/planfor a 3-step modification task, compare with no-plan execution. - Intermediate (⭐⭐): Use Coding Plan for 5+ step refactoring, create checkpoints at each step.
- Advanced (⭐⭐⭐): Generate Plan for 10+ step large migration, execute in phases, record Token and time per Phase.