logo
37

Claude Code Examples

⏱️ 30 min

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 add to integrate a local MCP server
  • Design a 3-step tool call task and measure its context cost

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