Best Practices for Claude Code
Patterns that consistently produce better results — from how you phrase prompts and manage context, to parallelising work and avoiding the traps that slow most people down.
The one constraint that shapes everything
Claude's context window holds your entire conversation — every message, every file it read, every command output. It fills up fast. A single debugging session can consume tens of thousands of tokens, and performance degrades as it fills. Claude may start overlooking earlier instructions or making more mistakes.
Almost every best practice in this lesson flows from this one constraint: manage context carefully, keep prompts focused, and reset often.
1. Always give Claude a way to verify its work
Without verification criteria, Claude produces something that looks right but may not work. You become the only feedback loop, and every mistake needs your attention.
2. Explore first, then plan, then code
Letting Claude jump straight to coding risks solving the wrong problem. Use plan mode to separate research from implementation.
Claude reads files and answers questions without making any changes. Understand the codebase before touching it.
Ask Claude for a detailed implementation plan. Press Ctrl+G to open and edit the plan before Claude starts coding.
Switch out of plan mode. Claude codes against the plan and verifies with tests.
Ask Claude to commit with a descriptive message and open a PR.
3. Write specific prompts
The more precise your instructions, the fewer corrections you need. Claude can infer intent but it can't read your mind. Reference files, mention constraints, and point to examples.
You can also provide rich input: use @filename to reference files directly, paste screenshots by copying and dropping into the prompt, pipe data with cat error.log | claude, or paste a URL for Claude to fetch documentation.
4. Write an effective CLAUDE.md
CLAUDE.md is loaded at the start of every session. Include bash commands, code style rules, and workflow conventions that differ from sensible defaults. Run /init to generate a starter file from your current project.
# Code style - Use ES modules (import/export), not CommonJS (require) - Destructure imports when possible # Workflow - Always typecheck after a series of code changes - Run single tests, not the full suite, for speed # Repo etiquette - Branch names: feat/<ticket> fix/<ticket> - PR titles must reference a ticket number
For each line ask: "Would removing this cause Claude to make a mistake?" If not, cut it. A bloated CLAUDE.md causes Claude to miss important rules buried in the noise.
| ✅ Include | ❌ Skip |
|---|---|
| Bash commands Claude can't guess | Things Claude can figure out from code |
| Code style that differs from defaults | Standard language conventions |
| Test runner preferences | Detailed API docs — link instead |
| Branch naming & PR conventions | Information that changes frequently |
| Non-obvious architectural decisions | Self-evident rules like 'write clean code' |
CLAUDE.local.md for personal overrides — gitignore it so it stays private.5. Manage context aggressively
Long sessions accumulate irrelevant file contents, failed attempts, and detours. This degrades performance. A few commands keep the context clean:
/clear and start fresh with a better prompt that incorporates what you learned.6. Use subagents for investigation
When Claude needs to explore a lot of files to answer a question, those reads consume your context. Subagents run in a separate context window, explore, and then report back a summary — leaving your main conversation clean.
You can also use subagents for verification after implementation: use a subagent to review this code for edge cases. A fresh context means no bias toward code it just wrote.
7. Run parallel sessions to multiply output
Claude Code scales horizontally. Once you're comfortable with one session, run multiple in parallel for faster delivery or independent review.
A useful pattern is Writer / Reviewer: one session implements, another reviews with fresh context. Claude won't be biased toward code it wrote.
8. Automate with non-interactive mode
Use claude -p "prompt" in CI pipelines, pre-commit hooks, or scripts to run Claude without a session. The --output-format flag controls how output is structured for programmatic use.
# One-off query
claude -p "Explain what this project does"
# Structured output for scripts
claude -p "List all API endpoints" --output-format json
# Batch file migration
for file in $(cat files.txt); do
claude -p "Migrate $file from React to Vue. Return OK or FAIL." \
--allowedTools "Edit,Bash(git commit *)"
done
# Run autonomously with safety checks
claude --permission-mode auto -p "fix all lint errors"--allowedTools tightly in batch scripts — it restricts what Claude can do when running unattended. Test on 2-3 files before running at scale.9. Configure permissions to reduce interruptions
By default Claude asks before every file write or command. After the tenth click-through you stop reviewing. Three tools reduce this:
10. Avoid common failure patterns
Quick Reference
| Practice | Key action |
|---|---|
| Provide verification | Add test cases or a script to every implementation request |
| Explore before coding | Switch to plan mode first; press Ctrl+G to edit the plan |
| Write specific prompts | Name files, describe symptoms, define what 'done' looks like |
| Maintain CLAUDE.md | Run /init to generate; prune aggressively; commit to git |
| Reset context between tasks | /clear after each unrelated workstream |
| Summarise long sessions | /compact or /compact <focus instructions> |
| Investigate without polluting | Use subagents — they run in a separate context window |
| Reduce permission prompts | --permission-mode auto or /permissions allowlists |
| Parallelize work | Worktrees, Desktop app, or Claude Code on the web |
| Recover from mistakes | Esc + Esc to open /rewind — restore code and/or conversation |
What's Next
You've completed the Claude Code module. The next module covers Claude Skills — reusable instruction files that give Claude a consistent way of working.