Beyond Prompts: 4 Context Engineering Secrets for Claude Code
Overview
You can stop hoping your Large Language Model (LLM) follows complex instructions. Context Engineering is the strategic practice of curating what enters the model's limited attention budget. To build reliable AI agents, you must master these four deterministic context patterns.
This post explores the key insights from my presentation "Claude Code Skill(s): Mastering AI-Powered Development", focusing on practical patterns that transform unpredictable AI interactions into deterministic, production-ready workflows.
What is Context Engineering?
Context Engineering is the art and science of strategically managing what information an LLM processes within its limited attention window. Unlike traditional prompt engineering, which focuses on crafting individual requests, context engineering treats the entire development environment as a programmable context system.
The challenge: Modern LLMs like Claude offer massive context windows (up to 1 million tokens), but without proper engineering, this capacity becomes a liability rather than an asset. Information overload, context pollution, and inconsistent behavior plague naive implementations.
The solution: Treat context as a managed resource with four key patterns.
1. Memory is a Hierarchical Filesystem
Claude Code manages context through structured, version-controllable files rather than ephemeral prompts or database entries. This Hierarchical Memory system uses a clear precedence:
1~/.claude/CLAUDE.md (User) # Global instructions across all projects
2./CLAUDE.md (Project) # Project-specific guidelines
3./CLAUDE.local.md (Local) # Machine-specific overrides (gitignored)
Why Filesystem-Based Memory Matters
Version Control Integration: Your team's AI expertise becomes git-committable knowledge. When a senior engineer discovers an optimal workflow pattern, it's captured in CLAUDE.md and distributed to the entire team through version control.
Consistent Context Delivery: Every interaction with Claude Code starts with the same foundational knowledge. No more repeating "use conventional commits" or "follow our coding standards" in every session.
Layered Context Precedence: The hierarchical structure allows for inheritance and overrides:
- User-level instructions define personal preferences
- Project-level instructions enforce team standards
- Local overrides handle machine-specific configurations
Practical Example
1# ./CLAUDE.md (Project)
2
3## AWS CDK Best Practices
4
5- **Resource Naming**: Do NOT explicitly specify resource names
6 when optional in CDK constructs. Let CDK generate unique names
7 to enable parallel stacks and environments.
8
9- **Lambda Functions**: Use `@aws-cdk/aws-lambda-nodejs` for
10 TypeScript/JavaScript. These constructs handle bundling,
11 dependencies, and transpilation automatically.
This single file eliminates hundreds of repetitive prompts across your team's development lifecycle.
2. Hooks Enforce Context Injection
Hooks are shell commands triggered at specific lifecycle events in Claude Code, providing Deterministic Control over AI behavior. The most powerful pattern is the Memory Enforcer, which leverages the UserPromptSubmit event.
The Power of UserPromptSubmit Hooks
This event executes before any AI processing begins, allowing you to:
- Inject domain-specific knowledge
- Pre-load necessary context
- Trigger autonomous skills
- Enforce organizational policies
1# ~/.claude/hooks/user-prompt-submit.sh
2
3# Automatically inject AWS best practices for infrastructure queries
4if echo "$PROMPT" | grep -qi "aws\|lambda\|cdk"; then
5 echo "Loading AWS architecture context..."
6 cat ~/.claude/aws-patterns.md
7fi
8
9# Trigger security review for authentication-related changes
10if echo "$PROMPT" | grep -qi "auth\|login\|credential"; then
11 echo "/security-review"
12fi
From Hope to Guarantee
"Deterministic Control: Hooks transform 'hope AI follows instructions' into 'guaranteed execution' through code enforcement."
Traditional prompt engineering: "Please remember to check security implications..."
Hook-based enforcement:
1# Security hook always runs on code changes
2if [ -n "$(git diff --name-only | grep -E '\.(ts|js|py)$')" ]; then
3 /run-security-scan
4fi
The hook guarantees execution. The AI doesn't "forget" or "overlook"—the system enforces the behavior.
3. Skills Are Autonomous, Context-Driven Extensions
Agent Skills are modular knowledge bases that Claude autonomously invokes based on context. Unlike manual tool invocations, Skills are discovered and activated by Claude itself when the context matches their description.
The Anatomy of an Effective Skill
Skills are defined as SKILL.md files with three critical components:
- Clear Description: What the skill does (for autonomous discovery)
- Activation Context: When Claude should use it
- Domain Knowledge: The expertise it provides
1---
2name: aws-cdk-patterns
3description: AWS CDK architecture patterns and best practices
4trigger: Use when designing or implementing AWS infrastructure with CDK
5---
6
7# AWS CDK Architecture Patterns
8
9## Serverless API Pattern
10When building REST APIs, prefer this stack composition:
11- API Gateway (HTTP API for cost efficiency)
12- Lambda (Node.js runtime with arm64 for performance)
13- DynamoDB (single-table design when appropriate)
14
15[Implementation details...]
Autonomous Activation
The key difference from traditional tools:
Manual Tool Invocation (Traditional):
1User: "Use the AWS tool to create a Lambda function"
Autonomous Skill Activation (Context-Driven):
1User: "Create a serverless API for user management"
2Claude: [Sees "serverless API" context]
3 [Discovers aws-cdk-patterns skill]
4 [Autonomously loads and applies patterns]
5 [Implements with best practices baked in]
The skill's description enables proper discovery. Claude reasons: "This query involves serverless APIs → aws-cdk-patterns skill matches → load and apply."
Reducing Repetitive Prompting
Before Skills:
1User: "Create Lambda with proper IAM roles"
2User: "Add DynamoDB with encryption"
3User: "Configure API Gateway with CORS"
4User: "Set up CloudWatch logging"
With Skills:
1User: "Create a serverless API"
2Claude: [aws-cdk-patterns skill automatically applies all patterns]
The skill encapsulates the complete pattern, eliminating prompt repetition.
4. Configure for 1M Token Scale
Effectively using Claude's 1 million token context window requires explicit configuration and understanding of the infrastructure.
Amazon Bedrock Integration
When integrating Claude via Amazon Bedrock, enable extended context explicitly:
1# Enable 1M token context window
2/model sonnet[1m]
3
4# Verify configuration
5aws bedrock get-foundation-model \
6 --model-identifier anthropic.claude-3-5-sonnet-20241022-v2:0[1m]
The [1m] suffix is critical—without it, you're limited to smaller context windows.
Claude Agent SDK Features
For programmatic agent development, the Claude Agent SDK provides essential context management:
1import { Agent } from '@anthropic-ai/agent-sdk';
2
3const agent = new Agent({
4 model: 'claude-3-5-sonnet-20241022',
5 // Automatic context compaction when approaching limits
6 autoCompact: true,
7 // Control token allocation for reasoning
8 thinkingBudget: 16000,
9 // Long-running session support
10 maxTurns: 100
11});
Token Budget Optimization
Thinking Budget: Control how many tokens Claude allocates to internal reasoning:
1// Development/debugging: verbose reasoning
2thinkingBudget: 32000
3
4// Production: efficient processing
5thinkingBudget: 8000
Context Compaction: The SDK automatically summarizes older context when approaching limits, maintaining relevance while preserving essential information.
Long Session Strategies
For extended development sessions:
- Periodic Checkpointing: Save key decisions and context
- Strategic Summarization: Compress completed work
- Context Pruning: Remove no-longer-relevant information
- Hierarchical Memory: Offload persistent knowledge to CLAUDE.md files
1# Hook for automatic session checkpointing
2# ~/.claude/hooks/every-10-turns.sh
3echo "Creating context checkpoint..."
4claude-snapshot save "checkpoint-$(date +%s)"
The Paradigm Shift: Programming Claude's Perception
Context engineering represents a fundamental shift from request-response prompting to environment programming. You're not asking Claude to do things differently—you're changing what Claude perceives as reality.
Traditional Approach: Persuasion
1"Please follow our coding standards..."
2"Remember to add tests..."
3"Don't forget error handling..."
Context Engineering: Perception Programming
1CLAUDE.md defines coding standards as reality
2Hooks guarantee test execution
3Skills embed error handling patterns
Claude doesn't need to "remember" or "try hard"—the engineered context makes correct behavior the natural, obvious choice.
Implementation Checklist
Ready to implement these patterns? Here's your action plan:
Immediate Actions
- Create project
CLAUDE.mdwith team standards - Set up user-level
~/.claude/CLAUDE.mdfor personal workflows - Configure
.gitignoreto excludeCLAUDE.local.md
Hooks Setup
- Create
~/.claude/hooks/user-prompt-submit.sh - Implement context injection for common domains
- Add security enforcement hooks
Skills Development
- Identify repetitive instruction patterns
- Convert top 3 patterns to Agent Skills
- Write clear skill descriptions for autonomous activation
Scale Configuration
- Enable
[1m]context for larger context window - Configure thinking budget for your use case
- Implement session management strategy
Conclusion
Context engineering transforms AI development from an art of persuasion into a science of deterministic systems design. By treating context as managed infrastructure—through hierarchical memory, enforced hooks, autonomous skills, and optimized configuration—you build reliable AI agents that perform consistently.
The four patterns work synergistically:
- Memory provides foundational knowledge
- Hooks enforce critical behaviors
- Skills deliver domain expertise autonomously
- Configuration enables scale and efficiency
Stop hoping your LLM follows instructions. Start engineering the context that makes correct behavior inevitable.
Watch the Full Presentation
For a deeper dive into these concepts with live demonstrations, watch my presentation: