Claude cost cache scales with transcript *file count*: a 51k-file `~/.claude/projects` gives a ~650 MB floor, ~1.2 GB bursts every 15–20 min, and daily disk-write reports (0.74–0.76)
Setup: CodexBar 0.76.0 (Homebrew), macOS 27.0.1, Mac mini M4, 16 GB. Providers: claude (cli), codex, elevenlabs. refreshFrequency adaptive, tokenCostUsageEnabled on, default costReportingPeriod. No plugins.
Scale that the existing benchmarks don't cover: ~/.claude/projects holds 51,488 .jsonl files (9.7 GB). About 7,200 changed in the last 7 days and ~280 in the last day; most come from automated claude -p runs. The cost artifacts in ~/Library/Caches/CodexBar/cost-usage/ carry 51,483 file entries each, and 25,148 of those have zero rows but are still serialized and decoded. Rows: 96.5k in the 30-day artifact, 180.4k in the all-time one. On disk: claude-history-v6.json 70 MB + claude-v6.json 47 MB + the two report memos 35 MB and 24 MB, ≈176 MB of JSON. The benchmarks in #4092 and #4396 use a single transcript with ~24k rows and a ~9 MB artifact, which is about 2,000× fewer files.
Memory trajectory, 0.76.0, footprint -p every 15 min for 2 h 45 min (one launch):
| UTC | footprint | peak |
|---|---|---|
| 15:40 | 720 MB | 1,174 MB |
| 16:10 | 776 MB | 1,203 MB |
| 16:40 | 851 MB | 1,203 MB |
| 17:10 | 642 MB | 1,203 MB |
| 17:40 | 1,209 MB | 1,211 MB |
| 18:10 | 1,070 MB | 1,220 MB |
| 18:25 | 867 MB | 1,220 MB |
That's a floor of ~640–870 MB plus bursts to ~1.2 GB that come back down, on the ~15-minute cost-scan cadence (minimumTokenFetchTTL). It isn't monotonic growth, so it reads as retention plus refresh peaks, not a classic leak (leaks not run). At the 18:25 sample, vmmap -summary: DefaultMallocZone 572.9 MB allocated in 1.35 M allocations, 10% fragmentation, 621.7 MB of it swapped or compressed. footprint: Malloc Large 591 MB in 15 regions, Malloc Small 258 MB. On an earlier 0.75 run, 96% of the footprint sat in the compressor between scans: held, not touched.
Disk writes: macOS logged a disk writes resource report for CodexBar on 7 consecutive days (0.74.0 → 0.75.0), sustained at 106–199 KB/s while over the limit. The heaviest stack ends in pwrite from the CodexBar binary on a serial queue, with no libsqlite frames. That fits the whole-artifact rewrite described in #3882 and #4396. The local cost-usage.sqlite is only 1.8 MB.
Why this is the file-count axis: each scan enumerates and stats every .jsonl under the Claude roots regardless of age. Any changed file then triggers the full reconcile / reprice / re-encode of the whole artifact plus memo (loadClaudeDaily). The all-time Usage & Spend pass can't be bounded from settings. Turning Track costs off is the only lever that stops it.
Possible fixes, smallest first:
- Don't serialize or retain zero-row file entries, or keep them as stamp-only records (here that's half the entries).
- Skip inventory files whose mtime predates the scan window before stat-heavy work. Old transcripts can't contribute rows to a 30-day report.
- Let users bound or disable the all-time Claude pass.
- Long term, move the Claude cache to SQLite, as #2760 did for Codex.
Repro idea: N = 50k synthetic .jsonl files, half with zero usage rows, in a temp Claude root. Append one row, then measure decodes, encodes and submitted bytes per pass with the existing CODEXBAR_REFRESH_BENCHMARK=1 swift test --filter CostUsageClaudeRefreshBenchmarkTests harness.
Related: #3882 (closed; its write and CPU work was noted as still open), #3323, #4486 (asks for a 0.76.0 vmmap/footprint trajectory; this is one), #4512, #2760.
Happy to run a build with instrumentation if that helps.
Codex review: this still needs some work.
Summary Keep open: current main still has file-count-dependent Claude cache work, including a 16,384-file threshold that disables fragment reuse for the reported corpus.
Reproducibility: Current source proves full inventory work, empty-row file retention, and fragment-memo rejection above 16,384 files; the reporter's exact memory and disk measurements remain unverified, and no tests or live probes ran during this read-only review.
Next step Establish a 50,000-file regression across the fragment-memo threshold, measure retained memory and submitted writes, and select a bounded repair that preserves empty-file scan state.
Review details
Best possible solution:
Reduce measured many-file cache overhead while preserving bounded retention, incremental scan metadata, report fidelity, and atomic persistence.
Do we have a high-confidence way to reproduce the issue?
Current source proves full inventory work, empty-row file retention, and fragment-memo rejection above 16,384 files; the reporter's exact memory and disk measurements remain unverified, and no tests or live probes ran during this read-only review.
Is this the best way to solve the issue?
A many-file benchmark should guide a bounded cache optimization; dropping scan state, trusting filesystem age, or increasing memo limits without measurements could worsen performance or lose report fidelity.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
- Source establishes scaling and loss of fragment reuse, but does not attribute the reported memory floor or daily disk-write volume to a single retaining owner.
- Deleting empty-file records can discard parsed offsets and cause repeated full scans; mtime filtering alone does not establish transcript event dates.
- Raising the fragment-count limit can increase retained memory, while a SQLite migration requires separate compatibility and recovery design.
Codex review notes: model internal, reasoning medium; reviewed against a91669f2ff97.
Label changes
Label changes:
No label changes.
Label justifications:
P2: The report establishes substantial resource overhead on a large Claude corpus without demonstrating a current crash or blocked core workflow.impact:other: The concrete impact is excess memory, CPU work, and cache-write volume during local cost tracking.
Evidence reviewed
Acceptance criteria:
- CODEXBAR_REFRESH_BENCHMARK=1 swift test --filter CostUsageClaudeRefreshBenchmarkTests
- swift test --filter CostUsageClaudeFragmentTests
- swift test --filter CostUsageClaudeWriteAmplificationTests
- swift test --filter CostUsageScannerClaudeMemoTests
- swift test --filter CostUsageScannerClaudeSwapTests
What I checked:
- Current default branch verified: GitHub main and the clean review checkout both resolve to a91669f2ff972ac2a549ed8c20725fdc1a510194; the latest release is v0.77.0. (a91669f2ff97)
- Concrete affected-release report: The reporter supplies 0.76.0 configuration, 51,488 transcript files, artifact entry counts, repeated physical-footprint readings, and earlier disk-write reports; these measurements were not independently reproduced.
- File-count threshold defeats fragment reuse: After each save, the fragment memo removes its previous entry and installs the replacement only when files.count is at most 16,384 and the byte budget permits it; a 51,483-entry artifact therefore retains no fragment memo, and subsequent changed saves encode every file again. (
Sources/CodexBarCore/Vendored/CostUsage/CostUsageClaudeFragments.swift:99, a91669f2ff97) - Inventory and empty-file state remain: inventoryClaudeRoots reads a stamp for every nonempty JSONL file before report-memo reuse; processClaudeFile stores file usage and identity even when parsed rows are empty, preserving offsets and change detection. (
Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+Claude.swift:628, a91669f2ff97) - Changed inventories still trigger global report work: Changed source inventories invalidate report reuse; loadClaudeDaily then reconciles cached rows, rebuilds aggregates, constructs the report, and saves the artifact and report memo. (
Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+Claude.swift:811, a91669f2ff97) - All-history scan is independent of display selection: The independent dashboard refresh uses SpendDashboardSource.scanDays, which resolves All available history; cache URLs separate regular and dashboard windows because parsing filters dates before duplicate selection. (
Sources/CodexBar/SpendDashboardController.swift:177, a91669f2ff97)
How this review workflow works
- ClawSweeper keeps one durable marker-backed review comment per issue or PR.
- Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
- A fresh review can be triggered by eligible
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch. - PR/issue authors and users with repository write access can comment
@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only. - Maintainers can also comment
@clawsweeper reviewto request a fresh review only. - Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge; those execution lanes are retired.
- Maintainers can comment
@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.
Reviewed October 16, 2026, 5:42 PM ET / 21:42 UTC.
Two follow-up readings from the same machine and the same 0.76.0 launch:
- Peak: by 21:37 UTC, three hours after the last table row, that same process reported
phys_footprint_peak: 4423 MB(current footprint 1,396 MB). That's about 4× the largest peak in the table above. - Control: with Track costs turned off and the app restarted, the footprint is 56–57 MB (peak 113 MB), steady over three readings 5–7 min after launch. Same providers otherwise.
So on this machine essentially all of the memory, and the disk writes, belong to the Claude cost-scan path. A 51k-file transcript tree takes it from ~56 MB to a 640–1,400 MB working range, with peaks up to 4.4 GB.
Thanks @cristbc, the file-count reproduction pinned this down. On a synthetic 50,000-transcript tree, an unchanged refresh is cheap (about half a second of CPU and no reads or writes), but a single appended response, which is what happens on most refreshes while a session is active, re-encodes all 50,000 per-file fragments and reads and rewrites the whole Claude cost cache, about 33 MB each way and several seconds of CPU.
Two quick fixes didn't hold up when measured (a faster directory walk and keeping more fragments in memory), and directory modification times can't be used as a shortcut because an append doesn't change them. The real fix is making the cache persist incrementally, so a change rewrites only the affected part. That work is in progress, with explicit gates on I/O, CPU and byte-identical results before it ships.
Fixed in #4638 (8fa003e092fe). Thanks @cristbc! The Claude cost cache is now split into per-project pieces behind a manifest, so a refresh after an append only rewrites the project that changed. On a 50,000-file synthetic history, one appended response went from about 33 MB read and 33 MB written per refresh to about 0.2 MB each, and CPU dropped from roughly 8 to 3.4 seconds, with identical cost results. Existing caches migrate on their next save without rescanning your transcripts. It will be in the next release.
Thanks for the fix and the quick turnaround. I re-tested on 0.79.0 against the same machine and the same kind of corpus, which has grown since I filed: 55,349 .jsonl files, 13 GB (was 51,488 / 9.7 GB). Result: the memory part of #4598 is still there, so I'm leaving this here in case it's worth reopening or tracking separately. I measured memory only; I did not re-measure disk writes, so I can't speak to the I/O half of your fix.
Setup: CodexBar 0.79.0 (Homebrew), macOS 27.0.1, Mac mini M4, 16 GB. Same providers as before. tokenCostUsageEnabled was the only setting changed.
What I ran (100 min, one fresh launch, Track costs ON):
defaults write com.steipete.codexbar tokenCostUsageEnabled -int 1 # quit, set, relaunch
# every 5 min:
footprint -p <pid> # Footprint and phys_footprint_peak
vmmap -summary <pid>
# every 15 s (guard, so a runaway could be stopped):
footprint -p <pid>; sysctl -n kern.memorystatus_vm_pressure_level
Results beside the 0.76.0 numbers from this issue:
| 0.76.0 | 0.79.0 | |
|---|---|---|
| sample footprint, min–max | 642–1,209 MB (12 samples, 15 min apart) | 537–1,509 MB (20 samples, 5 min apart) |
| sample median | 851 MB | 569 MB |
| 15 s polls | not taken | 397 polls: min 533, median 573, p90 1,130, max 1,642 MB; 50 polls over 1,000 MB |
phys_footprint_peak |
1,220 MB (4,423 MB seen later on that launch) | 1,659 MB |
| Track costs off | 56–70 MB | 56 MB |
The quiet floor between scans is a bit lower than on 0.76.0 (about 540–575 MB vs 640–850 MB). Bursts to 1.5–1.66 GB happened on four scan cycles and are as large as or larger than before, and there was a 7-minute plateau at ~990 MB with no burst. So peak is not back near 1.2 GB, and both numbers are roughly 8–30× the Track-costs-off footprint. The 4.4 GB launch from the earlier run didn't recur, but that was one launch and I only have one launch here.
I know the 0.79.0 note says "back to pre-0.78 levels." My earlier numbers were from 0.74–0.76, so that note may be true and still leave this cost in place.
The cache is still one entry per transcript file, empty ones included. After the run, ~/Library/Caches/CodexBar/cost-usage/ has a small index per artifact plus a .fragments/ directory of 492 hashed files each (54 MB and 78 MB, 212 MB total with memos). Counting entries inside the fragments:
cd ~/Library/Caches/CodexBar/cost-usage
cat claude-v6.json.fragments/*.json | jq -s '[.[]|to_entries[]|.value]
| {entries:length, zero_rows:(map(select((.usage.claudeRows//[])|length==0))|length)}'
| artifact | entries | zero-row entries |
|---|---|---|
claude-v6 (30-day) |
55,375 | 28,663 (52%) |
claude-history-v6 (all-time) |
55,375 | 761 |
Entries track the transcript count (55,349 files at the start of the run), and half of the 30-day artifact is zero-row entries, as before. The ClawSweeper review here mentioned a 16,384-file threshold that disables fragment reuse; I couldn't check whether that still applies in 0.79.0, but my corpus is well above it, so it may be worth a look.
To reproduce without my data: the harness you already used (50,000 synthetic transcripts, about half with zero usage rows) with a memory read added: run a refresh pass after appending one row and record footprint -p / phys_footprint_peak during the pass, not just CPU and bytes. Stock footprint and vmmap are enough; no instrumentation needed.
I have the 20 per-sample footprint/vmmap captures and the 15 s poll log if they'd help. Happy to run an instrumented build or a branch against this corpus.
Update from the same machine, now on 0.82.0 with Track costs ON and a smaller corpus (43,929 .jsonl files, 10 GB). From a fresh launch, phys_footprint_peak reached 4,397 MB over about 10.5 hours. That matches the 4,423 MB peak I reported on 0.76.0 and is well above the 1,659 MB I measured on 0.79.0, though that run was only a 100-minute window. So the memory part of this issue still looks open at this size.
Two caveats. My sampler stopped five minutes in, when the peak so far was 1,441 MB, so I have no trajectory and can't say when the 4.4 GB happened. And one run on 0.80 with Track costs OFF hit 3.8 GB once, so I can't pin every spike on the cost scan.
Track costs is back OFF here, where 0.82.0 sits at about 55 MB. I kept the footprint and vmmap output if either would help.