[FEATURE] Support independent Prompt Cache TTL for Subagents and Main Session
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] 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
- 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).
- Subagent Trigger: I ask the main agent to "Fix the linting errors in auth.ts."
- 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.
- 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.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