GeezerVison is showing github.com — [FEATURE]:config: no setting for prompt-cache TTL (1h) - Internals Support it · Issue #62125 · anomalyco/opencode
[FEATURE]:config: no setting for prompt-cache TTL (1h) - Internals Support it #62125DescriptionFeature hasn't been suggested before.
- I have verified this feature I'm about to request hasn't been suggested before.
Describe the enhancement you want to request
Summary
There is no config setting for the prompt-cache lifetime (TTL). opencode always marks the cache with the endpoint's default 5-minute lifetime. The internals already support a 1-hour cache (ttlSeconds >= 3600 maps to Anthropic ttl: "1h" and Bedrock cachePoint.ttl: "1h"), but nothing in user config reaches it. Long-running lead sessions that sit idle while background subagents work pay a full-context cache rewrite after every 5+ minute pause.
Environment
- opencode version: v2.1.2
- OS: Darwin 25.6.0 (darwin arm64)
- Terminal: TERM_PROGRAM=vscode, TERM=xterm-256color, COLORTERM=truecolor
- Shell: /bin/zsh
- Install/channel: latest
- Active plugins: none found in config
Reproduction
- Configure a Claude model behind an Anthropic Messages / Bedrock-backed gateway (
@ai-sdk/anthropic, custom baseURL).
- Run a long session (200k+ context) that launches background subagents and waits more than 5 minutes for them.
- On the next turn, inspect the usage:
cache_creation.ephemeral_5m_input_tokens is the full context (a complete rewrite) and ephemeral_1h_input_tokens is 0.
- Search the V2 docs (models, providers, config) for a cache TTL setting: only
compatibility.cacheFormat exists, and the docs state the default five-minute lifetime is used.
Expected Behavior
A per-model or per-agent setting, for example "cache": { "ttlSeconds": 3600 } (or "ttl": "1h"), that forwards to the existing LLM.CacheHint.ttlSeconds. A per-agent setting lets the primary session use 1 h while subagents, which run continuously, keep 5 m.
Actual Behavior
Always 5 minutes. A direct request through the same gateway with cache_control: {type: "ephemeral", ttl: "1h"} works: the first call reports ephemeral_1h_input_tokens: 5616 and an identical second call reports cache_read_input_tokens: 5616. So the gap is only the missing opencode setting.
Additional Context
Impact, measured from one month of local session history (Claude Opus/Sonnet at list prices: 5 m write 1.25x input, 1 h write 2x, read 0.05x):
- Primary (lead) session: 10% of turns (343) rewrote 50k+ tokens of cache, 94M tokens in total. 259 of those followed a 5–60 minute idle gap.
- A replay of that history with a 1 h TTL lowers the lead's cache spend by roughly 30%. For continuously running subagents it is neutral to slightly worse (+5–25%), so a per-agent setting matters.
- Related:
compaction.tail_turns in project config logs "unsupported legacy setting".
Activityopencodejr commented on Nov 5, 2026 Thanks for the detailed report and the cost measurements! I think this is a duplicate of #51109, which asks for the same thing: a configurable prompt-cache TTL so long-running lead sessions keep their cache while background subagents work.
The setting already exists in v2.2.0 and later (added in #59157), and you're on v2.1.2. After upgrading you can set cache.ttl at provider, model or variant level:
{
"providers": {
"anthropic": {
"settings": { "cache": { "ttl": "1h" } },
"models": {
"claude-opus-5-5": { "variants": [{ "id": "short", "settings": { "cache": { "ttl": "5m" } } }] }
}
}
}
}
Agents can select a model variant, so your lead agent can use the 1h default while subagents use the 5m variant. Choosing the TTL automatically by context (primary vs subagent) is discussed in #51109 and #53927.
Possible duplicates and related issues, ordered from most to least likely:
The compaction.tail_turns "unsupported legacy setting" warning is a separate topic. If it matters to you, please open its own issue.
The bot will close this issue as a duplicate in 1 day unless you reply explaining how your request is different.
opencodejr commented on Nov 6, 2026 Closing this as a duplicate of #51109, since we haven't heard back in the past day. The cache TTL setting you asked for is in v2.2.0 and later (#59157). After upgrading from v2.1.2, you can set settings.cache.ttl (e.g. "1h") at provider, model or variant level, and point an agent at a variant to give your lead session and your subagents different TTLs. Please follow #51109 and #53927 for choosing the TTL automatically by context. If this is still a problem after upgrading, or your request turns out to be different, reply here and we can reopen it. Thanks again for the detailed measurements!
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|