Guide

Claude Code best practices

Harrowtech.ai · last checked 13 October 2026

Anthropic's best practices for Claude Code rest on one constraint: the context window fills up fast, and Claude gets worse as it fills. This page turns each practice into a step you can take today, points to the Harrowtech guide that covers it in depth, and adds what four other Anthropic pages say about memory, compaction, cost and permissions that the best practices page only touches on.

Harrowtech.ai is independent of Anthropic. Sources were read on 13 October 2026. Every terminal flag named below was checked against claude --help on Claude Code 2.1.296. Slash commands such as /clear are not listed by --help, so they are given as Anthropic's documentation names them.

The checklist

Give Claude a check it can runPut the check in the prompt: the test cases plus "run the tests after implementing". To make it binding, add a Stop hook that runs the check and blocks the turn from ending until it passes. Ask for the test output, not a claim that it works. In depth: hooks.
Explore, plan, then codeStart with claude --permission-mode plan, or press Shift+Tab until the status bar shows plan mode. Ctrl+G opens the plan in your editor. Skip planning if you could describe the change in one sentence. In depth: permission modes.
Be specificName the file with @, the case to cover and how to test it. Point at an existing file to copy the pattern from. For a bug, give the symptom, where it probably is and what "fixed" looks like. Shortcuts for the prompt box: commands.
Keep CLAUDE.md shortRun /init, then delete every line that fails Anthropic's test: "Would removing this cause Claude to make mistakes?" Run /context to confirm it loaded. In depth: CLAUDE.md and projects.
Fewer prompts, still safeAdd allow rules for commands you trust with /permissions (Anthropic's examples are npm run lint and git commit), and turn on /sandbox. Switch to Manual mode when you want to approve each step. In depth: auto mode.
Prefer command-line toolsInstall gh for GitHub. For a tool Claude does not know, tell it to read the tool's --help first.
Connect outside systemsclaude mcp add --transport http <name> <url>. Switch off servers you are not using from /mcp. In depth: MCP servers.
Hooks for what must always happenAsk Claude to write one ("Write a hook that runs eslint after every file edit") or edit .claude/settings.json; /hooks lists them. In depth: hooks.
Skills for occasional knowledgeA folder in .claude/skills/ holding a SKILL.md. Add disable-model-invocation: true to any workflow with side effects so it runs only when you call it. In depth: skills.
Subagents for reading and reviewingSay "use subagents to investigate…" so the file reads stay out of your main context, or define one in .claude/agents/. In depth: agents.
Correct earlyEsc stops Claude and keeps the context. Esc twice or /rewind goes back. After two failed corrections on the same problem, /clear and write a better first prompt.
Clear between tasks/clear when the subject changes; /compact with a focus when it does not; /btw for a side question that never enters the history. Full list: commands.
Resume, do not re-explainName the session (/rename, or -n <name> at start), then claude -c for the latest or claude -r to pick one. In depth: CLI and headless mode.
Script repeat jobsclaude -p "<prompt>" --output-format json. For unattended loops, pre-approve what the job needs with --allowedTools and add --permission-mode dontAsk so anything else is refused. Try two or three files before the full run. In depth: CLI and headless mode.
Run sessions in parallelclaude -w <name> gives a session its own git worktree. The desktop app does the same from a tick box. Use a second session as the reviewer of the first. In depth: desktop app.
Review before you call it done/code-review checks the current diff in a fresh subagent. To check against a plan, ask a subagent to compare the diff with it, and tell it to report only gaps that affect correctness or the stated requirements.

What CLAUDE.md can and cannot do

The best practices page says to keep the file short. Anthropic's memory page explains why, with numbers:

That is why a rule that must never be broken belongs in a hook, not in CLAUDE.md. Where the file can live and how to set it up is in CLAUDE.md and projects.

What survives /compact

"Manage context aggressively" makes more sense once you know what compaction keeps. Anthropic's context window page lists it:

To change when automatic compaction happens, /autocompact 500k sets the threshold in a session; the matching terminal flag is --autocompact, which takes auto or a size from 100k to 1M tokens.

The cost side of the same habits

Anthropic's costs page shows that the context habits also save money, because each request sends the conversation again:

Matching the permission mode to the practice

Anthropic's permission modes page pairs each mode with a job. claude --help on 2.1.296 lists the same six values for --permission-mode: manual, acceptEdits, plan, auto, dontAsk and bypassPermissions.

Deny rules still block in every mode, including bypassPermissions. The full rules for each mode are in Claude Code auto mode and permission modes.

The five failure patterns

Anthropic closes by saying these are "starting points that work well in general, but might not be optimal for every situation."

Help setting this up

Harrowtech.ai's AI Setup service sets coding tools up with the rules and guardrails around how your developers work, from £720 (1 day). Coding tools training is a half-day from £360. See pricing.

Sources

Related: All Harrowtech.ai guides · What is Claude Code? · Claude Code docs: where to start