Back to all articles
19 min read

Advanced Claude Code Techniques: Master Pro-Level Patterns

By Dorian Laurenceau

Updated

šŸ“… Last reviewed: April 24, 2026. Updated with April 2026 findings and community feedback.

Advanced Claude Code Techniques

You've mastered the basics. Now it's time to unlock Claude Code's full potential with techniques used by the most productive developers. This guide covers context engineering, advanced prompting patterns, cost optimization, and the strategic patterns that separate power users from beginners.


1. Context Engineering: The Meta-Skill

Context is everything in Claude Code. The quality of your output is directly proportional to the quality of your context. This section teaches you to engineer context like a pro.

Understanding the Context Window

Claude Code has a 200K token context window. Think of it as RAM for your AI assistant:

UsageZoneVisualAction
0-50%Green🟢Work normally
50-75%Yellow🟔Consider /compact soon
75-90%RedšŸ”“Use /compact now
90%+Critical⚫Session may crash-act immediately

What Consumes Context?

Not all actions are equal. Here's the real cost breakdown:

Context Consumption Guide

ActionToken CostOptimization
Reading a small file (100 lines)~500 tokens (Low)Target specific line ranges
Reading a large file (2000+ lines)~5K+ tokens (High)Use @file:45-60 syntax
Running terminal commands~1K tokens (Medium)Limit output verbosity
Multi-file search (grep)~3K+ tokens (High)Be specific with patterns
Long conversation (20+ messages)AccumulatesUse /compact at 50%
MCP tool calls~2K per serverLoad only needed servers

← Scroll horizontally →

Interactive Context Visualizer

Use this interactive tool to visualize how different activities consume your 200K token context window:

Context Depletion Symptoms

Learn to recognize when context is running low:

Warning Signs of Context Exhaustion

🟔 Warning: Shorter Responses

Claude's responses become noticeably shorter than usual, even for complex questions.

šŸ’” This is your first warning. Continue with caution and check /status.

1/4
Quick Check

You're at 65% context and Claude starts giving shorter responses. What's the best action?

The Compact Command Deep Dive

When you run /compact, Claude:

  1. →Summarizes the conversation so far
  2. →Preserves essential info (project structure, current task, recent decisions)
  3. →Discards verbose details (old diffs, lengthy outputs, resolved discussions)
  4. →Frees typically 40-60% of context
Click to expand

A recurring observation from senior engineers shipping with Claude Code: context engineering is not "prompt engineering in disguise". Threads on r/ClaudeAI and r/ChatGPTCoding keep coming back to the same finding — the quality of a multi-hour coding session is decided in the first 2 000 tokens. What you put in the system prompt, what lives in CLAUDE.md, which files you load explicitly vs. let the model discover via Grep, and how you scope the task all compound. Anthropic's own prompt engineering documentation hints at this, but the real playbooks tend to emerge from repo authors shipping under deadline.

Where the community correctly pushes back on hype: no amount of clever prompting rescues a bad retrieval strategy. If the model cannot see the file that contains the invariant, it will invent one. Practitioners in r/LocalLLaMA and r/MachineLearning have documented this for years — the honest framing is that Claude Code is a retrieval system with a language model attached, not the other way around. Research like "Lost in the Middle" formalizes what every long-context user already knows: placement matters, and a 200k window does not mean 200k tokens of usable attention.

The pragmatic rule: treat context like a working set, not a history. Before each major phase — design, implementation, review — prune aggressively, reload only what matters, and commit a short written state (e.g. STATE.md) that you can reconstruct the session from. This is not theater; it is what keeps long sessions from decaying into hallucination.


2. Session vs. Persistent Memory

Claude Code has two distinct memory systems. Understanding the difference is crucial:

Memory Systems Comparison

AspectSession MemoryPersistent Memory
ScopeCurrent conversation onlyAcross all sessions
Managed by/compact, /clearCLAUDE.md, Serena MCP
Lost whenSession ends or /clearExplicitly deleted
Use caseImmediate working contextLong-term decisions
StorageIn-memory (ephemeral)File system (permanent)

← Scroll horizontally →

The CLAUDE.md Power Pattern

CLAUDE.md is your persistent project memory. Claude reads it automatically on every launch.

