hippo: This post is part of the Claude Code Official Docs Breakdown series. Treat Best Practices less like required reading and more like a field reference—skim it once up front, then come back to it whenever you hit friction.


1. The Core Constraint Behind Every Best Practice

Claude Code is an agentic coding environment. Unlike a chat assistant, it reads files, runs commands, edits code, and solves problems autonomously—whether you are watching or away from the keyboard. Your role shifts from writing code line by line to specifying the outcome you want and steering Claude as it executes.

One constraint underlies every best practice:

The context window is your most valuable resource. Every turn, file read, and command output consumes tokens, and performance degrades as the window fills up.

The context window holds your entire conversation history—every message, every file Claude has opened, and every command output. A single codebase investigation can burn tens of thousands of tokens. As the window approaches capacity, Claude starts forgetting earlier instructions and making more mistakes. Nearly every best practice reduces to a single rule: spend your context window deliberately.


2. Give Claude a Way to Verify Its Work + Explore Before Coding

2.1 Verification-Driven Development

Claude’s output quality jumps sharply when it can verify its own work—by running tests, comparing screenshots, or checking linter output. Without an automated feedback loop, you become the only verifier and have to catch every bug by hand.

Strategy Before After
Provide verification criteria “Implement a function to validate emails” “Write a validateEmail function. Tests: test@example.com returns true, invalid returns false. Run the tests after implementing.”
Verify UI visually “Make the dashboard look better” “[Paste design mockup] Implement this design. Take a screenshot when done, compare it against the mockup, list any differences, and fix them.”
Fix the root cause “The build is failing” “The build fails with: [paste error]. Fix it and verify the build passes—address the root cause rather than suppressing the error.”

Choosing a verification method:

Method Best For Examples
Test suite Feature work, bug fixes npm test, pytest
Linter Code style and lint rules eslint, prettier --check
Type checker Typed languages tsc --noEmit
Screenshot diff UI work Automated screenshots compared against mockups
Shell commands General checks grep, diff, curl

2.2 The Four-Phase Workflow

Asking Claude to jump straight into writing code often produces code that solves the wrong problem. The official docs recommend four phases:

Phase Action Details
1. Explore Let Claude inspect the codebase first Read relevant files and understand existing patterns
2. Plan Agree on an implementation plan Use Plan Mode (Shift+Tab) to separate planning from execution
3. Implement Write code against the plan Execute the agreed changes
4. Verify Run checks and tests Confirm the changes behave as expected

hippo: My go-to habit is “explain the plan first”—have Claude walk through its approach and wait for my sign-off before editing a single file. It eliminates a huge amount of rework.


3. Prompting Techniques and Providing Context

Claude can infer intent, but it cannot read your mind. Pointing to exact files, naming constraints, and referencing existing patterns makes a night-and-day difference.

3.1 Before-and-After Prompt Examples

Strategy Before After
Scope the task “Add tests for foo.py” “Write tests for foo.py covering the logged-out user edge case, without using mocks.”
Point to sources “Why is this API so weird?” “Check the git history of ExecutionFactory and summarize how its API evolved.”
Reference existing patterns “Add a calendar widget” “Look at how HotDogWidget.php is implemented on the homepage and build the calendar widget following that pattern.”
Describe the symptom “Fix the login bug” “Login fails after session timeout. Inspect the token refresh logic in src/auth/, write a failing test first, then fix it.”

3.2 Ways to Supply Rich Context

Method How It Helps Example
@ file references Tell Claude to read specific files @src/auth/login.py
Pasted images Share mockups or error screenshots directly Copy/paste or drag-and-drop into the terminal
URLs Pull in docs and API references Allow domains via /permissions
Piped input Feed file or log contents straight in cat error.log | claude
Let Claude fetch it Use Bash or MCP tools directly “Use Bash to fetch xxx”

When vague prompts actually help: If you want to see how Claude understands a problem before steering it, open-ended questions like “What would you improve in this file?” often surface issues you hadn’t considered.


4. Configure Your Environment

A handful of configuration files make Claude Code more effective across every session. This is the highest-leverage time you can invest.

4.1 CLAUDE.md: Persistent Project Context

CLAUDE.md loads automatically at the start of every session and tells Claude how your project works. The core rule: include only what Claude cannot infer from the code itself.

1
2
3
4
5
6
7
# Code style
- Use ES modules (import/export) syntax, not CommonJS (require)
- Destructure imports when possible (eg. import { foo } from 'bar')

