🧠 Claude Code Mastery Playbook

Understanding How Claude Code Works Better Than 99% of Users

Based on Mark's "How Claude Code Actually Works" Video

🎯 What You'll Master

Extract every principle from Mark's video into actionable steps. Understand architecture, tooling, context management, and advanced techniques.

Sections
9
Time
2-3h
Checkpoints
40+
0%

1 Core Architecture & System Design

Goal: Understand foundational architecture and how components interact

beginner-friendly 15-20 min
🧩 The 5 Core Components

What makes Claude Code work:

  • CLI: Terminal interface you interact with
  • Session Manager: Handles conversation state & context
  • Tool Executor: Runs file ops, bash commands, searches
  • Permission Layer: Security gatekeeper (ask/allow/block)
  • Claude API: Intelligence brain orchestrating everything
πŸ’‘ Key Insight

Claude Code = Smart engineering + Open-source tools + Claude API. Anthropic didn't reinvent wheelsβ€”they connected existing tools to AI reasoning.

# View architecture in action
/context

# Shows:
# - System prompt overhead  
# - claude.md impact
# - Current token usage
πŸ“Š The Gather β†’ Act β†’ Verify Loop

Every Claude Code operation follows this pattern:

  1. GATHER: Reads files, searches code, explores structure
  2. ACT: Edits files, creates folders, runs bash commands
  3. VERIFY: Runs tests, checks outputs, loops if needed
Ask Claude Code Guide

@claude_code_guide Explain the gather-act-verify loop with a real coding example

2 Context Window Management (CRITICAL)

Goal: Master the most important constraintβ€”your 200k token "bucket"

must-master 30-35 min
πŸͺ£ The Bucket Metaphor

Your context window is a bucket:

  • Opus 4.5 = 200,000 token capacity (~150k words)
  • Every message, file read, tool result fills it
  • When full β†’ forced to compact (loses information)
  • Quality degrades after 40-50% full
🚨 The Quality Cliff

After 50% context usage, Claude gets lazier, makes more errors, forgets earlier decisions. Manage your bucket aggressively.

πŸ“Š What Fills the Bucket Fastest

Token consumption ranked (worst first):

  1. PDFs: 1.8M tokens for 50-page doc (instant death)
  2. Large file reads: 10k+ line files
  3. MCP servers: 10-50k tokens at session start
  4. Tool result spam: JSON-heavy database responses
  5. Bloated claude.md: 5-15k tokens every session
⚠️ Mark's PDF Example

Reading a 50-page economic report consumed 100% context in ONE operation. Solution: External API (Gemini) + markdown summary.

# Solution: Offload to Gemini 2.5 Flash

"Create a skill that:
1. Uses Gemini API (1M context window)
2. Reads large PDF
3. Converts to markdown (strips metadata)  
4. Returns summary only
5. Preserves my Claude context"
πŸ’‘ Context Preservation Strategies

1. External API Offloading

Use Gemini/GPT for large doc processing, return summary only

2. Sub-Agent Delegation

Virgin 200k context for exploration β†’ report back summary

3. Multi-Terminal Workflow

Terminal 1: Frontend | Terminal 2: Backend | Terminal 3: Testing

4. Slim claude.md

Keep under 2k tokens. Use as routing document, not knowledge dump.

Audit Your claude.md

Read my claude.md. Tell me: 1) Token count? 2) What's bloated? 3) How to compress under 2k tokens?

3 Tool Mastery: Read, Write, Edit, Search

Goal: Master how Claude uses file tools efficiently

intermediate 25-30 min
πŸ“– Read Tool: Surgical Loading

How to avoid nuking context:

🚨 Never Direct-Read Large Files

Reading a 50-page PDF = 1.8M tokens. Your bucket only holds 200k. Use external APIs instead.

# Bad: Direct PDF read ❌
# This nukes your context instantly

# Good: External API βœ…
"Create Python script:
- Uses Gemini 2.5 Flash API  
- Reads PDF
- Strips metadata
- Returns markdown summary"
πŸ” Glob + Grep: Smart Search

Glob: Pattern-based file finding

*.ts         # All TypeScript files
**/*.jsx     # All JSX in any folder
src/**/*.js  # All JS under src/

Grep (ripgrep): Fast codebase search

  • Runs searches in parallel (not sequential)
  • Memory-efficient (doesn't load full files)
  • Returns snippets, not entire files
πŸ’‘ Search Strategy

Claude searches in phases: 1) Find files with keyword, 2) Search within files, 3) Read only relevant sections. This preserves context.

4 Bash & System Control

Goal: Understand bash power and risks

high-risk 20-25 min
⚑ What Bash Enables
  • Install packages (npm, pip)
  • Run tests
  • Git operations
  • Spin up local servers
  • Docker builds
🚨 DANGER ZONE

Bash can nuke your laptop. Always use "Ask before edits" mode when starting out.

πŸ›‘οΈ Permission Modes

Three modes:

  1. Ask before edits: Claude requests approval (default)
  2. Bypass permissions (YOLO): Executes without asking
  3. Custom whitelist: Allow specific, block dangerous
