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 run | Put 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 code | Start 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 specific | Name 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 short | Run /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 safe | Add 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 tools | Install gh for GitHub. For a tool Claude does not know, tell it to read the tool's --help first. |
| Connect outside systems | claude mcp add --transport http <name> <url>. Switch off servers you are not using from /mcp. In depth: MCP servers. |
| Hooks for what must always happen | Ask 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 knowledge | A 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 reviewing | Say "use subagents to investigate…" so the file reads stay out of your main context, or define one in .claude/agents/. In depth: agents. |
| Correct early | Esc 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-explain | Name 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 jobs | claude -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 parallel | claude -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:
- Size. Target under 200 lines per CLAUDE.md file; longer files "consume more context and reduce adherence". Splitting a long file with
@pathimports tidies it but saves nothing, because imported files load at launch too. - Status. CLAUDE.md arrives as a user message after the system prompt, so there is "no guarantee of strict compliance, especially for vague or conflicting instructions". If two files contradict each other, Claude may pick one arbitrarily.
- Auditing.
/doctor prompt-audit(Claude Code 2.1.283 or later) looks for instructions written for older models, references to files or commands that do not exist, and files that contradict each other. It proposes edits and changes nothing until you ask. - Auto memory is separate. Claude's own notes live in a
MEMORY.mdindex, and only its first 200 lines or 25KB, whichever comes first, load at the start of a session.
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:
- The project-root CLAUDE.md, auto memory and any plan written in plan mode are re-read from disk.
- Up to five of the files Claude read or edited are re-read, most recently changed first. A file over 5,000 tokens comes back as a path only.
- Skills already used are re-injected, capped at 5,000 tokens each and 25,000 in total, oldest dropped first. Truncation keeps the start of the file, so put a skill's key instructions near the top.
- Anything you said only in the conversation is summarised with everything else. If it must persist, put it in CLAUDE.md.
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:
- Clear rather than compact for a fresh start.
/compacthas to read the conversation it summarises, so on a large context it is itself a large request./clearcosts nothing. - Breaks cost more than you think. The prompt cache lasts an hour on a subscription and five minutes by default on an API key. The first message after a longer break reprocesses the whole context.
- Command-line tools beat MCP on context. Tools such as
ghadd no per-tool listing, which is the reason behind the "prefer command-line tools" practice. - Hooks can shrink what Claude reads. Anthropic's example is a hook that greps a 10,000-line log for
ERRORinstead of passing the whole file, cutting tens of thousands of tokens to hundreds. - Pick the model for the job. Anthropic says Sonnet handles most coding tasks and costs less than Opus, and suggests
model: haikufor simple subagents. - Know your baseline. Across enterprise deployments Anthropic puts the average at around US$13 per developer per active day and US$150 to US$250 a month, with 90% of users under US$30 a day.
/usageshows your own figures. Plan prices are in Claude Code pricing.
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.
- Exploring before a change:
plan; Claude Code blocks edits until you approve the plan. - Long tasks with fewer prompts:
auto, which from Claude Code 2.1.283 is the starting mode for interactive terminal and VS Code sessions. - CI with an exact allowlist: Anthropic's example is
claude -p "run the test suite" --permission-mode dontAsk --allowedTools "Bash(npm test)" "Read". - Fully unattended:
bypassPermissions, only inside a container or virtual machine.
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
- Kitchen sink session (unrelated tasks in one context):
/clearbetween them. - Correcting over and over: after two misses, clear and rewrite the first prompt.
- Over-long CLAUDE.md: prune; turn rules Claude already follows into hooks or delete them.
- Trust-then-verify gap (plausible code, missed edge cases): always give a check. In Anthropic's words, "If you can't verify it, don't ship it."
- Endless exploration: scope the investigation, or hand it to a subagent.
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
- Anthropic: Best practices for Claude Code, read 13 October 2026
- Anthropic: How Claude remembers your project, read 13 October 2026
- Anthropic: Explore the context window, read 13 October 2026
- Anthropic: Manage costs effectively, read 13 October 2026
- Anthropic: Choose a permission mode, read 13 October 2026
claude --helpandclaude mcp --helpon Claude Code 2.1.296, run 13 October 2026
Related: All Harrowtech.ai guides · What is Claude Code? · Claude Code docs: where to start