Official Best Practices

Verified beginner beginner 流程型 Process ⚡ Claude Code 专属 ⚡ Claude Code Optimized
3 min read · 136 lines

Official best practices: verification-first + explore-plan-implement + session management + 5 anti-patterns

Official Best Practices

Core Principle

The context window is your most important resource. It fills up fast, and performance degrades as it fills. Every strategy revolves around efficient context usage.

Six Key Strategies

1. Give Claude Verification

Single highest-leverage action. Provide tests, screenshots, expected outputs so Claude can self-verify.

Run the tests and ensure all pass before saying you're done.
If tests fail, fix the code — don't modify the tests.

Verification means include:

  • Existing test suites
  • Screenshots (paste images directly)
  • Expected output examples
  • Lint/type-check commands

2. Explore First, Then Plan, Then Code

Recommended workflow (press Ctrl+G to toggle Plan Mode):

Explore (Plan Mode) → Plan (Plan Mode) → Implement (Normal Mode) → Commit
  1. Explore: Let Claude read relevant code, understand existing architecture
  2. Plan: Claude drafts implementation plan, you review and adjust
  3. Implement: Switch to Normal Mode to execute
  4. Commit: Verify and commit

3. Provide Specific Context

  • Use @ to reference files
  • Paste images (error screenshots, design mockups)
  • Pipe input data: cat logs.txt | claude
  • Specify constraints and reference patterns

4. Configure Your Environment

Configuration items by priority:

Config Purpose
CLAUDE.md Project-level instructions (< 200 lines, concrete rules)
Permissions/sandbox Security boundaries
CLI tools gh, aws, gcloud, etc.
MCP servers Connect external services
Hooks Deterministic automation (not advisory)
Skills and subagents Reusable specialized workflows
Plugins Packaged and distributable extensions

5. Manage Sessions

Action Shortcut/Command Purpose
Stop Esc Interrupt current operation
Rewind Esc+Esc or /rewind Undo last step
Clear /clear Clean context between unrelated tasks
Compact /compact <instructions> Targeted context compaction
Side question /btw Quick aside (never enters history)
Subagent research Use Agent tool Protect main context window

6. Scale with Parallelism

  • Non-interactive/CI: claude -p "prompt"
  • Multiple sessions: Desktop app, web, Agent Teams
  • Fan-out: for file in $(cat files.txt); do claude -p "..." done

Common Anti-Patterns

❌ Kitchen Sink Session

Doing everything in one session. Context pollution degrades subsequent task quality.

Fix: /clear between unrelated tasks.

❌ Correcting Over and Over

Correcting the same error 2+ times. Claude may be stuck in a local loop.

Fix: After 2 failed corrections, /clear and rewrite the prompt.

❌ Over-specified CLAUDE.md

CLAUDE.md too long and detailed, burying critical rules.

Fix: Prune ruthlessly. Only keep what Claude can't infer from code.

❌ Trust-Then-Verify Gap

No verification means for Claude — just checking final results.

Fix: Always provide verification (tests, lint, type checks).

❌ Infinite Exploration

Claude keeps reading files but never starts actual work.

Fix: Scope investigations, or use subagents to isolate research.

Writer/Reviewer Pattern

An efficient collaboration pattern:

  1. Writer: Claude writes code
  2. Reviewer: Claude (or another subagent) reviews code
  3. Loop until review passes

This can be automated via skills or subagents.

Context Management Decision Guide

When you need... Use...
Project-level permanent instructions CLAUDE.md
Path-specific differentiated rules .claude/rules/
Reusable specialized workflows Skills
Delegate focused tasks Subagents
Deterministic automation Hooks
Connect external services MCP servers
Package and distribute extensions Plugins
Cross-session learning Auto Memory

相关技能 Related Skills