πŸ’‘ Graduate to YOLO

Start with "Ask" mode to learn patterns. After 10-20 sessions, enable YOLO for speed.

5 Skills, MCPs & Sub-Agents

Goal: Master advanced customization

advanced 35-40 min
πŸ› οΈ Skills: On-Demand Workflows

Why skills over MCPs?

  • Just-in-time loading: Only when needed (saves context)
  • No startup overhead: MCPs load at session start
  • More predictable: Clearer execution paths
πŸ’‘ MCP β†’ Skill Migration

Mark went from 10 MCPs to 1-3. If you're not using an MCP constantly, make it a skill to save context.

πŸ€– Sub-Agents: Context Multiplication

Use cases:

  • Exploration: Virgin 200k context to explore codebase
  • Testing: Isolated test runs
  • Research: Deep-dive into docs
"Spin up sub-agent to explore backend:
1. All API endpoints
2. Database models  
3. Key dependencies
Report back summary only"

6 Claude.md Command Center

Goal: Master the persistent instruction file

leverage-point 25-30 min
πŸ“œ What is claude.md?

First thing Claude reads every session

🚨 Token Cost Warning

A 10k token claude.md = 5% context usage at startup. Keep it under 2k tokens.

πŸ”€ Routing Pattern

Use claude.md as index, not encyclopedia:

# In claude.md (routing):
"For LinkedIn posts, read linkedin-playbook.md"
"For API design, consult api-guidelines.md"
"Database changes require db-schema.md first"

# This keeps claude.md tiny
# While preserving access to deep knowledge

7 Session Management

Goal: Understand state, persistence, multi-terminal workflows

practical 20-25 min
πŸ’Ύ What Persists Between Sessions

Persists:

  • Files created/edited
  • Git commits
  • Installed packages
  • claude.md updates

Doesn't persist:

  • Context window state
  • File snapshots (in-memory)
  • Tool results
πŸ—‚οΈ Multi-Terminal Strategy

Why separate terminals?

  • Isolate context windows by task
  • Run background processes
  • Avoid compaction pollution
# 3-terminal setup:
Terminal 1: Frontend React work
Terminal 2: Backend API  
Terminal 3: Testing & deployment

# Each = independent 200k context

8 Security & Permissions

Goal: Balance safety with productivity

security 20-25 min
🚦 Permission Best Practices

Security rules:

  1. Never commit .env files
  2. Review random npm packages before installing
  3. Block system file deletion
  4. Require approval for production pushes
🚨 Production Warning

ALWAYS use "Ask" mode or custom whitelists in production. YOLO = solo dev only.

9 Advanced Workflows & Mastery

Goal: Synthesize everything into production-grade workflows

mastery 30-35 min
🎬 Real Example: Fix Login Bug

Full workflow:

# GATHER
- Glob: Find *.tsx files
- Grep: Search for "login"
- Read: LoginButton.tsx only

# ACT  
- Edit: Fix onClick typo (onClic β†’ onClick)

# VERIFY
- Run: npm test
- Bash: Start localhost:3000
- Verify: Click button (works!)
- Git: Commit fix

# Context impact: ~5,500 tokens (~3%)
πŸ’‘ Efficiency Win

Smart tool usage: Found issue with <10k tokens instead of reading entire 50k+ codebase.

πŸ“š Large Codebase Exploration

Problem: 50,000-line codebase to understand

Solution: Multi-phase with sub-agents

# Phase 1: Overview (main session)
"High-level folder structure and components?"

# Phase 2: Parallel exploration (sub-agents)
Terminal 2: Explore frontend/ β†’ report components
Terminal 3: Explore backend/ β†’ list API endpoints  
Terminal 4: Explore tests/ β†’ summarize coverage

# Phase 3: Synthesize (main session)
Each sub-agent reports SUMMARY only
Main session builds mental model
Create architecture.md for reference

# Context preserved: Exploration in sub-agents!
🧠 Plan β†’ Clear β†’ Execute Pattern

For complex builds exceeding context:

# Session 1: Planning
"Use Plan Mode to design auth system:
- Email/password login
- OAuth (Google, GitHub)  
- Password reset
- Session management
Create detailed plan"

# After plan complete:
/clear

# Session 2: Execution (fresh context)
"Execute the auth plan in plan.md"
πŸ’‘ Context Reset

Benefits of exploration WITHOUT context cost during execution. Start building with fresh bucket.

πŸ“ Session-End Protocol

Before ending session:

# Checklist:
1. Update claude.md with learnings
2. Create playbook.md for complex workflows  
3. Commit key files to git
4. Update TODO.md with next steps

# Example prompt:
"Before ending, create summary:
1. What we accomplished
2. Key decisions made
3. What to update in claude.md
4. Next steps"

πŸ“š Resources & Next Steps

Essential Links:

🎯 Next Steps
  1. Pick small project to practice
  2. Create optimized claude.md
  3. Build first skill for repetitive task
  4. Experiment with multi-terminal workflows
  5. Join community and share what you build