claude-code - 💡(How to fix) Fix [FEATURE] Support independent Prompt Cache TTL for Subagents and Main Session [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#54568Fetched 2026-04-30 06:42:06
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×3closed ×1

Fix Action

Fix / Workaround

Current Workaround: I manually restart sessions to clear cache, but this destroys the main session's valuable context.

RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • This is a single feature request (not multiple features)

Problem Statement

Currently, Claude Code appears to apply a uniform caching strategy to both the main session and spawned Subagents. In complex development workflows, the main session often requires a long-lived context (e.g., 1 hour) to maintain a holistic understanding of the project.

However, Subagents are frequently used for short-lived, high-frequency tasks (like fixing a single test or refactoring a small function). Keeping their specific context in the cache for a full hour results in unnecessary token costs and rapid accumulation of expenses. I need a way to decouple these TTL (Time-To-Live) settings to optimize for both persistence and cost-efficiency.

Proposed Solution

I would like to see granular cache control for different agent layers. Ideally:

CLI Flags: Add flags to specify distinct TTLs: claude --cache-ttl 1h --subagent-cache-ttl 5m.

Environment Variables: Support variables like CLAUDE_CODE_SUBAGENT_CACHE_TTL.

Smart Defaults: Subagents should ideally default to a much shorter TTL than the main session to prevent "cost leaking."

Alternative Solutions

Current Workaround: I manually restart sessions to clear cache, but this destroys the main session's valuable context.

Other Tools: Some custom MCP clients allow per-agent API parameter overrides, but as an official CLI, Claude Code should offer this natively.

Priority

High - Significant impact on productivity

Feature Category

Configuration and settings

Use Case Example

  1. Main Session: I start a session to work on a large refactor. The main session caches the entire project structure and key files (TTL set to 1h).

  2. Subagent Trigger: I ask the main agent to "Fix the linting errors in auth.ts."

  3. Short-term Task: A Subagent is spawned. It only needs to cache the auth.ts file and linting rules for the duration of that specific fix.

  4. Result: With this feature, the Subagent's cache expires in 5 minutes, saving money, while my main session remains "warm" and ready for the next high-level instruction.

Additional Context

This differentiation would allow users to be more aggressive with Subagent usage without fearing a massive bill from idle, long-lived cached tokens that are no longer relevant to the primary task.

extent analysis

TL;DR

Implementing granular cache control with distinct TTLs for the main session and Subagents can help optimize cache persistence and cost-efficiency.

Guidance

  • Introduce CLI flags to specify separate TTLs for the main session and Subagents, such as --cache-ttl and --subagent-cache-ttl.
  • Support environment variables like CLAUDE_CODE_SUBAGENT_CACHE_TTL to allow for flexible configuration.
  • Set smart defaults for Subagent TTLs to a shorter duration than the main session to prevent unnecessary costs.
  • Consider implementing a mechanism to automatically clear Subagent caches after a specified TTL to prevent "cost leaking".

Example

claude --cache-ttl 1h --subagent-cache-ttl 5m

This example demonstrates how to set a 1-hour TTL for the main session and a 5-minute TTL for Subagents using CLI flags.

Notes

The proposed solution requires changes to the Claude Code configuration and settings. The exact implementation details may vary depending on the underlying architecture and technology stack.

Recommendation

Apply a workaround by implementing granular cache control using CLI flags or environment variables, as this will allow for more flexible and efficient cache management.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [FEATURE] Support independent Prompt Cache TTL for Subagents and Main Session [1 participants]