# CLAUDE.md

## Project: E-Commerce Platform
Tech stack: Next.js 14, TypeScript, Prisma, PostgreSQL

## Decisions Made
- JWT auth (not sessions) for horizontal scaling
- Server Components by default, Client only when needed
- All API routes return Result<T, AppError> pattern

## Coding Standards
- No `any` types - use `unknown` with type guards
- All functions must have JSDoc comments
- Tests required for all business logic

## Current Sprint Focus
- User authentication system (70% complete)
- Next: Implement refresh token rotation

Build Your Perfect CLAUDE.md

Use this interactive editor to create a customized CLAUDE.md for your project. Choose from templates and customize to your needs:

Session Handoff Pattern

When ending a session, create a handoff document to maintain continuity:

# Session Handoff - 2025-01-15 18:00

## Accomplished
- Implemented JWT access token generation
- Added /auth/login endpoint
- Created User model with Prisma

## Current State
- Login works for valid credentials
- Refresh tokens: NOT YET IMPLEMENTED
- Tests: 80% coverage on auth module

## Next Session
1. Implement refresh token generation
2. Add token rotation on refresh
3. Write integration tests for full flow

## Key Files
- src/auth/tokens.ts (main logic)
- src/routes/auth.ts (endpoints)
- prisma/schema.prisma (User model)
Quick Check

Where should you store architectural decisions that need to persist across all sessions?


3. XML-Structured Prompts

For complex requests, XML tags provide semantic organization that helps Claude distinguish between instructions, context, and constraints.

Basic Structure

<instruction>
  Your main task description here
</instruction>

<context>
  Background information, project details
</context>

<constraints>
  - Limitation 1
  - Requirement 2
</constraints>

<output>
  Expected format or structure
</output>

When to Use XML Tags

XML Tags Decision Guide

ScenarioUse XML?Why
Simple typo fixāŒ NoOverhead outweighs benefit
Multi-step feature implementationāœ… YesSeparates goals, constraints, examples
Bug investigation with contextāœ… YesDistinguishes symptoms from environment
Code review with criteriaāœ… YesClear separation of code and requirements
Quick file readāŒ NoUnnecessary complexity
Architecture planningāœ… YesOrganizes goals, trade-offs, constraints

← Scroll horizontally →

Real-World Example

Here's a production-quality prompt for security review:

<instruction>
Review this authentication middleware for security vulnerabilities
</instruction>

<context>
Financial application handling sensitive user data.
Must follow OWASP Top 10 and PCI DSS compliance.
</context>

<code>
async function authenticate(req, res, next) {
  const token = req.headers.authorization?.split(' ')[1];
  if (!token) return res.status(401).json({ error: 'No token' });
  
  const decoded = jwt.verify(token, process.env.JWT_SECRET);
  req.user = decoded;
  next();
}
</code>

<constraints>
- Point out security risks with severity ratings
- Consider timing attacks and token leakage
- Suggest PCI DSS compliant alternatives
</constraints>

<output>
1. Security issues found (Critical/High/Medium/Low)
2. Specific code fixes with examples
3. Additional hardening recommendations
</output>

4. Semantic Anchors

Semantic anchors are precise technical terms that activate specific patterns in Claude's training data. Vague terms produce generic code; precise anchors produce expert-level implementations.

The Precision Difference

Vague vs. Anchored Prompts

Vague TermSemantic AnchorWhat It Activates
"clean code""SOLID principles with SRP and DIP"Specific design patterns
"good tests""TDD London School, outside-in approach"Mockist testing methodology
"error handling""Railway Oriented Programming with Result monad"Functional error patterns
"good architecture""Hexagonal Architecture (Ports & Adapters)"Concrete structural pattern
"scalable design""CQRS with Event Sourcing"Distributed system patterns
"API design""REST Level 3 with HATEOAS"Specific REST maturity

← Scroll horizontally →

How to Apply Semantic Anchors

Add them to your CLAUDE.md:

# Architecture Principles

Follow these patterns explicitly:
- **Architecture**: Hexagonal Architecture (Ports & Adapters)
- **Error handling**: Railway Oriented Programming - return Result<T, E>
- **Testing**: TDD London School - mock collaborators, test behaviors
- **Documentation**: ADR (Architecture Decision Records) for choices

