Context engineering is about making sure Claude has exactly the information it needs, and nothing it doesn’t.
The Three Layers
Layer 1: Always loaded (CLAUDE.md) Keep this small. Only rules that apply to every single task.
# CLAUDE.md
Use TypeScript. Run `bun test` to verify. Follow existing patterns.
Layer 2: Conditionally loaded (.claude/rules/) Rules that apply only in certain directories or file types.
# .claude/rules/api.md
All API routes go in src/routes/. Use Zod for request validation.
Return consistent error shapes: { error: string, code: number }.
Layer 3: On-demand (skills, @ references) Heavy context loaded only when needed.
@src/db/schema.ts implement a new users table following this schema pattern
Minimize Token Waste
- Use
.claudeignoreto excludenode_modules,dist, build artifacts, and large generated files - Keep CLAUDE.md under 200 lines (aim for under 50)
- Use
.claude/rules/for directory-specific instructions instead of bloating CLAUDE.md - Reference files with
@instead of pasting their contents
Session Habits
- Start with
/clearbetween unrelated tasks - Use
/compactwhen context gets long - Front-load important context in your first message
- Tell Claude which files matter: “Focus on src/auth/ for this task”
Measure Your Context
Run /cost periodically. If you’re burning through context fast, check whether Claude is reading files it doesn’t need. Add those patterns to .claudeignore.