Claude Code Best Practices
Claude Code best practices fall into four habits: keep CLAUDE.md small, plan before you write code, guard the context window, and make safety checks deterministic. The pattern across practitioner accounts is that the person holding the tool, not the model, sets the ceiling on quality. Teams that follow these habits get predictable, reviewable output, while teams that skip them get a faster autocomplete.
Keep the instruction file small and specific
CLAUDE.md is the project memory that Claude Code reads at the start of every session. Keep the file small because frontier models reliably follow roughly 150 to 200 instructions and the system prompt already uses about 50. The HumanLayer team keeps CLAUDE.md under 60 lines with 300 as the hard limit. If Claude can infer a rule from reading the code, leave it out.
- Build, test, and deploy commands
- Project structure and framework versions
- Coding conventions
- Important rules like never committing secrets, static export constraints, and accessibility requirements
When rules accumulate, split them into files under .claude/rules/ and load them only for matching paths. Path frontmatter can scope rules to file types so TypeScript rules load only when Claude reads .ts files. Skills work the same way: they load on demand instead of every session, which keeps context lean. CLAUDE.md is advisory, so anything that must happen without exception belongs in a hook, not in the file.
Plan before you write code
The most common failure is treating Claude Code like a faster autocomplete. For anything moderately complex, press Shift+Tab twice to enter plan mode, where Claude researches the codebase and produces a plan without changing any files. This prevents Claude from spending twenty minutes confidently solving the wrong problem. Review and refine the plan before exiting plan mode, and do not accept the first version.
- Multi-file changes and refactors
- Unfamiliar parts of the codebase
- Architecture decisions that touch several components
- Debugging where the cause is unclear
Plan mode alone is not enough for substantial projects. Ask Claude to interview you with the AskUserQuestion tool before building. The questions surface edge cases you did not consider. Some practitioners use a structured AI SDLC framework that produces user flows and specifications before any code and validates each stage against them. After the interview, start a fresh session for execution, because the interview conversation clutters context and degrades the build.
Manage the context window aggressively
Claude performance drops noticeably when context usage passes about 60 to 70 percent. Practitioners call this the agent dumb zone, where Claude ignores instructions and makes basic errors. Compact manually at 50 percent instead of waiting for automatic compaction, which fires too late.
- Press Esc twice or use /rewind to roll back to a checkpoint when Claude goes off track
- Start a clean session with /clear when switching tasks or after two failed fix attempts
- Install a statusline script that color-codes context usage
- Run long investigations in subagents so they do not consume main context
Make guardrails deterministic
Anything that must happen every time belongs in a hook. PostToolUse hooks can run a formatter on every edit. PreToolUse hooks can block destructive commands like rm -rf or drop table before they run. Sandbox mode restricts writes to the project directory and network requests to approved domains. Keep a human reviewer on auth flows, payment logic, and data mutations regardless of how good the rest looks.
Community skills close expertise gaps that Claude Code will not suggest on its own. Skills are markdown files that load only when relevant, so they add knowledge without bloating every session. Structure a skill as a folder with a main SKILL.md plus references, scripts, and examples. Keep a Gotchas section that records failure modes, and over time that section becomes the highest signal-to-noise content in the skill.
Match the workflow to the task size
Small tasks do not need the full pipeline. For a variable rename or any diff you can describe in one sentence, just do it directly. The complex workflows exist for large tasks involving multiple files and steps. Running plan, review, and validation for a three-minute change wastes more time than it saves. If Claude drifts twice on the same issue, stop correcting within the session, roll back, and restart.
Make the practices team defaults
Best practices only change the team if the team runs Claude Code. Getting the whole engineering team into the workflow takes onboarding, a shared CLAUDE.md, and standardized hooks, and that adoption is the hardest part. Changes made by people who do not run Claude Code never pass through the guardrails, so the practices do not travel with the work. If you are the only one using Claude Code, every change that needs it funnels through you.
| Option | Who it fits | Downside |
|---|---|---|
| Individual habits | Developers with small, clear-scope changes | Practices stay personal because getting the whole team into the workflow is the hard part |
| Team defaults | Teams that commit to shared onboarding | Needs onboarding, a shared CLAUDE.md, and standardized hooks before it reaches everyone |
| Workflow frameworks | Large tasks with multiple files and steps | Slower than native Claude Code for changes you can describe in one sentence |
| Pilot engagement | CTOs who want one standard AI-assisted workflow | One team goes through the workflow change first and every other team waits on that result |
Where lighter setups win
For small, clear-scope changes, the lighter setup wins. Native Claude Code with a lean CLAUDE.md handles a variable rename or any diff you can describe in one sentence, and the extra minutes of planning are wasted on work direct execution finishes first. Structured workflow frameworks pay off only on large tasks spanning multiple files and steps. If your engineers mostly ship small, well-understood changes, keep these habits as individual practice and change nothing about the team. Discuss the pilot when the work spans teams and you want one standard way to run it, not when every change is small and local.