Or use them inline:

Refactor the user service following Domain-Driven Design (Evans).
Apply Repository pattern for persistence and ensure 
Screaming Architecture where package structure reveals intent.
Quick Check

Which prompt will produce better-structured error handling code?


5. Plan Mode & OpusPlan

Plan Mode is Claude Code's "look but don't touch" mode-essential for safe exploration and strategic thinking.

Entering Plan Mode

/plan

Or simply ask Claude:

Let's plan this feature before implementing

What Plan Mode Allows vs. Prevents

Plan Mode Capabilities

Allowed āœ…Prevented āŒ
Reading filesEditing files
Searching the codebaseCreating new files
Analyzing architectureRunning state-changing commands
Proposing approachesMaking commits
Writing to a plan fileAny modifications

← Scroll horizontally →

OpusPlan Mode: Best of Both Worlds

OpusPlan uses Opus for planning (superior reasoning) and Sonnet for implementation (cost-efficient).

/model opusplan

The Workflow:

OpusPlan Workflow

Enable OpusPlan

Run `/model opusplan` to activate the hybrid mode.

šŸ’” You can also set this in ~/.claude/settings.json for persistence.

1/6

6. Rev the Engine

For critical decisions, run multiple rounds of planning before executing.

The Pattern

Standard workflow: think → plan → execute

Rev the Engine: think → plan → think harder → refine → think hardest → finalize → execute

When to Use

  • →Critical architectural decisions (irreversible, high-impact)
  • →Complex migrations affecting 10+ files
  • →Unfamiliar domains where first instincts are often wrong

Three-Round Example

## Round 1: Initial Analysis
User: /plan
User: Analyze the current auth system. What are the key components,
      dependencies, and risks of migrating to OAuth2?
Claude: [Initial analysis]

## Round 2: Deep Challenge
User: Now challenge your own analysis:
      - What assumptions did you make?
      - What failure modes did you miss?
      - What would a senior security engineer flag?
Claude: [Deeper analysis with self-correction]

## Round 3: Final Plan
User: Based on both rounds, write the definitive migration plan.
      Include rollback strategy and risk mitigation.
Claude: [Refined plan incorporating both rounds]

## Execute
User: /execute
User: Implement the plan from round 3.
Click to expand

7. Cost Optimization

Claude Code uses API credits. Understanding costs helps optimize without sacrificing productivity.

Pricing Reality Check

ModelInput (per 1M tokens)Output (per 1M tokens)
Sonnet 3.5 (default)$3.00$15.00
Opus 4$15.00$75.00
Haiku 3.5$0.80$4.00

Typical session costs:

  • →Quick task (5-10 min): $0.05-$0.10
  • →Feature work (1-2 hours): $0.20-$0.50
  • →Deep refactor (half day): $1.00-$2.00

The Expensive Operations

Cost by Operation

OperationTokensEst. Cost
Read 100-line file~500$0.0015
Read 10 files (1000 lines)~5,000$0.015
Long conversation (20 messages)~30,000$0.090
MCP tool call~2,000$0.006
Running tests with output~3-10K$0.009-$0.030
Code generation (100 lines)~2,000 output$0.030

← Scroll horizontally →

Cost Optimization Strategies

5 Strategies to Reduce Costs

Strategy 1: Be Specific in Queries

āŒ 'Check auth.ts for issues' (~5K tokens) āœ… 'Check login function in auth.ts:45-60' (~500 tokens)

šŸ’” Targeting specific line ranges instead of entire files cuts costs 90%.

1/5

Track Your Costs

Check current session cost anytime:

/status

Output:

Session Status
───────────────────────────────────────────────
  Context:  45% used (90K / 200K tokens)
  Cost:     $0.23 this session
  Duration: 1h 23m
───────────────────────────────────────────────
Quick Check

You need to read 5 TypeScript files to understand a feature. What's the most cost-effective approach?


8. Prompting as Provocation

The Claude Code team internally treats prompts as challenges to a peer, not instructions to an assistant. This subtle shift produces higher-quality outputs.

Three Provocation Patterns

Provocation Patterns from the Claude Team

The Gatekeeper

