Skip to content

fix: preserve Codex cache usage in Claude messages - #29

Merged
treeleaves30760 merged 1 commit into
mainfrom
fix/codex-cache-usage
Sep 18, 2026
Merged

treeleaves30760 merged 1 commit into
mainfrom
fix/codex-cache-usage

Conversation

@treeleaves30760

Copy link
Copy Markdown
Owner

Summary

Fix Codex cache usage being reported as ordinary input when using Claude Code through ALC. The upstream response contains aggregate cache details, but the typed usage decoder discarded them and the Messages conversion always emitted zero cache counts.

  • Preserve optional cache-read and cache-write input details, including absent/null fields.
  • Translate inclusive OpenAI input into disjoint Anthropic buckets: ordinary input = total input − cache reads − cache writes. Preserve output (which already includes reasoning) and model identity.
  • For inconsistent cache breakdowns, preserve gross input/output and omit cache fields instead of underflowing, double-counting, or failing the response.
  • Keep Chat Completions prompt totals inclusive; no Chat production behavior changes.

Validation

  • Added regressions first: both Messages tests failed on the previous implementation (input=100/read=0/write=0 instead of input=20/read=60/write=20). They pass with the fix.
  • Synthetic completed/incomplete SSE → production decoder/translator → wire serialization and nonstream collection, including final-count replacement and duplicate-terminal suppression.
  • Cases cover positive reads/writes, all-cached input, absent/null details, invalid breakdowns, and u64::MAX boundaries. Original captured fixtures remain unchanged.
  • cargo fmt -- --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test --all-targets --all-features: 571 unit tests + 66 integration tests passed locally on macOS.
  • JavaScript syntax checks and 52 existing Node tests passed.

Local Rust checks used the separately installed Command Line Tools SDK (DEVELOPER_DIR=/Library/Developer/CommandLineTools) because the default Xcode installation requires license acceptance; no system configuration was changed.

Boundaries

No pricing changes, ledger schema changes, historical JSONL rewriting, or dependency updates. This fixes newly emitted bridge usage. Existing Claude logs cannot recover discarded cache details merely by recalculating prices. Actual Claude Code JSONL persistence / live upstream HTTP behavior was not exercised; coverage here is the production SSE translation/serialization and collection path. No better-ccusage package execution or paid upstream calls were used.

🤖 Generated with Claude Code

Translate aggregate cache reads and writes into disjoint Anthropic input categories, keeping OpenAI totals and output usage unchanged. Cover terminal SSE, collected responses, optional details and inconsistent counters.

Co-Authored-By: Claude Code <[email protected]>
@treeleaves30760
treeleaves30760 merged commit b78b407 into main Sep 18, 2026
5 checks passed
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.

1 participant