Most best practices are based on one constraint: Claude’s context window fills up fast, and performance degrades as it fills. Claude’s context window holds your entire conversation, including every message, every file Claude reads, and every command output. However, this can fill up fast. A single debugging session or codebase exploration might generate and consume tens of thousands of tokens. This matters since LLM performance degrades as context fills. When the context window is getting full, Claude may start “forgetting” earlier instructions or making more mistakes. The context window is the most important resource to manage. Track context usage continuously with a custom status line, and see Reduce token usage for strategies on reducing token usage.
Give Claude a way to verify its work
Claude performs dramatically better when it can verify its own work, like run tests, compare screenshots, and validate outputs. Without clear success criteria, it might produce something that looks right but actually doesn’t work. You become the only feedback loop, and every mistake requires your attention.| Strategy | Before | After |
|---|---|---|
| Provide verification criteria | ”implement a function that validates email addresses" | "write a validateEmail function. example test cases: user@example.com is true, invalid is false, user@.com is false. run the tests after implementing” |
| Verify UI changes visually | ”make the dashboard look better" | "[paste screenshot] implement this design. take a screenshot of the result and compare it to the original. list differences and fix them” |
| Address root causes, not symptoms | ”the build is failing" | "the build fails with this error: [paste error]. fix it and verify the build succeeds. address the root cause, don’t suppress the error” |
Explore first, then plan, then code
Letting Claude jump straight to coding can produce code that solves the wrong problem. Use Plan Mode to separate exploration from execution. The recommended workflow has four phases:Explore
Enter Plan Mode. Claude reads files and answers questions without making changes.
claude (Plan Mode)
Plan
Ask Claude to create a detailed implementation plan.Press
claude (Plan Mode)
Ctrl+G to open the plan in your text editor for direct editing before Claude proceeds.Implement
Switch back to Normal Mode and let Claude code, verifying against its plan.
claude (Normal Mode)
Plan Mode is useful, but also adds overhead.For tasks where the scope is clear and the fix is small (like fixing a typo, adding a log line, or renaming a variable) ask Claude to do it directly.Planning is most useful when you’re uncertain about the approach, when the change modifies multiple files, or when you’re unfamiliar with the code being modified. If you could describe the diff in one sentence, skip the plan.
Provide specific context in your prompts
Claude can infer intent, but it can’t read your mind. Reference specific files, mention constraints, and point to example patterns.| Strategy | Before | After |
|---|---|---|
| Scope the task. Specify which file, what scenario, and testing preferences. | ”add tests for foo.py" | "write a test for foo.py covering the edge case where the user is logged out. avoid mocks.” |
| Point to sources. Direct Claude to the source that can answer a question. | ”why does ExecutionFactory have such a weird api?" | "look through ExecutionFactory’s git history and summarize how its api came to be” |
| Reference existing patterns. Point Claude to patterns in your codebase. | ”add a calendar widget" | "look at how existing widgets are implemented on the home page to understand the patterns. HotDogWidget.php is a good example. follow the pattern to implement a new calendar widget that lets the user select a month and paginate forwards/backwards to pick a year. build from scratch without libraries other than the ones already used in the codebase.” |
| Describe the symptom. Provide the symptom, the likely location, and what “fixed” looks like. | ”fix the login bug" | "users report that login fails after session timeout. check the auth flow in src/auth/, especially token refresh. write a failing test that reproduces the issue, then fix it” |
"what would you improve in this file?" can surface things you wouldn’t have thought to ask about.
Provide rich content
You can provide rich data to Claude in several ways:- Reference files with
@instead of describing where code lives. Claude reads the file before responding. - Paste images directly. Copy/paste or drag and drop images into the prompt.
- Give URLs for documentation and API references. Use
/permissionsto allowlist frequently-used domains. - Pipe in data by running
cat error.log | claudeto send file contents directly. - Let Claude fetch what it needs. Tell Claude to pull context itself using Bash commands, MCP tools, or by reading files.
Configure your environment
A few setup steps make Claude Code significantly more effective across all your sessions. For a full overview of extension features and when to use each one, see Extend Claude Code.Write an effective CLAUDE.md
CLAUDE.md is a special file that Claude reads at the start of every conversation. Include Bash commands, code style, and workflow rules. This gives Claude persistent context it can’t infer from code alone. The/init command analyzes your codebase to detect build systems, test frameworks, and code patterns, giving you a solid foundation to refine.
There’s no required format for CLAUDE.md files, but keep it short and human-readable. For example:
CLAUDE.md
| ✅ Include | ❌ Exclude |
|---|---|
| Bash commands Claude can’t guess | Anything Claude can figure out by reading code |
| Code style rules that differ from defaults | Standard language conventions Claude already knows |
| Testing instructions and preferred test runners | Detailed API documentation (link to docs instead) |
| Repository etiquette (branch naming, PR conventions) | Information that changes frequently |
| Architectural decisions specific to your project | Long explanations or tutorials |
| Developer environment quirks (required env vars) | File-by-file descriptions of the codebase |
| Common gotchas or non-obvious behaviors | Self-evident practices like “write clean code” |
@path/to/import syntax:
CLAUDE.md
- Home folder (
~/.claude/CLAUDE.md): Applies to all Claude sessions - Project root (
./CLAUDE.md): Check into git to share with your team, or name itCLAUDE.local.mdand.gitignoreit - Parent directories: Useful for monorepos where both
root/CLAUDE.mdandroot/foo/CLAUDE.mdare pulled in automatically - Child directories: Claude pulls in child CLAUDE.md files on demand when working with files in those directories
Configure permissions
By default, Claude Code requests permission for actions that might modify your system: file writes, Bash commands, MCP tools, etc. This is safe but tedious. After the tenth approval you’re not really reviewing anymore, you’re just clicking through. There are two ways to reduce these interruptions:- Permission allowlists: Permit specific tools you know are safe (like
npm run lintorgit commit) - Sandboxing: Enable OS-level isolation that restricts filesystem and network access, allowing Claude to work more freely within defined boundaries
--dangerously-skip-permissions to bypass all permission checks for contained workflows like fixing lint errors or generating boilerplate.
Read more about configuring permissions and enabling sandboxing.
Use CLI tools
CLI tools are the most context-efficient way to interact with external services. If you use GitHub, install thegh CLI. Claude knows how to use it for creating issues, opening pull requests, and reading comments. Without gh, Claude can still use the GitHub API, but unauthenticated requests often hit rate limits.
Claude is also effective at learning CLI tools it doesn’t already know. Try prompts like Use 'foo-cli-tool --help' to learn about foo tool, then use it to solve A, B, C.
Connect MCP servers
With MCP servers, you can ask Claude to implement features from issue trackers, query databases, analyze monitoring data, integrate designs from Figma, and automate workflows.Set up hooks
Hooks run scripts automatically at specific points in Claude’s workflow. Unlike CLAUDE.md instructions which are advisory, hooks are deterministic and guarantee the action happens. Claude can write hooks for you. Try prompts like “Write a hook that runs eslint after every file edit” or “Write a hook that blocks writes to the migrations folder.” Run/hooks for interactive configuration, or edit .claude/settings.json directly.
Create skills
Skills extend Claude’s knowledge with information specific to your project, team, or domain. Claude applies them automatically when relevant, or you can invoke them directly with/skill-name.
Create a skill by adding a directory with a SKILL.md to .claude/skills/:
.claude/skills/api-conventions/SKILL.md
.claude/skills/fix-issue/SKILL.md
/fix-issue 1234 to invoke it. Use disable-model-invocation: true for workflows with side effects that you want to trigger manually.
Create custom subagents
Subagents run in their own context with their own set of allowed tools. They’re useful for tasks that read many files or need specialized focus without cluttering your main conversation..claude/agents/security-reviewer.md
Install plugins
Plugins bundle skills, hooks, subagents, and MCP servers into a single installable unit from the community and Anthropic. If you work with a typed language, install a code intelligence plugin to give Claude precise symbol navigation and automatic error detection after edits. For guidance on choosing between skills, subagents, hooks, and MCP, see Extend Claude Code.Communicate effectively
The way you communicate with Claude Code significantly impacts the quality of results.Ask codebase questions
When onboarding to a new codebase, use Claude Code for learning and exploration. You can ask Claude the same sorts of questions you would ask another engineer:- How does logging work?
- How do I make a new API endpoint?
- What does
async move { ... }do on line 134 offoo.rs? - What edge cases does
CustomerOnboardingFlowImplhandle? - Why does this code call
foo()instead ofbar()on line 333?
Let Claude interview you
Claude asks about things you might not have considered yet, including technical implementation, UI/UX, edge cases, and tradeoffs.Manage your session
Conversations are persistent and reversible. Use this to your advantage!Course-correct early and often
The best results come from tight feedback loops. Though Claude occasionally solves problems perfectly on the first attempt, correcting it quickly generally produces better solutions faster.Esc: Stop Claude mid-action with theEsckey. Context is preserved, so you can redirect.Esc + Escor/rewind: PressEsctwice or run/rewindto open the rewind menu and restore previous conversation and code state, or summarize from a selected message."Undo that": Have Claude revert its changes./clear: Reset context between unrelated tasks. Long sessions with irrelevant context can reduce performance.
/clear and start fresh with a more specific prompt that incorporates what you learned. A clean session with a better prompt almost always outperforms a long session with accumulated corrections.
Manage context aggressively
Claude Code automatically compacts conversation history when you approach context limits, which preserves important code and decisions while freeing space. During long sessions, Claude’s context window can fill with irrelevant conversation, file contents, and commands. This can reduce performance and sometimes distract Claude.- Use
/clearfrequently between tasks to reset the context window entirely - When auto compaction triggers, Claude summarizes what matters most, including code patterns, file states, and key decisions
- For more control, run
/compact <instructions>, like/compact Focus on the API changes - To compact only part of the conversation, use
Esc + Escor/rewind, select a message checkpoint, and choose Summarize from here. This condenses messages from that point forward while keeping earlier context intact. - Customize compaction behavior in CLAUDE.md with instructions like
"When compacting, always preserve the full list of modified files and any test commands"to ensure critical context survives summarization
Use subagents for investigation
Since context is your fundamental constraint, subagents are one of the most powerful tools available. When Claude researches a codebase it reads lots of files, all of which consume your context. Subagents run in separate context windows and report back summaries:Rewind with checkpoints
Claude automatically checkpoints before changes. Double-tapEscape or run /rewind to open the rewind menu. You can restore conversation only, restore code only, restore both, or summarize from a selected message. See Checkpointing for details.
Instead of carefully planning every move, you can tell Claude to try something risky. If it doesn’t work, rewind and try a different approach. Checkpoints persist across sessions, so you can close your terminal and still rewind later.
Resume conversations
Claude Code saves conversations locally. When a task spans multiple sessions (you start a feature, get interrupted, come back the next day) you don’t have to re-explain the context:/rename to give sessions descriptive names ("oauth-migration", "debugging-memory-leak") so you can find them later. Treat sessions like branches. Different workstreams can have separate, persistent contexts.
Automate and scale
Once you’re effective with one Claude, multiply your output with parallel sessions, headless mode, and fan-out patterns. Everything so far assumes one human, one Claude, and one conversation. But Claude Code scales horizontally. The techniques in this section show how you can get more done.Run headless mode
Withclaude -p "your prompt", you can run Claude headlessly, without an interactive session. Headless mode is how you integrate Claude into CI pipelines, pre-commit hooks, or any automated workflow. The output formats (plain text, JSON, streaming JSON) let you parse results programmatically.
Run multiple Claude sessions
There are three main ways to run parallel sessions:- Claude Desktop: Manage multiple local sessions visually. Each session gets its own isolated worktree.
- Claude Code on the web: Run on Anthropic’s secure cloud infrastructure in isolated VMs.
- Agent teams: Automated coordination of multiple sessions with shared tasks, messaging, and a team lead.
| Session A (Writer) | Session B (Reviewer) |
|---|---|
Implement a rate limiter for our API endpoints | |
Review the rate limiter implementation in @src/middleware/rateLimiter.ts. Look for edge cases, race conditions, and consistency with our existing middleware patterns. | |
Here's the review feedback: [Session B output]. Address these issues. |
Fan out across files
For large migrations or analyses, you can distribute work across many parallel Claude invocations:Generate a task list
Have Claude list all files that need migrating (e.g.,
list all 2,000 Python files that need migrating)--verbose for debugging during development, and turn it off in production.
Safe Autonomous Mode
Useclaude --dangerously-skip-permissions to bypass all permission checks and let Claude work uninterrupted. This works well for workflows like fixing lint errors or generating boilerplate code.
Avoid common failure patterns
These are common mistakes. Recognizing them early saves time:- The kitchen sink session. You start with one task, then ask Claude something unrelated, then go back to the first task. Context is full of irrelevant information.
Fix:
/clearbetween unrelated tasks. - Correcting over and over. Claude does something wrong, you correct it, it’s still wrong, you correct again. Context is polluted with failed approaches.
Fix: After two failed corrections,
/clearand write a better initial prompt incorporating what you learned. - The over-specified CLAUDE.md. If your CLAUDE.md is too long, Claude ignores half of it because important rules get lost in the noise.
Fix: Ruthlessly prune. If Claude already does something correctly without the instruction, delete it or convert it to a hook.
- The trust-then-verify gap. Claude produces a plausible-looking implementation that doesn’t handle edge cases.
Fix: Always provide verification (tests, scripts, screenshots). If you can’t verify it, don’t ship it.
- The infinite exploration. You ask Claude to “investigate” something without scoping it. Claude reads hundreds of files, filling the context.
Fix: Scope investigations narrowly or use subagents so the exploration doesn’t consume your main context.