# Workflow
- Be sure to typecheck when you're done making a series of code changes
- Prefer running single tests, and not the whole test suite, for performance

What to include vs. leave out:

Include Leave Out
Bash commands Claude cannot guess Anything obvious from reading the code
Code style rules that differ from defaults Standard language conventions
Test instructions and preferred test runners Detailed API docs (link to them instead)
Repo etiquette (branch naming, PR conventions) Information that changes frequently
Dev environment quirks (required env vars) File-by-file descriptions of the codebase

hippo: For every line in CLAUDE.md, ask: “Would Claude make a mistake if I deleted this?” If not, cut it. A bloated CLAUDE.md dilutes the rules that actually matter. I once stuffed a full page of project notes into mine and Claude actually got worse at following instructions.

File locations and imports:

Location Scope
~/.claude/CLAUDE.md User-level, applied across all sessions
./CLAUDE.md Project-level, committed to git and shared with the team
Parent / child directories Monorepo support; child files load on demand

Import additional files with @path/to/import:

1
2
3
See @README.md for project overview and @package.json for available npm commands.
- Git workflow: @docs/git-instructions.md
- Personal overrides: @~/.claude/my-project-instructions.md

4.2 Skills: On-Demand Knowledge Modules

Skills complement CLAUDE.md: CLAUDE.md loads on every session, while Skills load on demand without bloating context. Use them for domain knowledge or repeatable workflows you only need occasionally.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# .claude/skills/fix-issue/SKILL.md
---
name: fix-issue
description: Fix a GitHub issue
disable-model-invocation: true
---
Analyze and fix the GitHub issue: $ARGUMENTS.
1. Use `gh issue view` to get the issue details
2. Understand the problem described in the issue
3. Search the codebase for relevant files
4. Implement the necessary changes
5. Write and run tests to verify the fix
6. Create a descriptive commit message
7. Push and create a PR
Skill Front Matter Field Purpose
name Skill name
description Tells Claude when to invoke the skill
disable-model-invocation Set to true to prevent automatic model invocation

4.3 Subagents: Isolated Context Investigators

Subagents run in their own context window, making them ideal for broad codebase investigations that would otherwise pollute your main conversation. They are one of the highest-impact tools for managing context.

1
2
3
4
5
6
7
8
9
10
11
12
13
# .claude/agents/security-reviewer.md
---
name: security-reviewer
description: Reviews code for security vulnerabilities
tools: Read, Grep, Glob, Bash
model: opus
---
You are a senior security engineer. Review code for:
- Injection vulnerabilities (SQL, XSS, command injection)
- Authentication and authorization flaws
- Secrets or credentials in code
- Insecure data handling
Provide specific line references and suggested fixes.
Subagent Front Matter Field Purpose
name Agent name
description Describes when to use the agent
tools List of allowed tools
model Target model (e.g., opus)

4.4 Hooks, MCP Servers, Plugins, and Permissions

Hooks run shell scripts automatically on lifecycle events—such as capturing a verification screenshot after every file edit. Configure them in .claude/settings.json and inspect active hooks with /hooks.

MCP servers (Model Context Protocol, a standard protocol for connecting AI models to external tools) let Claude talk to third-party APIs, databases, and other external systems.

Plugins bundle ready-to-use capabilities out of the box.

Three permission modes:

Mode How It Works Best For
Auto mode A classifier reviews commands and blocks only risky ones Tasks where you trust the direction and want fewer prompts
Permission allowlist Explicitly allowlist specific commands/tools Safe routine actions like npm run lint, git commit
Sandbox OS-level process and filesystem isolation High-risk environments

Quick bootstrap: Run /init to have Claude analyze your repository and draft a starter CLAUDE.md—the fastest way to set up a new project.

4.5 CLI Tools

CLI tools are the most context-efficient way to interact with external services:

1
2
3
4
5
# GitHub integration
brew install gh # Claude knows how to use gh to create issues, open PRs, and read comments

# Claude can also learn unfamiliar tools on its own
# "Use 'foo-cli-tool --help' to learn about it, then use it to solve A, B, C."

5. Session Management and Scaling with Automation

5.1 Manage Context Actively

Action Effect
/clear Fully reset the context window between unrelated tasks
/compact <instructions> Guide compaction explicitly, e.g., /compact Focus on the API changes
Esc + Esc → Summarize from here Summarize a slice of the conversation while keeping earlier context
/btw Ask a quick side question without adding the exchange to conversation history
Auto-compaction Automatically summarizes key context when approaching the token limit

