Skip to content

feat(history): retain usage and recover Claude records - #97

Merged
ericjypark merged 1 commit into
mainfrom
codex/durable-usage-recovery
Sep 11, 2026
Merged

ericjypark merged 1 commit into
mainfrom
codex/durable-usage-recovery

Conversation

@ericjypark

@ericjypark ericjypark commented Sep 11, 2026

Copy link
Copy Markdown
Owner

Usage captured from local provider logs now remains available after those logs are removed. A local SQLite archive preserves per-day records, deduplicates repeated scans, retains long-term totals, and lets the app rebuild recent usage without depending on the original session files.

Settings now offers Claude usage recovery with a read-only preview, explicit timezone selection for older daily snapshots, and a backup before an atomic import. The same flow is available through the bundled recovery command. Recovery uses saved counters only, excludes unsupported records, and does not access login credentials or message text.

Validation: the full repository test runner passes, including 47 archive checks, 45 recovery checks, and 20 recovery UI-state checks. The production app builds for Intel and Apple Silicon; bundle metadata, Sparkle configuration, and deep code-signature verification pass. The packaged recovery command's help works, and the recovery flow was also exercised in the native Settings UI during development.

GitHub security scan passes. The optional Claude review did not execute because its CI account returned HTTP 403 (oauth_org_not_allowed); it produced no review findings. Manual source review and the local validation above completed before merge.

Summary by CodeRabbit

  • New Features

    • Added durable local usage-history storage across supported providers.
    • Added a Claude usage recovery workflow in Settings, including previews, timezone selection, optional source imports, backups, and rollback protection.
    • Added a command-line recovery option and bundled recovery script.
    • Added English and Simplified Chinese localization for recovery flows.
  • Bug Fixes

    • Improved duplicate scan handling and recovery of missing Claude usage.
    • Expanded usage summaries to include recovered historical totals.
  • Documentation

    • Documented usage-history storage, recovery options, limitations, and testing tools.

@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: cf8a0b63-1dd3-4130-a873-977f6b47e3ed

📥 Commits

Reviewing files that changed from the base of the PR and between c507f1d and b6fe69c.

📒 Files selected for processing (30)
  • README.md
  • Resources/en.lproj/Localizable.strings
  • Resources/zh-Hans.lproj/Localizable.strings
  • Sources/App.swift
  • Sources/Cost/AntigravityLogReader.swift
  • Sources/Cost/ClaudeLogReader.swift
  • Sources/Cost/CodexLogReader.swift
  • Sources/Cost/CostStore.swift
  • Sources/Cost/CostSummary.swift
  • Sources/Cost/CostUsage.swift
  • Sources/Cost/GrokLogReader.swift
  • Sources/Cost/HistoricalUsageDay.swift
  • Sources/Cost/LogParseCache.swift
  • Sources/Cost/OpenCodeLogReader.swift
  • Sources/Cost/TokenEvent.swift
  • Sources/Cost/UsageLedger.swift
  • Sources/Recovery/ClaudeRecoveryModel.swift
  • Sources/Recovery/ClaudeUsageRecovery.swift
  • Sources/Views/Settings/ClaudeRecoveryView.swift
  • Sources/Views/SettingsView.swift
  • Tests/ClaudeRecoveryModelTests.swift
  • Tests/ClaudeUsageRecoveryTests.swift
  • Tests/LocalProviderCostTests.swift
  • Tests/UsageLedgerTests.swift
  • build.sh
  • docs/USAGE-HISTORY.md
  • scripts/recover-claude-usage.sh
  • scripts/run-tests.sh
  • scripts/test-claude-recovery.sh
  • scripts/test-usage-ledger.sh

📝 Walkthrough

Walkthrough

The change adds durable SQLite usage history, stable event identity, historical daily aggregates, and Claude usage recovery from logs and backups. It adds recovery controls in Settings, a command-line entry point, localized strings, bundled scripts, documentation, and executable test coverage.

Changes

Usage history capture and aggregation

Layer / File(s) Summary
Event identity and log ingestion
Sources/Cost/TokenEvent.swift, Sources/Cost/*LogReader.swift, Sources/Cost/LogParseCache.swift
Scans support all-time and custom-root operation. Events receive stable IDs and aliases. Claude scanning includes Cowork logs and replaces incomplete streaming rows.
SQLite ledger and cost summaries
Sources/Cost/UsageLedger.swift, Sources/Cost/HistoricalUsageDay.swift, Sources/Cost/CostSummary.swift, Sources/Cost/CostUsage.swift, Sources/Cost/CostStore.swift, Tests/UsageLedgerTests.swift, Tests/LocalProviderCostTests.swift
UsageLedger stores events and historical daily totals with transactional validation. CostStore retains provider scans and CostSummary includes recovered and unpriced usage in history buckets.

Claude usage recovery

Layer / File(s) Summary
Recovery preparation and application
Sources/Recovery/ClaudeUsageRecovery.swift, Sources/App.swift, Tests/ClaudeUsageRecoveryTests.swift
The recovery pipeline parses options, scans Claude sources and legacy caches, creates isolated previews, validates totals and time zones, creates database backups, and applies verified records.
Recovery state and interface
Sources/Recovery/ClaudeRecoveryModel.swift, Sources/Views/Settings/ClaudeRecoveryView.swift, Sources/Views/SettingsView.swift, Tests/ClaudeRecoveryModelTests.swift
The model manages scan and save state. Settings presents the recovery sheet, source selection, previews, errors, and results. Successful recovery refreshes cost data and posts a notification.

Distribution and support

Layer / File(s) Summary
Localization, scripts, and documentation
Resources/*/Localizable.strings, scripts/*, build.sh, README.md, docs/USAGE-HISTORY.md
Localization covers recovery states and validation messages. Build and test scripts include recovery resources and test runners. Documentation describes local history and recovery usage.

Estimated code review effort: 5 (Critical) | ~90 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Settings
  participant ClaudeRecoveryModel
  participant ClaudeUsageRecovery
  participant UsageLedger
  Settings->>ClaudeRecoveryModel: start scan
  ClaudeRecoveryModel->>ClaudeUsageRecovery: prepare recovery preview
  ClaudeUsageRecovery->>UsageLedger: simulate against saved history
  UsageLedger-->>ClaudeUsageRecovery: return preview snapshot
  ClaudeUsageRecovery-->>ClaudeRecoveryModel: return preview or error
  Settings->>ClaudeRecoveryModel: save preview
  ClaudeRecoveryModel->>ClaudeUsageRecovery: apply recovery
  ClaudeUsageRecovery->>UsageLedger: create backup and save records
  UsageLedger-->>ClaudeRecoveryModel: return outcome
  ClaudeRecoveryModel-->>Settings: refresh usage and show result
Loading
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/durable-usage-recovery

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ericjypark
ericjypark merged commit b5bbd84 into main Sep 11, 2026
2 of 3 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