Skip to content

Restore the 1-hour prompt cache for pooled Claude Code threads - #5130

Merged
SawyerHood merged 1 commit into
get-bb:mainfrom
vburojevic:account-pool-subscription-cache-ttl
Oct 7, 2026
Merged

SawyerHood merged 1 commit into
get-bb:mainfrom
vburojevic:account-pool-subscription-cache-ttl

Conversation

@vburojevic

Copy link
Copy Markdown
Contributor

Human comments

What was wrong

Claude Code picks its prompt-cache TTL automatically: 1 hour for a recognized Claude subscription login, 5 minutes for an API key or a custom endpoint. Pooled Claude Code threads run with ANTHROPIC_BASE_URL pointed at the hub and ANTHROPIC_AUTH_TOKEN set to the hub token. Claude Code then no longer sees a subscription login, so every pooled conversation silently falls back to the 5-minute cache. It also prints claude.ai connectors are disabled because ANTHROPIC_API_KEY or another auth source is set.

Agent threads often pause for more than 5 minutes: a long build or test run, a CI wait, a background task, a thread message, or a user who replies a few minutes later. Each such pause expires the cache. The next request then re-writes the whole conversation prefix at the cache-write price instead of reading it at the cache-read price. With large contexts these rewrites become a large share of usage, so subscription limits drain much faster through the pool than the same work on a direct login. The change is visible in session transcripts: for pooled threads, usage.cache_creation.ephemeral_1h_input_tokens stays at 0.

This is the same class of custom-base-URL side effect the plugin already offsets with ENABLE_TOOL_SEARCH and _CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL.

What changed

  • plugins/account-pool/src/server.ts: the claude-code env contribution now adds ENABLE_PROMPT_CACHING_1H=1 when the pool can serve Claude through at least one enabled subscription (OAuth) account. It also adds it while the instance proxies to a parent pool, because the child cannot see the parent's account kinds.
  • plugins/account-pool/src/operations.ts: new routesOnlyApiKeys(provider). When every usable enabled Claude account is an API key, the flag is left out and Claude Code keeps its 5-minute API-key default.
  • Why ENABLE_PROMPT_CACHING_1H and not CLAUDE_CODE_PROMPT_CACHE_TTL=1h:
    • Contributed env overrides the thread's shell env.
    • In Claude Code, CLAUDE_CODE_PROMPT_CACHE_TTL outranks the user's promptCacheTtl setting, so it would silently override a user's explicit choice.
    • ENABLE_PROMPT_CACHING_1H ranks below FORCE_PROMPT_CACHING_5M, CLAUDE_CODE_PROMPT_CACHE_TTL, the promptCacheTtl and subagentPromptCacheTtl settings, and agent frontmatter. An explicit user choice therefore still wins.
  • One known difference from a direct subscription login: by default a direct login gives the 1-hour TTL only to the main conversation and keeps subagent and helper requests on 5 minutes. With this flag, subagent and helper requests also use 1 hour. Users who want the exact split can set subagentPromptCacheTtl: "5m".
  • No host-daemon wire change and no CLI or configuration surface change.

How you verified

  • New test restores the 1-hour prompt cache only while a subscription account can serve Claude:
    • an API-key-only pool contributes no flag;
    • adding an imported subscription account contributes ENABLE_PROMPT_CACHING_1H=1;
    • disabling that account removes the flag again.
  • Updated the parent-proxy env-name test to include the flag.
  • pnpm exec turbo run typecheck test --filter=bb-plugin-account-pool: typecheck passes, 12 test files / 349 tests pass. turbo run lint for the plugin passes (two existing warnings in app.tsx, untouched).
  • Mutation check: dropping the enabled filter in routesOnlyApiKeys makes the new test fail.
  • Manual check with Claude Code 2.1.289, one-turn claude -p through a local hub, user settings excluded. The response's usage.cache_creation showed:
    • through the hub without the flag: only ephemeral_5m_input_tokens;
    • same call with ENABLE_PROMPT_CACHING_1H=1: only ephemeral_1h_input_tokens;
    • flag plus a promptCacheTtl: "5m" setting: only ephemeral_5m_input_tokens, so the user's setting wins;
    • same call with the hub env removed (direct subscription login): only ephemeral_1h_input_tokens, which confirms the hub routing is what changes the TTL.

🤖 Generated with Claude Code

AGENT GENERATED

Claude Code picks a 5-minute prompt cache when it runs behind a custom
base URL, so pooled subscription threads lost the 1-hour cache a direct
subscription login gets. Contribute ENABLE_PROMPT_CACHING_1H=1 while a
subscription account (or a parent pool) can serve Claude. API-key-only
pools keep Claude Code's 5-minute default, and an explicit user TTL
setting still wins.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@SawyerHood
SawyerHood merged commit f4ecbaa into get-bb:main Oct 7, 2026
21 checks passed
stephendolan added a commit to stephendolan/bb that referenced this pull request Oct 13, 2026
Incorporate upstream get-bb#5130, get-bb#5226, get-bb#5283 and settings/clipboard fixes. Keep retry availability scoped to durable conversation assignments, including parent pools and spend-control recovery. Build the managed package against BB 0.46.0 SDK 0.6.37.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants