Claude Code Best Practices and Cheat Sheet (2026)
The Claude Code best practices that matter most, from Anthropic’s own guidance: keep CLAUDE.md short and limited to what Claude can’t find in the repo; give Claude a check it can run that passes or fails; run /clear between unrelated tasks; press Esc as soon as it drifts; use subagents for parallel or noisy work; and make anything that must always happen a hook or a deny rule.
Best practices
- Tell Claude only what it can’t see. “Only write down what Claude can’t find by reading the repo, or what it would otherwise spend time rediscovering every session.” Run
/initto start a CLAUDE.md, and keep personal preferences inCLAUDE.local.md. - Keep CLAUDE.md short. Every line “takes a little of Claude’s attention on every task”.
- Give it a check. “Give Claude something it can run that comes back pass or fail”: tests, a build, a script.
/goalkeeps Claude working until a condition is met. - Ask for evidence. Have Claude show “the command it ran and its output, or the screenshot”.
- Clear context between tasks. “
/clearbetween unrelated tasks. It costs nothing.” Use/compactwith focus instructions in a long task, and/btwfor a side question that shouldn’t enter the history. - Steer early. Press Esc “the moment Claude drifts, and after two failed corrections run
/clear”. - Use subagents for parallel and noisy work. Give a reviewer subagent only
tools: Read, Grep, Glob. See Claude Code subagents. - Enforce what can’t be skipped. “If something has to happen every time, make it a hook, a deny rule, or a managed setting.”
- Isolate parallel work.
claude -w <name>starts a session in its own git worktree. - Script it when it’s routine.
claude -p "prompt"runs once and exits;--allowedToolspre-approves tools and--output-format jsonreturns one result object.
Cheat sheet: commands
| Command | What it does |
|---|---|
/init |
Initialize the project with a CLAUDE.md guide |
/clear |
Start a new conversation with empty context |
/compact [instructions] |
Free up context by summarizing the conversation so far |
/context |
Visualize current context usage |
/btw [question] |
Ask a side question without adding it to the conversation |
/plan [description] |
Enter plan mode |
/goal [condition] |
Keep working across turns until a condition is met |
/model [model] |
Switch the model |
/effort [level] |
Set the effort level |
/permissions |
Manage allow, ask and deny rules |
/sandbox |
Toggle sandbox mode |
/mcp |
Manage MCP servers and sign-in |
/memory |
Edit CLAUDE.md files and auto memory |
/agents |
Create or manage subagents (ask Claude, or edit .claude/agents/) |
/code-review |
Review the current diff for correctness bugs |
/security-review |
Check the branch’s changes for security vulnerabilities |
/diff |
Review the changes in your working tree |
/rewind |
Rewind the conversation and/or code to an earlier point |
/resume |
Resume a conversation by ID or name |
/teleport |
Pull a cloud session into this terminal |
/usage |
Show session cost, plan limits and activity |
Cheat sheet: keyboard shortcuts
| Keys | What it does |
|---|---|
| Esc | Stop the current response or tool call so you can redirect |
| Esc Esc | Clear the draft; with an empty prompt, open the rewind menu |
| Shift+Tab | Cycle permission modes |
| Ctrl+C | Interrupt; with nothing running, clear input, then exit |
| Ctrl+R | Search command history |
| Ctrl+O | Toggle the transcript viewer |
| Ctrl+T | Toggle the task checklist |
| Ctrl+B | Send running tasks to the background |
| Ctrl+G | Open the prompt in your text editor |
| Ctrl+V | Paste an image (Cmd+V in iTerm2, Alt+V on Windows) |
! / @ / / |
Shell mode / file path / command |
Working with a team
Commit CLAUDE.md, project MCP servers (.mcp.json) and custom subagents (.claude/agents/) so everyone starts from the same setup; see Claude Code for teams. Each session still belongs to one person: to let teammates’ agents coordinate, connect them to a shared thread, as in Claude Code multiplayer.
Frequently Asked Questions
What should go in CLAUDE.md?
Only what Claude can’t find by reading the repo, or would otherwise rediscover every session: build and test commands, conventions and gotchas. Keep it short; every line costs a little attention on every task.
How do I stop Claude Code from drifting?
Press Esc as soon as it drifts. After two failed corrections, run /clear and start again with a clearer prompt.
When should I use /clear vs /compact?
Use /clear between unrelated tasks; it costs nothing. Use /compact, with instructions on what to keep, when a long task needs to free up context.
How do I run Claude Code without the interactive UI?
claude -p "prompt" runs once and exits. Add --allowedTools to pre-approve tools and --output-format json for a single result object.
Sources
Best practices, commands, interactive mode and subagents (Anthropic), checked November 20, 2026.