Claude Code Examples
This chapter collects real-world Claude Code usage patterns and translates them into actionable engineering habits. The goal: understand why Claude Code stays stable during long tasks, and how to borrow its context management approach.
- Claude Code uses CLAUDE.md as procedural memory.
- Exceeding 95% of the context window triggers auto-compact.
- File-system-as-memory + grep/head/tail is the core capability.
- Local MCP servers can be added quickly with
claude mcp add. - Tool responses are capped at 25,000 tokens by default to prevent context from being consumed.
What You'll Learn
- Claude Code's context management patterns and when to use them
- How to use CLAUDE.md as a project-level rules entry point
- How to integrate MCP servers and evaluate tools
- How to design token-efficient tool responses
Example 1: CLAUDE.md as Procedural Memory
Claude Code treats CLAUDE.md as project-level rules and operational norms (procedural memory). It's a "fixed-load" context that gives the model a consistent behavioral baseline on every inference.
Practical tips:
- Use CLAUDE.md to record key norms and constraints
- Don't cram details into the system prompt -- put them in CLAUDE.md
- Rules should be "actionable and verifiable" -- no fluff
Example 2: Auto-Compact at 95% Context Window
Claude Code triggers auto-compact when context usage exceeds 95%, summarizing and compressing the full conversation. It's automated context hygiene.
You can implement something similar in your own system:
- Set a threshold (e.g., 70-80% or 90-95%)
- Generate structured summaries (Files/Decisions/Next Steps)
- Keep the most recent N turns for continuity
Example 3: File-System-as-Memory (Just-in-Time Context)
Claude Code uses file system operations to "load on demand" rather than stuffing everything into context. Common methods include grep/head/tail to quickly locate and read file fragments.
Core principles:
- Keep lightweight references (file paths / query strings)
- Read when needed -- don't do a one-time full load
- Small incremental reads are more stable than one big bulk load
Example 4: MCP Server Integration
When you have your own tools or MCP servers, you can wire them into Claude Code directly:
claude mcp add <name> <command> [args...]
This lets local MCP servers be called directly in Claude Code for quick tool usability testing.
Recommended approach:
- Get the local prototype running first
- Use Claude Code for exploratory calls
- Collect failure patterns and improve tool descriptions based on them
Example 5: Token-Efficient Tool Responses
Claude Code caps tool responses at 25,000 tokens by default, preventing context from being consumed by tool outputs. Key strategies:
- Use pagination / filtering / truncation
- Provide both concise and detailed response formats
- Use error responses to guide more precise calls
Very effective for reducing context sprawl.
Example 6: Evaluation with Claude Code
Claude Code can quickly generate prompt/response pairs to help you build evaluation tasks. Tips:
- Tasks should be close to real scenarios, not toy examples
- Tasks should include multi-step tool calls
- Don't make the verifier too strict -- format differences shouldn't count as failures
Quick Checklist
- Do you have a CLAUDE.md as project-level rules?
- Is auto-compact or compaction triggers set up?
- Are you using file-system-as-memory?
- Can your MCP server be called directly from Claude Code?
- Do tool responses have a default token limit?
Practice Task
- Create a CLAUDE.md with 5 project rules
- Use
claude mcp addto integrate a local MCP server - Design a 3-step tool call task and measure its context cost
Related Pages
Integration
This page complements Context Engineering topics by showing production patterns used in Claude Code. It pairs well with:
- context-fundamentals
- context-compression
- tool-design
References
- Agent Skills for Context Engineering: blogs.md
- Agent Skills for Context Engineering: claude_research.md
Skill Metadata
Created: 2025-12-24 Last Updated: 2025-12-24 Author: JR Academy Version: 1.0.0
📚 Related resources
❓ Common questions
Open a question to review the practical answer.
What role does CLAUDE.md actually play in Claude Code?
Claude Code uses CLAUDE.md as procedural memory — project-level rules and conventions loaded by default every turn. Detail rules (naming, commits, API style) belong in CLAUDE.md, not in system prompt; the rules must be executable and verifiable — "keep code clean" is filler, "single file ≤ 500 LOC" is a rule.
Why does Claude Code wait until 95% before triggering auto-compact?
95% is the "compact now or get truncated" threshold — earlier loses conversational continuity, later gets hard-cut. auto-compact does not drop messages, it produces a structured summary (Files / Decisions / Next Steps) and preserves the last N turns for continuity. When implementing your own version, dialing the threshold down to 70-80% is safer; reserve 95% for the truly desperate case.
What does the claude mcp add command actually do?
The shortcut for plugging a local MCP server into Claude Code: claude mcp add <name> <command> [args...]. Once added, Claude Code can call your tool directly — perfect for usability testing, running the prototype, checking whether the tool description reads clearly, and capturing failure modes to feed back into the schema. Saves about a week versus writing client integration code.
Where does the 25,000-token tool response cap come from?
It is Claude Code's default — a guardrail against a single tool output devouring the entire context. Typical triggers: cat on a large file, ls across an entire monorepo, an API list call returning a thousand records. Past 25K it truncates with a notice. Pair it with two response formats — concise (default) and detailed (on request) — and use error responses to steer more precise calls instead of retrying the full payload.
What should I watch out for when building evaluation tasks with Claude Code?
Three keys: (1) tasks must mirror real scenarios — toy examples produce metrics that do not transfer to production; (2) tasks should require multi-step tool calls, single-step tasks cannot reveal context management ability; (3) verifiers must not be overly strict — failing on whitespace or quote-style differences pushes noise above signal, so judge by semantic equivalence.