Claude Code Tips and Best Practices
Canonical version: Claude Code Tips and Best Practices.
General tips
- Course correct early and often: cancel whatever Claude is doing and adapt your prompt whenever needed
- Use
claude --continueto continue your last conversation - Use
/clearto keep the context "clean" (focused) - Use
/add-dir <new dir>to work with multiple directories in a single session - Pipe data into Claude instead of copy/pasting (e.g.,
cat foo.txt | claude) - Ask Claude to read files or fetch URLs (also works with images!)
- Enable sound alerts:
claude config set --global preferredNotifChannel terminal_bell - Vim key bindings via
/vimor/config: https://docs.anthropic.com/en/docs/claude-code/settings#vim-mode - Add/configure/leverage Model Context Protocol (MCP) servers
- Run multiple tasks in parallel:
Use 3 parallel agents to ... - Drag and drop images or copy/paste into Claude Code to analyze them
- Use
git,gh(GitHub CLI), and other CLI tools from within Claude Code - Prompt stashing: long prompt, short detour?
Ctrl+Sstashes your draft so you can fire off a quick question first. The stashed prompt restores automatically after you submit (tip from Ado: https://x.com/adocomplete/status/2029988814924722559) - Background bash commands: prompt Claude to run in background, or
Ctrl+Bto move a running command to background. Output is buffered and retrievable. Disable withCLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1- Hit the down arrow in chat, select a background command, hit enter for details. Kill any with
k
- Hit the down arrow in chat, select a background command, hit enter for details. Kill any with
- Launch background sessions programmatically:
claude --bg --name "Session Name" "Prompt goes here"dispatches a new named session that runs in the background and shows up in the agent view (claude agents). Perfect for handing work off to a parallel session without opening a new terminal — the session is just... already running when you check on it - Use
#to quickly add something to memory - Use
! <command>to run a shell command without leaving Claude Code. Adds command + output to context, supportsCtrl+Bbackgrounding, and has history-based Tab autocomplete. Exit withEscape,Backspace, orCtrl+Uon empty prompt - YOLO mode alias:
alias cc="claude --dangerously-skip-permissions"(use with caution!) - Add
IS_SANDBOX=1 claude --dangerously-skip-permissionsfor fully unrestricted mode - Use "Correct me if I'm wrong" to decrease AI Sycophancy
- Front-load the most important instruction at the top of the prompt
- Assume zero context: Claude knows nothing about your project. Tell it everything it needs
- Run
/initto generate a starter CLAUDE.md for your project /rewindor double-tapESCto open the checkpoint menu and roll back/pluginto browse the plugin marketplace. Plugins add skills, tools, and integrations without config- For larger projects, have Claude interview you first: ask it to use AskUserQuestion to clarify requirements before starting
- Ask Claude to score its output against pre-defined success criteria
- Use other LLMs to plan and generate mega prompts before opening Claude Code (saves tokens from Plan Mode)
Context management
/context: visualize context usage and get optimization tips/compact [focus]: compress context with an optional focus instruction- Auto-compact triggers at ~95% capacity
- CLAUDE.md content survives compaction
claude -c: continue the last conversationclaude -r "name": resume a named session/btw question: side question with no context cost--max-budget-usd 5: cap session cost- Pipe input for one-shot queries:
cat file | claude -p "Summarize" - Don't context-switch mid-session.
/clearbetween unrelated tasks; mixing topics pollutes context with irrelevant information - Scope investigations narrowly or use subagents so open-ended exploration doesn't fill main context
- After two failed corrections,
/clearand write a better initial prompt incorporating what you learned rather than adding more corrections
Session management with 1M context
With the 1M token context window, Claude Code can operate autonomously for longer — but only if you manage sessions well. Context rot (the gradual drop in model quality as the window fills) makes active session management more important, not less.
Every turn is a branching point. After Claude finishes a turn, you have five choices:
- Continue — send another message in the same session
/rewind(or double-tapEsc) — jump back to a previous message and retry from there/clear— start a new session, usually with a brief you've distilled from what you just learned- Compact — summarize the session so far and keep going on top of the summary
- Subagents — delegate the next chunk of work to a subagent with its own clean context, and only pull its result back
Rules of thumb:
- New task → new session. Related follow-ups (e.g., writing docs for a feature you just shipped) can stay in the same session to reuse context
- Rewind beats correcting. If Claude went down a bad path,
/rewindis cleaner than piling on corrections — the failed attempt stays in context and poisons future reasoning - Use
"summarize from here"at a good state to produce a handoff brief for/clearor a fresh session /clearwith a hand-written brief is often better than/compactfor a genuinely new chunk of work. Compact preserves detail but inherits whatever context rot was already present- Bad compacts happen when autocompact fires mid-debugging and drops information that mattered for a later turn. Because context rot is at its worst right before compaction, the summary is produced by the model at its least intelligent point — compact deliberately, not reactively
Subagent mental test: "Will I need this tool output again, or just the conclusion?" If only the conclusion, spawn a subagent so the raw exploration stays out of your main context. Explicit triggers:
- "Spin up a subagent to verify this work against the spec file"
- "Spin off a subagent to read through codebase X and summarize how it implemented auth"
- "Spin off a subagent to write the docs on this feature based on my git changes"
Reference: https://x.com/trq212/status/2044548257058328723 (Thariq, Claude Code team)
Git worktrees
Leverage worktrees to run multiple Claude instances in parallel:
claude -w feature-a: start Claude in an isolated worktreegit worktree add ../project-feature-a feature-a && cd ../project-feature-a && claude- Keep one terminal tab per worktree
- Use separate IDE windows for different worktrees
- Cleanup:
git worktree remove ../project-feature-a isolation: worktreein agent frontmatter runs a subagent in its own worktreesparsePathsin worktree config to checkout only needed directories/batchauto-creates worktrees for parallel changes
Useful prompt to let Claude handle worktrees:
I want to run Claude Code in multiple terminal windows on this codebase simultaneously.
The recommended way is using git worktrees. Ultrathink about this and plan, then create
a set of rules in a new "worktrees" folder with a Markdown file for each of the following:
init, create, merge, pr for, sync, remove a worktree. Consider conflicting issues like ports.
Reference: https://x.com/iannuttall/status/1938177015384805548
Extended thinking and effort
Since Opus 4.6 (Feb 2026), Claude Code uses adaptive thinking by default: the model decides how long to think, which tends to outperform fixed thinking budgets across the board. Opt out with CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1
Since Mar 2026, the default reasoning effort is medium (85), a sweet spot on the intelligence-latency-cost curve for most users. To increase intelligence at the cost of more tokens and latency:
/effort high— sticky across sessions, shareable via settings.json/effort max— even higher effort for the rest of the conversationULTRATHINKkeyword in a prompt — max effort for a single turn only
Anthropic plans to default Teams and Enterprise users to high effort
Thinking keywords (escalating depth):
think— basic extended thinkingthink hard— deeperultrathink— deepest (equivalent to max effort for that turn)
Model switching
In the /model picker, Enter changes your default. Press s to change the session only.
Easy to get wrong, and the cost is silent: you dip into a more expensive model for one conversation that warrants it, hit Enter, and every later session keeps using it until you notice. That's the whole tip, via Craigory Coppola.
The useful habit that follows: treat s as the default gesture and Enter as a deliberate decision about how you want to work from now on. Same distinction as /effort high being sticky across sessions versus ULTRATHINK applying to a single turn. Claude Code repeatedly offers per-turn, per-session and persistent versions of the same control, and knowing which one you just pulled is most of the skill.
Prompt structure
XML-like tags help Claude isolate different parts of long prompts:
<instructions>Foo</instructions>
<requirements>Bar</requirements>
<rules>Baz</rules>
A practical prompting structure: [Role] + [Task] + [Context]
Recommendations
- Avoid pasting long content. Use file-based workflows instead
- Create
CLAUDE.mdfiles to customize behavior (see Claude Code Memory) - Explore > Plan > Confirm > Do:
Analyze X then propose different approaches and let me choose one before you continue - Leverage screenshots:
Do X then screenshot Y using Z and ... - Leverage commands to automate specific tasks
- Give Claude a way to verify its work: include tests, screenshots, or expected outputs so Claude can self-check. Highest-leverage tip
- Create skills from great outputs: paste a good result and ask Claude to turn it into a reusable skill. Also works with screenshots
- Version skills: duplicate and version as you refine instead of editing live ones
- Define custom subagents in
.claude/agents/for isolated, specialized tasks - If CLAUDE.md gets too long, Claude ignores half of it. Prune ruthlessly; delete rules Claude already follows by default, or convert mandatory behaviors to hooks
More: https://www.anthropic.com/engineering/claude-code-best-practices
Debugging and error handling
- Re-run only the broken step instead of regenerating everything
- Ask Claude to intentionally reproduce a failure to understand it
- Revert to the last known good prompt and reapply changes one at a time
- Have Claude walk through how it generated an answer step by step
Status line
Claude Code supports custom status lines via statusLine in ~/.claude/settings.json. See Claude Epic Status Line for a feature-rich implementation with colors, rate limits, git info, session cost, worktree detection, and auto-compact warnings.
Plugins
- Codex plugin for Claude Code — integrate OpenAI Codex for code review and task delegation (
/codex:review,/codex:rescue)
Utilities
- Claude Account Switcher — one isolated config + credential store per account (
claude account add/use/list), so work and personal stop fighting over the same login. The DIY version isCLAUDE_CONFIG_DIRplus a shell alias. - ccusage — track real usage and costs (
npm install -g ccusage,npx ccusage blocks --live) - Trace Claude Code calls: https://github.com/badlogic/lemmy/tree/main/apps/claude-trace
- Explanations: https://simonwillison.net/2025/Jun/2/claude-trace
- https://github.com/possibilities/claude-composer
- Collection of resources: https://github.com/affaan-m/everything-claude-code
Templates
References
- Thariq on session management & 1M context: https://x.com/trq212/status/2044548257058328723
- Boris Cherny's hidden features thread: https://x.com/bcherny/status/2038454336355999749
- Best practices: https://www.anthropic.com/engineering/claude-code-best-practices
- Troubleshooting: https://docs.anthropic.com/en/docs/claude-code/troubleshooting
- Third-party integrations: https://docs.anthropic.com/en/docs/claude-code/third-party-integrations
- Proxy to connect to other LLMs: https://github.com/1rgs/claude-code-proxy
- History of system prompts: https://github.com/badlogic/cchistory
- How to extend Claude Code: https://code.claude.com/docs/en/features-overview
- Token usage tips: https://code.claude.com/docs/en/costs#reduce-token-usage
- Claude Superpowers (GitHub): https://github.com/obra/superpowers
- Claude Code course (inside Claude Code): https://ccforeveryone.com
Related
About Sébastien
Ready to get to the next level?
Found this valuable? Share it with someone who needs it.