Getting the Most Out of Claude Code: My Best Practices
This guide captures the Claude Code workflow I distilled through iterative discussions with Claude while building my personal blog.
It combines official best practices with lessons from real-world pitfalls.
Rather than a static reference manual, it is a living record that evolves alongside my daily engineering practice.
How to Read This Guide
| Your Situation | Where to Focus |
|---|---|
| Just getting started with Claude Code | Sections 1 → 5 are plenty |
| Using it for a while and ready to go deeper | Focus on Section 4 (Skills) and Section 5 (Hooks) |
| Planning a larger, multi-step project | Sections 6 → 8 |
| Quick lookup for “which tool should I use?” | Jump straight to the decision tree in Section 2 |
1. Start with the Right Mental Model
Most developers treat Claude Code as “a smarter autocomplete tool” when they first pick it up.
That mental model is wrong—and it limits what you get out of it.
A better mental model: Claude Code is an AI collaborator living inside your terminal.
It does much more than generate snippets. It can:
- Read and reason about your entire repository’s structure and logic
- Write scripts, run shell commands, and inspect the results directly
- Debug failures and fix its own mistakes
- Pass context across tasks and coordinate multi-step work
Your relationship with it is not Q&A—it is “you define the goal, it executes, and you review the checkpoints.”
2. The Six Tools and How to Choose
Claude Code offers six extension mechanisms.
One foundational distinction drives every architectural decision:
CLAUDE.mdand Hooks are deterministic—they run every time, with no exceptions.
Skills and Subagents are probabilistic—Claude uses its own judgment to decide when to invoke them.
Understanding this boundary determines where every rule and workflow belongs.
| Tool | What It Is | How It Triggers | Determinism |
|---|---|---|---|
| CLAUDE.md | Persistent project memory | Loaded automatically on every startup | ✅ Deterministic |
| Skills | On-demand specialized playbooks | Auto-matched or /command |
⚡ Probabilistic |
| Hooks | Event-driven hard guardrails | Fired automatically on lifecycle events | ✅ Deterministic |
| Subagents | Dedicated workers with isolated context | Spawned by the main agent | ⚡ Probabilistic |
| MCP | Standardized connectors to external systems | Invoked as tools | ✅ Deterministic |
| Plugins | Packaging format for all of the above | Active once installed | - |
Tool Selection Decision Tree
When a new requirement comes up, walk through these questions in order:
1 | Does Claude need to remember this in every single session? |
Quick cheat sheet:
- Persistent memory →
CLAUDE.md - Mandatory enforcement → Hook
- Repeatable workflow → Skill
- Isolated context → Subagent
- External services → MCP
3. CLAUDE.md: Persistent Project Memory
Every time Claude Code starts, it reads CLAUDE.md at the repository root.
Think of it as a standing contract between you and Claude—write it once, and it applies to every session.
Three Layers of Content
A solid CLAUDE.md covers three layers. Skip any of them and you will find yourself correcting Claude at the start of every session:
Layer 1: The Map (shows Claude what the project looks like)
1 | Hexo blog using the Butterfly theme, deployed to GitHub Pages. |
Layer 2: Intent (explains why things are designed this way)
1 | All theme customizations must go into _config.butterfly.yml. |
Layer 3: Operations (tells Claude how to run common tasks)
1 | Local preview: hexo clean && hexo server |
Five Standard Sections
1 | # Project Name - Claude Guide |
Keep It Short: Under 200 Lines
Research shows that frontier LLMs start losing instruction-following accuracy uniformly past 150–200 instructions,
and Claude Code’s own system prompt already occupies roughly 50 slots.
That leaves you with around 100–150 effective slots.
Every line in CLAUDE.md competes with every other line for Claude’s attention.
❌ Anti-pattern: a 700-line CLAUDE.md with everything dumped into one file.
✅ Better approach: keep core rules ≤200 lines, move detailed docs into .claude/docs/, and only tell CLAUDE.md when to read each file.
Iterating on CLAUDE.md
CLAUDE.md is not written once and frozen—it evolves as you work.
When to add a rule:
Whenever Claude repeats the same class of mistake more than once, codify it.
How to write rules that stick:
❌ Prohibition only, with no alternative:
1 | Never call generate() directly |
The problem: when Claude hits a situation where generation is required, it gets stuck wondering what to call instead.
✅ Prohibition + concrete alternative:
1 | Do not call generate() directly; use generate_with_system() instead. |
When to move a rule into a Skill:
If a rule only applies in a narrow context (such as “when writing a blog post”),
don’t let it pollute the context budget of every unrelated task—move it into the relevant Skill.
How to tell if rules are actually working:
Watch Claude’s execution. When it ignores a rule,
check whether the wording is vague or buried under noisy instructions
before blindly adding more rules. Trimming CLAUDE.md often works better than expanding it.
Three Hierarchy Levels of CLAUDE.md
1 | ~/.claude/CLAUDE.md ← User-level: applies across all projects (personal preferences, style) |
Project-level overrides user-level, and subdirectory-level overrides project-level.
4. Skills: On-Demand Playbooks
Skills are the easiest Claude Code feature to over-engineer.
Many teams design a dozen Skills up front, only to end up with high maintenance overhead and mediocre results.
The right workflow: do the work first, then extract a Skill once repetition appears.
Official recommendation: complete the task without a Skill first,
notice what context you repeatedly supply and what mistakes you repeatedly correct,
then distill those lessons into a Skill.
Two Trigger Modes
1 | # Manual trigger: runs only when you invoke /publish |
About disable-model-invocation: true:
Any operation with side effects—publishing, deploying, pushing code, mutating databases—
must set this flag. You never want Claude deciding “looks ready to ship” and pushing on its own.
Writing Precise Descriptions
A Skill’s description serves two purposes: explaining to humans what it does, and telling Claude when to auto-load it.
❌ Vague description → fires on every file, including JSON and config files:
1 | description: "Check content quality" |
✅ Precise description → triggers only when editing blog posts:
1 | description: "Automatically validate Front Matter syntax and required fields |
❌ Vague description → fires on any code change:
1 | description: "Run tests" |
✅ Precise description → triggers only after backend edits:
1 | description: "Run unit tests and report results whenever Claude modifies |
Rule of thumb: specify the directory, file type, and triggering action in description.
Claude’s auto-matching becomes dramatically more accurate.
Basic SKILL.md Template
1 | --- |
Skills Directory Layout
1 | .claude/skills/ |
5. Hooks: Deterministic Quality Guardrails
Hooks are the most underused yet highest-leverage feature in Claude Code.
Skills are guidance that Claude can still overlook. Hooks are physical barriers that execute 100% of the time.
Empirical testing shows that writing “Never run
rm -rf“ inCLAUDE.mdachieves roughly 70% compliance.
Blocking it with a Hook achieves 100%. For safety rules, determinism beats probability every time.
How Hooks Work
Hooks fire at key points in Claude Code’s execution across 26 lifecycle events. The three you will use most often are:
- PreToolUse: before a tool runs (can block execution)
- PostToolUse: after a tool finishes (logging, notifications, verification)
- Notification: when Claude needs your attention
Hook scripts communicate via exit codes:
exit 0: allow execution to proceedexit 2: block the action; Claude receives stderr as feedback and tries another approach- Other non-zero codes: warn and continue while surfacing feedback
Hook or Skill?
| Scenario | Use Hook | Use Skill |
|---|---|---|
| Non-negotiable security rules | ✅ | ❌ |
| Mandatory tests before commit | ✅ | ❌ |
| Writing style checks | ❌ | ✅ |
| Defining a release workflow | ❌ | ✅ (optionally paired with a Hook guardrail) |
Essential Hook #1: Blocking Dangerous Commands
.claude/hooks/block-dangerous.sh:
1 |
|
Essential Hook #2: Mandatory Tests Before Commit
This Hook solves the “backend test context gets too noisy” problem cleanly:
the testing procedure lives in a Skill as reference documentation,
while the hard requirement—“tests must pass before committing”—is enforced by a Hook instead of relying on Claude’s memory.
.claude/settings.json:
1 | { |
Key principle: enforce checks at git commit (block-at-submit),
not on every individual file edit (block-at-write).
Let Claude finish implementing its plan, then validate everything at the final commit gate instead of interrupting its train of thought mid-edit.
6. Subagents: Isolated Specialists
When Subagents Actually Shine
- Running multiple independent tasks in parallel (zero shared dependencies)
- Offloading heavy search/read exploration that would otherwise bloat the main session’s context
- Using a faster, cheaper model for straightforward, repetitive subtasks
A Counterintuitive Pitfall
A common instinct is to create a dedicated subagent for every discipline:
a PythonTests subagent, a FrontendDev subagent, and so on.
That usually backfires and makes the workflow worse.
If you isolate testing inside a
PythonTestssubagent, the main agent loses visibility into the test suite
and can no longer reason holistically about the impact of its changes. It is forced to delegate just to learn how to verify its own code.
What looks like clean separation of concerns actually creates an information silo.
What works better:
- Put testing workflows into a Skill so Claude can read them when needed
- Let the main agent decide when to fan out work via the built-in
Task(...)tool - Don’t micromanage delegation—let Claude choose when isolation helps
When Custom Subagents Are Worth Building
- Work units are completely independent and need no main-session context
(e.g., converting 30 documentation pages in parallel where each page stands alone) - The subtask requires restricted tool permissions
(e.g., a read-only code review agent) - The task is large enough to justify dedicated configuration
Subagent Definition Format
1 | # .claude/agents/doc-processor.md |
7. MCP: Connecting to the Outside World
MCP (Model Context Protocol) is the standard interface for connecting Claude Code to external services.
When Do You Actually Need MCP?
Only add an MCP server when Claude Code genuinely needs to talk to an external system.
For most personal projects, the built-in tools (file read/write, shell execution, built-in WebSearch / WebFetch) are more than enough.
| Need | Matching MCP Server |
|---|---|
| Browser debugging & screenshots | Chrome DevTools MCP / Playwright MCP |
| Reading and writing Notion | Notion MCP |
| Querying databases | Database MCP (PostgreSQL, MySQL, etc.) |
| Looking up up-to-date library docs | Context7 MCP |
How to Configure MCP
Configure project-level MCP servers in .mcp.json at the repo root (user-level servers go in ~/.claude.json—never in .claude/settings.json):
1 | // .mcp.json |
You can also register it directly from the CLI: claude mcp add context7 -- npx -y @upstash/context7-mcp.
8. Plugins: Packaging Workflows Across Projects
Plugins bundle Skills, Hooks, and MCP servers into a single distributable package that you can install and share across repositories.
When do you need Plugins?
- You want to reuse the same setup across multiple projects
- You want to share your workflow with a team or the broader community
For a single personal project, skip Plugins for now. Master Skills and Hooks first.
9. Task Management: TASKS.md
Granularity: Specify Goals, Not Implementation
❌ Bad (prescribes implementation details):
1 | Use Python's requests library to scrape the page, parse HTML, extract body text, and save as .md |
✅ Good (specifies goal + constraints + acceptance criteria):
1 | Goal: Convert every page of the official Claude Code docs into a blog post |
Let Claude Code choose the language, libraries, and implementation strategy on its own.
TASKS.md Format
1 | # Task List |
How Completion Is Verified
- Regular tasks: Claude Code self-verifies against acceptance criteria and continues without interrupting you
- Milestone checkpoints: Claude pauses, presents deliverables, and waits for your sign-off before proceeding
Task Status Markers
| Marker | Meaning |
|---|---|
⏳ Pending |
Not started yet |
🔄 In Progress |
Currently being executed by Claude Code |
✅ Done |
Completed and verified |
❌ Failed |
Failed; needs attention |
⏸ Paused |
Waiting for human intervention |
10. State Management: A Two-Tier Layout
1 | state/ |
On startup, Claude Code reads only manifest.json (tiny).
It pulls in a specific taskN-output.md only when it needs deep context or has to backtrack.
Example manifest.json:
1 | { |
11. Automatic Backtracking: Self-Healing Pipelines
Three Backtracking Policies
1 | backtrack: full # Fully automatic; retry upstream until green (simple isolated tasks) |
Typical guided Flow
1 | Frontend (task3) runs and fails when calling the backend API |
Two Safety Guardrails
- Max backtrack depth: 2 levels. Crossing 2 levels means the root cause is unclear—pause and ask for human input.
- Post-fix drift report: after every automated fix, Claude Code must report which files changed, why, and whether any downstream tasks are affected.
12. Logging: Organized by Session
1 | logs/ |
Per-Task Log Template
1 | ## Task 2: Backend API Implementation |
13. Context Management: Act Before It Fills Up
Warning Signs It’s Time to Reset
Don’t wait until the context window hits capacity. Reset as soon as you notice these signals:
- Claude starts repeating completed work or contradicting earlier answers
- It begins ignoring rules clearly stated in
CLAUDE.md /contextreports usage above 60–70% (don’t wait for 90%+)- You just wrapped up one self-contained module and are moving on to the next
Three Reset Strategies
/compact (avoid when possible)
Automatically compresses conversation history, but the process is opaque and subtle requirements can silently disappear.
/clear + re-sync changes (lightweight reset)
Clear the session, then ask Claude to inspect the files shown in git status / git diff (you can also bind a custom /catchup Skill for one-command recovery).
Works well when the task is straightforward and changes are localized to a handful of files.
Document then reset (complex tasks)
Have Claude write the current plan and progress into a .md file,
run /clear, and resume from that file in the fresh session.
That is the exact reason we built TASKS.md + state/—manifest.json acts as a lightweight progress checkpoint,
so a new session only needs CLAUDE.md + TASKS.md + manifest.json to recover full state.
14. Complete Project Structure
1 | <repo-root>/ |
15. Build in Phases, Not All at Once
Phase 1: Set up on day one
CLAUDE.md(keep it under 200 lines).claude/settings.json+block-dangerous.shHookTASKS.md(create tasks as needed)
Phase 2: Add after real usage (only when repetition appears)
- Skills (distilled from corrections you keep making by hand)
- Detailed docs inside
.claude/docs/ - Pre-commit test Hook
Phase 3: Add when project complexity demands it
- Subagents (when you actually need parallel execution)
- MCP (when you need external service access)
- Plugins (when you want reuse across repositories)
16. Personal SOP
Before starting every new task:
- Check whether
CLAUDE.mdneeds any updates - Write the task in
TASKS.md(goal + constraints + acceptance criteria + backtrack policy) - Start
claudeand say:"Read TASKS.md and start from the first pending task." - Review outputs at each milestone checkpoint before approving the next phase
- After completion, review the execution log and record any recurring mistakes in
CLAUDE.md
Every time Claude makes a mistake:
- One-off slip → correct it inline and move on
- Recurring mistake → add it to the “Mistakes Claude Frequently Makes” section in
CLAUDE.md(prohibition + alternative) - Repeatable workflow gap → extract it into a Skill
17. Common Pitfalls
| Pitfall | Better Practice |
|---|---|
| Hand-writing scripts for Claude Code to run | Describe the goal and constraints; let Claude choose the implementation |
Thinking a longer CLAUDE.md is better |
Keep it ≤200 lines; offload details to docs/ via progressive disclosure |
| Designing every Skill up front | Work without them first; extract Skills only after repetition emerges |
Relying on CLAUDE.md for safety rules |
Enforce them with Hooks so compliance never depends on memory |
| Hands-off full autonomy from start to finish | Set milestones and review at critical checkpoints |
| Starting over from scratch after an error | Resume from the last checkpoint using state/ and logs |
| Creating a dedicated Subagent for every role | Use Skills + the built-in Task tool; let the main agent decide how to delegate |
| Waiting until context is full before resetting | Run /clear proactively on early signals and persist progress in manifest.json |
| Writing rules as bare “Never do X” | Always pair prohibitions with the expected alternative so Claude never gets stuck |
This guide is continuously updated with new findings from real-world usage.
Last updated: 2026-03-12




