fix(anthropic-subscription): read the prompt-cache lifetime from loaded settings files (senpi#2988)
Summary
Fixes senpi#2988 item 4 (settings-file lifetime invisible to the pin). The one-shot pin only saw process env and query-options env, so a FORCE_PROMPT_CACHING_5M / CLAUDE_CODE_PROMPT_CACHE_TTL set in a loaded settings file was invisible: on a managed lane the pin defaulted to 1h while Claude Code used the settings 5m, and the 1h breakpoint could then be rejected by the Messages API (the exact failure senpi#2982 fixed for explicit env).
- New
claude-settings-env.ts: resolves the effective settingsenvwith the SDK's ownresolveSettingsmerge engine (same files, lookup rules and precedence as the CLI), for exactly the sources the attempt loads (explicitsettingSources, or user/project in preset-append ambient mode). Resolution failure falls back to the old pin behavior instead of failing the turn. pinOneShotPromptCacheTtltakes the settings env as a fourth input. Precedence: explicit env > settings env > lane default. The pin still writes the final lifetime into query-options env, so what Claude Code receives matches the breakpoint.stream.tsresolves the settings env once per stream and passes it to the pin only for attempts whosesettingSourcesare non-empty (managed lanes load none).
Items 1 (ambient lane breakpoint) and 2 (wide tool turns) of #2988 stay open; this PR covers item 4 only.
Evidence
- RED: new regression file
test/suite/regressions/2988-anthropic-subscription-settings-env-cache-ttl.test.tsfailed before the fix (missing module import). - GREEN: 11/11 pass in that file (pin table incl. ambient + settings TTL, reader with injected resolver, failure fallback).
- Neighbors: 40/40 pass —
2982-anthropic-subscription-one-shot-cache-ttl,2982-anthropic-subscription-append-only-prompt-capture, and the three cold-seed suites. bun run check(root): clean — oxlint 0 warnings, fmt clean, tsc clean in both projects, install locks up to date.- No live-provider QA in this PR; tests are offline (fake resolver, no real credentials, no network).
Notes
- CLA: the CLA for this repo is pending the user's own signature; not signed here, please do not treat this PR as CLA-complete.
- Change fragment (
changes/unreleased/<PR#>.md) to follow once the PR number is assigned.
Summary by cubic
Makes the one-shot prompt-cache pin read the effective env block of loaded settings files, so its breakpoint matches the lifetime Claude Code actually applies. Previously a FORCE_PROMPT_CACHING_5M/CLAUDE_CODE_PROMPT_CACHE_TTL in a settings file was invisible: managed lanes pinned 1h while Claude Code used the settings 5m, and the 1h breakpoint could be rejected by the Messages API.
- New
claude-settings-env.tsresolves the effective settings env with the SDK'sresolveSettingsmerge engine, matching the CLI's files, lookup rules, and precedence; resolution failures fall back to the old pin behavior. - Precedence is now settings env > explicit env (options/process) > lane default, since Claude Code writes each settings source's env over the process env on an SDK spawn.
- The pin only receives settings env for attempts whose
settingSourcesare non-empty; managed lanes load none, so nothing changes there. - The lazy SDK module also loads
resolveSettings, and a change fragment documents the fix.