Rule of thumb: If you have corrected Claude more than twice on the same issue, the context is already polluted with failed attempts. Run /clear and start fresh with a sharper prompt that incorporates what you learned.

Customize compaction behavior by adding a line to CLAUDE.md:

1
When compacting, always preserve the full list of modified files and any test commands

5.2 Offload Codebase Investigation to Subagents

Exploring a codebase pulls dozens of files into context. Hand that work to a Subagent instead:

1
2
Use subagents to investigate how our authentication system handles token
refresh, and whether we have any existing OAuth utilities I should reuse.

The Subagent completes the investigation in its own context window and returns only a concise summary—keeping your main session clean.

5.3 Non-Interactive Mode and Parallel Sessions

1
2
3
4
5
6
7
8
9
10
11
12
# One-off query
cat error.log | claude -p "Explain these errors"

# Structured output for scripting
claude -p "List all API endpoints" --output-format json

# Batch fixes in auto permission mode
claude --permission-mode auto -p "fix all lint errors"

# Resume a conversation
claude --continue # Resume the most recent conversation
claude --resume # Pick from recent conversations

Parallel session patterns:

Approach How It Works
Desktop app Multiple local sessions, each backed by its own git worktree
Web app Runs inside isolated VMs
Writer/Reviewer One session writes code while a second reviews it with fresh, unbiased context
Agent teams Multiple sessions coordinate automatically via shared tasks and a team lead

hippo: I use the Writer/Reviewer pattern when writing blog posts—one session drafts the article and another reviews and scores it. Without the author bias of having written the draft, the review session gives much more honest feedback.


6. Avoiding Failure Modes & Hippo’s Pitfalls

6.1 Five Common Failure Modes

Failure Mode Symptom Fix
Kitchen-sink session Unrelated tasks piled into one session, filling context with noise Run /clear between unrelated tasks
Correction loop Still wrong after two corrections; context is poisoned by failed approaches Run /clear immediately after two failed corrections and rewrite the initial prompt
Bloated CLAUDE.md Too many rules, so Claude ignores half of them Prune ruthlessly; delete anything Claude already gets right
Trust-then-verify gap Output looks plausible but breaks on edge cases Always attach verification (tests, scripts, screenshots)
Unbounded exploration Open-ended “investigate this” reads hundreds of files Narrow the scope or delegate to a Subagent

6.2 Hippo’s Real-World Pitfalls

hippo: Every pitfall below actually happened to me.

Pitfall 1: Asking Claude to “optimize performance across the whole project”

It touched dozens of files that didn’t need changes, and several “optimizations” introduced new bugs.

The fix—optimize one function at a time with explicit success criteria:

1
2
Optimize only the debounce function in src/utils/debounce.ts.
Success criteria: reduce execution time by at least 50%, and all existing tests must still pass.

Pitfall 2: Repeatedly correcting Claude in the same session

Claude makes a mistake → I correct it → it makes another mistake → I correct it again → the context fills with failed attempts → Claude gets progressively more confused.

The fix—after two failed corrections, run /clear immediately and restart with a clean prompt that includes what you learned.

Pitfall 3: Stuffing too much into CLAUDE.md

I put over 200 lines of project documentation into CLAUDE.md, and Claude actually followed instructions less reliably—the signal got drowned out by the noise.

The fix—keep it to 50–100 lines containing only what Claude cannot guess. Reference longer docs with @ imports instead of inlining them.

6.3 My Most-Used Habits

Habit Why It Works
“Explain the plan first” Have Claude outline the approach and get sign-off before editing—prevents wasted work
“Act as a code reviewer” Asking Claude to review its own diff regularly catches issues missed on the first pass
“Why did you write it this way?” Surfaces Claude’s reasoning and often prompts it to spot flaws itself
Subagent investigations Keeps large-scale codebase exploration out of the main context window
Quick questions via /btw Answers minor side questions without cluttering conversation history

Summary

Every best practice revolves around one fact: the context window is your most precious resource. Around that constraint:

  1. Provide verification: Give Claude a way to check its own work—tests, linters, or screenshots.
  2. Work in phases: Explore → Plan → Implement → Verify.
  3. Configure your environment: Keep CLAUDE.md lean, load Skills on demand, automate with Hooks, and isolate investigations in Subagents.
  4. Manage sessions actively: Use /clear frequently, and control token growth with /compact and /btw.
  5. Watch for failure modes: Kitchen-sink sessions, correction loops, and bloated configs—spot them early and reset.

Series Navigation


Based on the official Best Practices for Claude Code documentation.

Last updated: 2026-03-31