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 --continue to continue your last conversation
  • Use /clear to 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 /vim or /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+S stashes 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+B to move a running command to background. Output is buffered and retrievable. Disable with CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1
    • Hit the down arrow in chat, select a background command, hit enter for details. Kill any with k
  • 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, supports Ctrl+B backgrounding, and has history-based Tab autocomplete. Exit with Escape, Backspace, or Ctrl+U on empty prompt
  • YOLO mode alias: alias cc="claude --dangerously-skip-permissions" (use with caution!)
  • Add IS_SANDBOX=1 claude --dangerously-skip-permissions for 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 /init to generate a starter CLAUDE.md for your project
  • /rewind or double-tap ESC to open the checkpoint menu and roll back
  • /plugin to 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 conversation
  • claude -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. /clear between 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, /clear and 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:

  1. Continue — send another message in the same session
  2. /rewind (or double-tap Esc) — jump back to a previous message and retry from there
  3. /clear — start a new session, usually with a brief you've distilled from what you just learned
  4. Compact — summarize the session so far and keep going on top of the summary
  5. 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, /rewind is 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 /clear or a fresh session
  • /clear with a hand-written brief is often better than /compact for 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 worktree
  • git 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: worktree in agent frontmatter runs a subagent in its own worktree
  • sparsePaths in worktree config to checkout only needed directories
  • /batch auto-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 conversation
  • ULTRATHINK keyword 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 thinking
  • think hard — deeper
  • ultrathink — deepest (equivalent to max effort for that turn)

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.md files 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

Utilities

Templates

References


About Sébastien

Ready to get to the next level?

Found this valuable? Share it with someone who needs it.

Join 6,000+ readers. Get practical systems for knowledge & AI. Free.

Subscribe ✨

Free: Knowledge System Checklist

A clear roadmap to building your own knowledge system. Subscribe and get it straight to your inbox.

6,000+ readers. No spam. Unsubscribe anytime.

Subscribe