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. To see how a session fills up in practice, watch an interactive walkthrough of what loads at startup and what each file read costs. 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 stops when the work looks done. Without a check it can run, âlooks doneâ is the only signal available, and you become the verification loop: every mistake waits for you to notice it. Give Claude something that produces a pass or fail, and the loop closes on its own. Claude does the work, runs the check, reads the result, and iterates until the check passes. The check is anything that returns a signal Claude can read in the conversation: a test suite, a build exit code, a linter, a script that diffs output against a fixture, or a browser screenshot compared against a design. Run/verify yourself after Claudeâs check passes to confirm the change against the running app.
Once the check exists, decide how hard it gates the stop:
- In one prompt: ask Claude to run the check and iterate in the same message, as in the table above.
- Across a session: set the check as a
/goalcondition. A separate evaluator re-checks it after every turn and Claude keeps working until the goal resolves. If Claude stalls, Claude Code eventually stops the run with the goal still set â see how /goal evaluation works. - As a deterministic gate: a Stop hook runs your check as a script and blocks the turn from ending until it passes. Claude Code overrides the hook and ends the turn after 8 consecutive blocks.
- By a second opinion: a verification subagent or a dynamic workflow that checks its own findings has a fresh model try to refute the result, so the agent doing the work isnât the one grading it.
/goal and Stop hook versions are what let an unattended run finish correctly without you.
Have Claude show evidence rather than asserting success: the test output, the command it ran and what it returned, or a screenshot of the result. Reviewing evidence is faster than re-running the verification yourself, and it works for sessions you werenât watching.
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:1
Explore
Enter plan mode by pressing
Shift+Tab until the status bar shows ⸠plan mode on, or start the session with claude --permission-mode plan. Claude reads files and answers questions without making changes.claude (plan mode)
2
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.3
Implement
Switch out of plan mode by approving the plan or pressing
Shift+Tab, then let Claude code, verifying against its plan.claude
4
Commit
Ask Claude to commit with a descriptive message and create a PR.
claude
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.
Vague prompts can be useful when youâre exploring and can afford to course-correct. A prompt like
"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. Thereâs no required format for CLAUDE.md files, but keep it short and human-readable. For example:CLAUDE.md
/context to confirm Claude loaded the file. CLAUDE.md is loaded every session, so only include things that apply broadly. For domain knowledge or workflows that are only relevant sometimes, use skills instead. Claude loads them on demand without bloating every conversation.
Keep it concise. For each line, ask: âWould removing this cause Claude to make mistakes?â If not, cut it. Bloated CLAUDE.md files cause Claude to ignore your actual instructions!
If Claude keeps doing something you donât want despite having a rule against it, the file is probably too long and the rule is getting lost. If Claude asks you questions that are answered in CLAUDE.md, the phrasing might be ambiguous. Treat CLAUDE.md like code: review it when things go wrong, prune it regularly, and test changes by observing whether Claudeâs behavior actually shifts. For a checked-in CLAUDE.md, run
/doctor and Claude proposes cuts for content it can derive from the codebase.
If Claude keeps skipping one instruction, add emphasis such as âIMPORTANTâ to that line alone. If you emphasize many lines, none of them stands out. Check CLAUDE.md into git so your team can contribute. The file compounds in value over time.
CLAUDE.md files can import additional files using @path/to/import syntax. For import rules and where CLAUDE.md files can live, see CLAUDE.md files.
Configure permissions
On Pro, Max, and Team plans, auto mode is the built-in starting permission mode for interactive terminal and VS Code sessions: a separate classifier model reviews most actions instead of you and blocks only what looks risky, such as scope escalation, unknown infrastructure, or hostile-content-driven actions. In Manual mode, the built-in starting permission mode on other plans, Claude Code asks before actions that might modify your system: file writes, Bash commands, MCP tools. Thatâs safe but tedious. After the tenth approval youâre clicking through rather than reviewing. Two tools cut those interruptions in Manual mode and apply in auto mode as well:- 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
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.â Edit.claude/settings.json directly to configure hooks by hand, and run /hooks to browse whatâs configured.
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
Ask Claude the questions youâd ask another engineer, and for larger features have Claude interview you and write a spec before you start implementing.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. Replace[brief description] with your feature before sending the prompt.
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 or Summarize up to here. The first condenses messages from that point forward while keeping earlier context intact; the second condenses earlier messages while keeping recent ones in full. See the rewind menuâs summarize options. - 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 - For questions that donât need to stay in context, use
/btw. The answer never enters conversation history, so you can check a detail without growing context.
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 snapshots files before each change so a checkpoint can restore them. 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 are saved with the conversation, so you can close your terminal, resume the session later, and still rewind.
Resume conversations
Claude Code saves conversations locally, so when a task spans multiple sittings you donât have to re-explain the context. Runclaude --continue to pick up where you left off, or claude --resume to choose from a list. Give sessions descriptive names like oauth-migration so you can find them later. See Manage sessions for the full set of resume, branch, and naming controls.
Automate and scale
Once youâre effective with one Claude, multiply your output with parallel sessions, non-interactive mode, and fan-out patterns.Run non-interactive mode
Withclaude -p "your prompt", you can run Claude non-interactively, without an interactive prompt. The run still creates a resumable session unless you pass --no-session-persistence. Non-interactive mode is how you integrate Claude into CI pipelines, pre-commit hooks, or any automated workflow. The output formats let you parse results programmatically: plain text, JSON, or streaming JSON.
json format returns a single JSON object with a result field. The stream-json format prints one JSON object per line, starting with an init event.
Run multiple Claude sessions
Pick the parallel approach that fits how much coordination you want to do yourself:- Worktrees: run separate CLI sessions in isolated git checkouts so edits donât collide
- Desktop app: manage multiple local sessions visually, each in its own worktree
- Claude Code on the web: run sessions in the cloud, on Anthropic-managed infrastructure by default
- Agent view: research preview. Run
claude agentsto dispatch sessions that keep running in the background and watch them from one screen - Agent teams: experimental and disabled by default. Automated coordination of multiple sessions with shared tasks, messaging, and a team lead
You can do something similar with tests: have one Claude write tests, then another write code to pass them.
Fan out across files
For large migrations or analyses, you can distribute work across many parallel Claude invocations. In a git repository, run/batch <instruction> to have Claude split the change across 5 to 30 subagents. Each subagent works in its own worktree and opens a pull request. To drive the fan-out from your own script instead, loop over claude -p:
1
Generate a task list
Have Claude write the list of files that need migrating to a file, so the loop in the next step can read it, with a prompt like
list all 2,000 Python files that need migrating and save the list to files.txt2
Write a script to loop through the list
3
Test on a few files, then run at scale
Refine your prompt based on what goes wrong with the first 2-3 files, then run on the full set. The
--allowedTools flag restricts what Claude can do, which matters when youâre running unattended.--verbose for debugging during development, and turn it off in production.
Run autonomously with auto mode
For uninterrupted execution with background safety checks, use auto mode. A classifier model reviews commands before they run, blocking scope escalation, unknown infrastructure, and hostile-content-driven actions while letting routine work proceed without prompts.-p flag, Claude Code doesnât stop the run. See when auto mode falls back for what happens instead and for the thresholds.
Add an adversarial review step
The longer Claude works unattended, the more an independent check matters before you count the work as done. A reviewer running in a fresh subagent context sees only the diff and the criteria you give it, not the reasoning that produced the change, so it evaluates the result on its own terms. For a correctness check, run the bundled/code-review skill, which reviews the current diff for bugs in a fresh subagent and returns findings to the session. To check the diff against your plan instead, write the review prompt yourself. Name the work to check, the plan to check it against, and what counts as a finding:
A reviewer prompted to find gaps will usually report some, even when the work is sound, because that is what it was asked to do. Chasing every finding leads to over-engineering: extra abstraction layers, defensive code, and tests for cases that canât happen. Tell the reviewer to flag only gaps that affect correctness or the stated requirements, and treat the rest as optional.
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.
Develop your intuition
The patterns in this guide arenât set in stone. Theyâre starting points that work well in general, but might not be optimal for every situation. Sometimes you should let context accumulate because youâre deep in one complex problem and the history is valuable. Sometimes you should skip planning and let Claude figure it out because the task is exploratory. Sometimes a vague prompt is exactly right because you want to see how Claude interprets the problem before constraining it. Pay attention to what works. When Claude produces great output, notice what you did: the prompt structure, the context you provided, the mode you were in. When Claude struggles, ask why. Was the context too noisy? The prompt too vague? The task too big for one pass? Over time, youâll develop intuition that no guide can capture. Youâll know when to be specific and when to be open-ended, when to plan and when to explore, when to clear context and when to let it accumulate.Related resources
- How Claude Code works: the agentic loop, tools, and context management
- Extend Claude Code: skills, hooks, MCP, subagents, and plugins
- Common workflows: step-by-step recipes for debugging, testing, PRs, and more
- CLAUDE.md: store project conventions and persistent context