"Grill me on these changes and don't make a PR until I pass your test"

šŸ’” Claude reviews your diff, asks pointed questions about edge cases, and only proceeds when satisfied.

1/3

9. Fresh Context Pattern

For long autonomous runs, consider the Fresh Context Pattern (also called the Ralph Loop).

The Problem: Context Rot

Research shows LLM performance degrades with accumulated context:

  • →20-30% performance gap between focused and polluted prompts
  • →Degradation starts around 16K tokens
  • →Failed attempts and error traces dilute attention

The Solution

Instead of managing context within a session, restart with a fresh session per task:

# The Ralph Loop
while :; do cat TASK.md PROGRESS.md | claude -p ; done

State persists via:

  • →TASK.md, Current task definition
  • →PROGRESS.md, Learnings, completed work, blockers
  • →Git commits, Each iteration commits atomically

Traditional vs. Fresh Context

TraditionalFresh Context
Accumulate in chat historyReset per task
/compact to compressState in files + git
Context bleeds across tasksEach task gets full attention
Good for interactive workGood for autonomous runs

← Scroll horizontally →

When to Use Fresh Context

SituationApproach
Interactive explorationTraditional (stay in session)
Context 70-90%/compact
Autonomous run > 1 hourFresh Context Pattern
Clear success criteria (tests pass)Fresh Context Pattern
Overnight/AFK executionFresh Context Pattern
Click to expand

10. Advanced Workflows Summary

The Expert's Decision Tree

Is this a simple, reversible change?
ā”œā”€ā”€ YES → Just execute (no planning overhead)
└── NO → How impactful is this decision?
    ā”œā”€ā”€ Medium → Plan Mode + Execute
    ā”œā”€ā”€ High → OpusPlan (Opus thinks, Sonnet implements)
    └── Critical → Rev the Engine (3 rounds) + OpusPlan

Quick Reference

TechniqueWhen to UseCommand/Pattern
/compactContext > 50%/compact
Plan ModeSafe exploration/plan
OpusPlanBest reasoning + cost efficiency/model opusplan
Rev the EngineCritical decisions3 rounds in Plan Mode
Fresh ContextLong autonomous runs`while :; do cat TASK.md
XML PromptsComplex multi-part requests<instruction>, <context>, <constraints>
Semantic AnchorsExpert-level outputUse precise technical terms

What's Next?

You now have the advanced techniques that separate power users from beginners. Practice these patterns and they'll become second nature.

Continue to Module 1 for hands-on exercises applying these techniques to real projects.


This article is part of the Claude Code Ultimate Guide series. Continue your journey with Module 1: Core Techniques for deeper practice.

Go deeper — free guide

Module 1 — LLM Anatomy & Prompt Structure

Understand how LLMs work and construct clear, reusable prompts.

D

Dorian Laurenceau

Full-Stack Developer & Learning Designer

Full-stack web developer and learning designer. I spent 4 years as a freelance full-stack developer and 4 years teaching React, JavaScript, HTML/CSS and WordPress to adult learners. Today I design learning paths in web development and AI, grounded in learning science. I founded learn-prompting.fr to make AI practical and accessible, and built the Bluff app to gamify political transparency.

Prompt EngineeringLLMsFull-Stack DevelopmentLearning DesignReact
Published: January 16, 2025Updated: April 24, 2026

One practical AI workflow in your inbox

Methods, resources and new exercises. Free, unsubscribe at any time.

FAQ

What is context engineering in Claude Code?+

Context engineering is the practice of optimizing what information Claude sees. This includes CLAUDE.md structure, file references, context compaction, and strategic use of the 200K token window.

What are XML-structured prompts?+

XML tags like <requirements>, <constraints>, <examples> help Claude parse complex instructions. They provide clear semantic boundaries and improve response accuracy for multi-part requests.

What is OpusPlan mode?+

OpusPlan triggers Claude to create a detailed execution plan before acting. Use it for complex tasks: 'OpusPlan: Refactor the authentication system to use JWT tokens.'

How can I reduce Claude Code costs?+

Use /compact to summarize context, be specific in requests to reduce iterations, use cheaper models (Haiku) for simple tasks, and structure CLAUDE.md efficiently.