Advanced Claude Code Techniques: Master Pro-Level Patterns
By Dorian Laurenceau
š 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:
| Usage | Zone | Visual | Action |
|---|---|---|---|
| 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:
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:
The Compact Command Deep Dive
When you run /compact, Claude:
- āSummarizes the conversation so far
- āPreserves essential info (project structure, current task, recent decisions)
- āDiscards verbose details (old diffs, lengthy outputs, resolved discussions)
- āFrees typically 40-60% of context
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:
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)
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
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
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.
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
OpusPlan Mode: Best of Both Worlds
OpusPlan uses Opus for planning (superior reasoning) and Sonnet for implementation (cost-efficient).
/model opusplan
The Workflow:
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.
7. Cost Optimization
Claude Code uses API credits. Understanding costs helps optimize without sacrificing productivity.
Pricing Reality Check
| Model | Input (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 Optimization Strategies
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
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
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
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
When to Use Fresh Context
| Situation | Approach |
|---|---|
| Interactive exploration | Traditional (stay in session) |
| Context 70-90% | /compact |
| Autonomous run > 1 hour | Fresh Context Pattern |
| Clear success criteria (tests pass) | Fresh Context Pattern |
| Overnight/AFK execution | Fresh Context Pattern |
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
| Technique | When to Use | Command/Pattern |
|---|---|---|
/compact | Context > 50% | /compact |
| Plan Mode | Safe exploration | /plan |
| OpusPlan | Best reasoning + cost efficiency | /model opusplan |
| Rev the Engine | Critical decisions | 3 rounds in Plan Mode |
| Fresh Context | Long autonomous runs | `while :; do cat TASK.md |
| XML Prompts | Complex multi-part requests | <instruction>, <context>, <constraints> |
| Semantic Anchors | Expert-level output | Use 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.
Module 1 ā LLM Anatomy & Prompt Structure
Understand how LLMs work and construct clear, reusable prompts.
Dorian Laurenceau
Full-Stack Developer & Learning DesignerFull-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.
Weekly AI Insights
Tools, techniques & news ā curated for AI practitioners. Free, no spam.
Free, no spam. Unsubscribe anytime.
āRelated Articles
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.