Mastering Claude Code: A Complete Guide
Claude Code is more than just an AI editor integration, it’s a complete development environment that learns your patterns, automates your workflows, and scales with your team. But unlocking its full power requires understanding a few key concepts.
Smart Prompting: Build a Learning Path
Most developers start with generic prompts. Instead, use structured, layered prompts that build on each other.
Start with an overview to establish context:
Analyze this codebase and give me a structured overview:
- What type of application is this?
- Main languages and frameworks
- Key directories and their purposes
- Important configuration files
Then proceed with layered prompts each one building on the previous answer:
# Layer 1: Architecture
Explain the main architectural patterns and how different layers interact.
# Layer 2: Data & Flow
Identify key data models and their relationships. How does data flow between modules?
# Layer 3: Specific Systems
Walk me through authentication. Show me the specific files and functions involved.
This creates a strong learning path, where Claude develops deeper understanding with each question. Each response gives it more context to work with.
Context Management: CLAUDE.md is Your Contract
Context gets reset across conversations but you can preserve it.
CLAUDE.md is a single file that defines how Claude should work on your project. Use it to encode:
- Build and test commands
- Coding conventions and style
- Project-specific architecture patterns
- Communication preferences
Claude supports a three-tier hierarchy:
- Global
~/.claude/CLAUDE.md- Your universal rules (TypeScript, testing standards, security mindset) - Project
.claude/CLAUDE.md- Team conventions (shared patterns, frameworks) - Local
.claude/CLAUDE.md- Personal customizations (not committed)
Pro tip: Keep it short. Use @ syntax to reference specific files instead of copying details:
# CLAUDE.md - Development Contract
## Core
- Build: `npm run build`
- Test: `npm test`
- Use TypeScript for new code
## Key Files
- @src/utils/database.ts - Database abstraction
- @tests/fixtures/ - Test data
- @docs/architecture.md - System design
## Conventions
- Functional programming preferred
- Error handling in all async functions
- Add security comments for auth/validation
If Claude breaks a convention, use # to add a quick correction that sticks to the context.
Reference Files with @
Use @filename to tell Claude, “You should already know about this file.” It goes into persistent context so Claude doesn’t repeatedly ask for content it should remember.
Best for frequently referenced files:
- Database schemas
- API client code
- Utility functions
- Architectural docs
Conversation Control: Planning, Thinking, and Flow
Planning Mode vs. Thinking Mode
Two different modes for different jobs:
Planning Mode → Big-picture coordination
- Good for: Multi-file features, refactors, migrations
- Behavior: Reads more files, creates a step-by-step plan, waits for approval
- Output: Implementation plan, affected files, rationale, risk assessment
- Use when: You need a design review before committing to changes
- How to trigger: Toggle in the editor (typically
Shift+Tabor via UI button), or start your prompt with “Plan:”
Thinking Modes → Deeper reasoning on focused problems
- Think - Light analysis
- Think more - Examine alternatives
- Think a lot - Thorough multi-angle analysis
- Think longer - Extended reasoning for tricky problems
- Ultrathink - Maximum depth (algorithms, design trade-offs)
- Good for: Debugging, performance tuning, nuanced decisions
- Use when: You’re stuck on a specific problem
- How to trigger: Start your prompt with the keyword, e.g.:
Think: Why does this debounce fail in Safari?Think more: Compare these two algorithms for memory usageThink a lot: Analyze this race condition across all code pathsUltrathink: Design the optimal data structure for this use case
Examples in practice:
# Planning Mode (via toggle or "Plan:" prefix)
Plan: Extract a shared button component and migrate both header
and footer to use it. Show affected files and implementation order.
# Thinking Mode (via keyword prefix)
Ultrathink: Our debounce fails in Safari but not Chrome.
Consider event timing, requestAnimationFrame behavior, and
Safari's specific JS event handling quirks. Why?
Flow Control: /clear, /compact, Escape
Keep conversations on track:
/clear- Reset completely. Start fresh on a new topic./compact- Summarize a 50-message conversation into essential decisions. Useful after long implementation sessions.Escape- Interrupt generation. Press twice to go back to a previous message. Use when conversation drifts.
Automation: Commands and Sub-Agents
Stop repeating the same prompts.
Custom Commands
Create .claude/<command-name>.md with a template. Use $ARGUMENTS for dynamic inputs:
# generate_tests.md
Write comprehensive unit tests for: $ARGUMENTS
**Requirements:**
- Use pytest
- Create `<module>_test.py` in tests/
- Cover happy path, edge cases, errors
- Include assertions
After writing, print: "Finished tests for $ARGUMENTS"
Now run: claude /generate_tests src/api.py - and Claude handles the details.
Name commands by outcome: /stabilize-tests, /document-api, /audit-security. Not /run-formatter.
Sub-Agents: Specialized Assistants
Sub-agents are focused AI helpers with limited context and specific tools. Create one with metadata:
---
name: code-reviewer
description: Expert code review. Use after writing or modifying code.
tools: Read, Grep, Bash
---
You are a senior code reviewer. Your job is to:
1. Check for bugs, edge cases, and security issues
2. Verify alignment with project conventions
3. Suggest improvements with reasoning
4. Point out potential performance problems
Call a sub-agent explicitly in your prompt, or let Claude choose based on task type. They don’t inherit the main conversation context, so they stay focused.
Integration: MCP, GitHub, and SDK
MCP (Model Context Protocol)
Connect Claude to external tools and datasources, databases, APIs, Figma, Jira, etc.
# Local tool (runs on your machine)
claude mcp add github -- npx mcp-github
# Remote SSE server
claude mcp add --transport sse linear https://mcp.linear.app/sse
# HTTP API
claude mcp add --transport http notion https://mcp.notion.com/mcp \
--header "Authorization: Bearer TOKEN"
Once connected, Claude can query, fetch, and update external systems natively.
GitHub Integration
Install the Claude Code GitHub App:
claude /install-github-app
Now Claude can:
- Respond to
@claudementions in issues and PRs - Post automatic reviews on pull requests
- Suggest diffs right in the conversation
SDK: Claude Code in Your Workflow
Embed Claude into scripts, CI/CD, git hooks, or anywhere:
from claude_code_sdk import query, ClaudeCodeOptions
options = ClaudeCodeOptions(
allowed_tools=["Edit", "Bash"],
permission_mode="acceptEdits" # Auto-apply changes
)
async for msg in query(
prompt="Find and fix duplicate SQL queries",
options=options
):
if msg.type == "result":
print(msg.result)
Use cases:
- Pre-commit hooks to catch issues
- CI/CD jobs to review PRs
- Local scripts to check for architectural smells
- Automated documentation generation
Best Practices: Work Smarter
Keep CLAUDE.md Short and Effective
Use a two-tier structure:
Tier 1 (Contract): 10–20 lines
- Non-negotiables: build commands, error-handling norms, architectural invariants
Tier 2 (Pointers): @ references to detailed docs
- Only link what Claude needs frequently
- Reduces token burn, improves consistency
Every line should reduce future errors or tokens. If it doesn’t, cut it.
Scope Sessions by Phase
- Planning: Broad, tool-heavy. Make decisions. End with a compact summary.
- Implementation: Code-heavy, minimal. Include only changed files and the plan.
- Review: Short, artifact-centric. Read diffs and test results. Don’t carry planning context.
Small context = faster responses.
Monitor Costs with ccusage
ccusage monthly # Overview
ccusage session # Per-session breakdown
ccusage blocks # Five-hour clusters to spot rate spikes
Look for outlier sessions with high tokens but low output. Usually means: narrow scope, compact earlier, or restart at milestones.
Hooks: Automate Beyond Prompts
Define operations before or after Claude uses a tool. Examples:
- Auto-format code after edits (
PostToolUsewith Prettier) - Run tests when files change
- Lint and report issues
- Block access to sensitive files
Configure in .claude/settings.json:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": ".claude/hooks/format.sh"
}
]
}
]
}
}
The Workflow
- Encode your standards in
CLAUDE.md - Reference key files with
@to build persistent context - Use structured prompts - overview, then layered deep dives
- Automate repetitive tasks with commands and sub-agents
- Connect external systems via MCP
- Monitor costs regularly
- Scope sessions by phase to keep context tight
Claude Code becomes smarter and more efficient the more you invest in setup. The payoff: from “generic coding assistant” to “team member who knows your codebase, your standards, and your preferences.”
Ready to level up? Start with a solid CLAUDE.md, try a structured prompt on your largest codebase, and watch how much faster you move. 🚀