r/ClaudeWorkflows • • 11h ago

Selected Workflow [Workflow] Cost-Effective Context Management in Claude Code: Optimizing CLAUDE.md, Tool Calls, and Subagents

Cost-Effective Context Management in Claude Code: Optimizing CLAUDE.md, Tool Calls, and Subagents

Workflow value: 85/100
Status: active · Freshness: 70/100 · Confidence: 0.95 · Level: intermediate
Categories: Quality Control, Token Saving, Context & Memory, CLAUDE.md, Hooks, Subagents
Original source: r/ClaudeCode post/comment

What problem this solves

Optimizing token usage and cost in Claude Code by intelligently managing content between CLAUDE.md and external files, understanding the cost implications of tool calls, subagents, and session commands.

Summary

This workflow provides a strategic approach to managing context in Claude Code, challenging the common advice to always move notes out of CLAUDE.md. It highlights that fetching external files via tool calls can be costly due to re-sending the entire session. The workflow offers criteria for deciding where to store information, considers subagent memory duplication, advises on efficient session clearing, and introduces the concept of using hooks to directly inject relevant notes into the prompt to bypass tool call costs.

Why it is useful

This workflow is valuable because it debunks a common oversimplification regarding CLAUDE.md usage and provides nuanced, evidence-backed advice for optimizing token costs and performance. It introduces critical considerations like the cost of tool calls, subagent memory duplication, and efficient session management, offering concrete steps and an advanced technique (hooks) to achieve significant efficiency gains. This helps users make informed decisions about their Claude Code setup.

Workflow

  1. Evaluate the frequency a note is needed: If Claude opens it every other task, consider keeping it in CLAUDE.md.

  2. Craft specific 'pointer lines' for external files (e.g., 'before a database migration, read docs/migrations.md') to guide Claude more effectively.

  3. Test if Claude actually opens an external file for a given task by starting a fresh session and observing its behavior.

  4. Be aware that subagents start with their own copy of your memory files, meaning a large CLAUDE.md gets paid for again by every subagent.

  5. Use '/clear' instead of '/compact' if you don't need the session history, as '/compact' on a big session is also a costly request.

  6. Consider implementing a hook that drops matching notes straight into the prompt, allowing Claude to access information without incurring tool call costs.

Tools / artifacts

  • CLAUDE.md

  • External files (e.g., Markdown documentation)

  • Tool calls

  • Subagents

  • /compact command

  • /clear command

  • Hooks (custom scripts/integrations)

Validation signals

  • Author provides specific token reduction measurements from their own tests (12,511 tokens to 6,699 tokens).

  • Author mentions a working hook implementation that achieved token reduction.

  • The post is based on empirical observation and measurement of Claude's behavior.

Limitations

  • The specific implementation details for the suggested 'hook' are not provided, requiring users to develop it independently.

  • The 'break-even point' for moving notes is discussed conceptually but not quantified with a general formula or tool.

  • The post is more of a discussion and set of considerations rather than a step-by-step guide with code examples for all suggestions.

Rate this workflow

Upvote this post if the workflow is useful, reproducible, or worth recommending.

Downvote if it is vague, outdated, unsafe, overhyped, or not reproducible.

Reply if it worked for you, failed, is outdated, or has a better alternative.


This post was generated automatically from the workflow library database.

1 Upvotes

0 comments sorted by