Skip to content

Add manual Claude Code weekly reset contributions - #41

Merged
starkdmi merged 4 commits into
mainfrom
ai/claude-weekly-reset-125f
Sep 29, 2026
Merged

starkdmi merged 4 commits into
mainfrom
ai/claude-weekly-reset-125f

Conversation

@starkdmi

@starkdmi starkdmi commented Sep 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

A Claude Code account can store one manual weekly reset anchor. Completed weeks are emitted as the existing quota_cycle_contribution.v1 records when this device has attributed usage in the week or on a boundary UTC day. The cycle that contains now is never emitted, and weeks with no such usage are omitted so the backend can fill them.

Anchors that differ by a whole number of weeks are the same schedule. account merge transfers a schedule, keeps one copy when the phases match, and refuses the merge when they differ. Those writes share the rest of the merge in one transaction. If a later check fails, such as overlapping subscriptions, both accounts keep the schedules they had. account remove treats a stored schedule as a reference.

Automatic capture from the status line is future work. This change only stores a manual anchor.

The boundary-day lookup needed an index on provider, account, and start time. EXPLAIN QUERY PLAN showed the existing provider/source index cannot bound that read.

Manual weekly contributions honor the same quota query filters as reconstructed cycles. A provider other than Claude Code returns none. An account filter limits the anchors. A source filter reads only that source. Any limit filter returns none, because these cycles have no limit id. A cycle is kept only when its half-open week overlaps from and to.

Boundary-day events are read as one indexed range per UTC day and combined with UNION ALL. Each range keeps the start-time bound on the provider, account, and start index. An OR of those same ranges does not: bundled SQLite then scans the account's whole history.

Testing

  • cargo fmt -p statsai-store -p statsai
  • cargo clippy -p statsai-store --all-targets -- -D warnings
  • cargo clippy -p statsai --all-targets -- -D warnings
  • ./scripts/rust-ci.sh full
  • Follow-up: cargo fmt -p statsai-store -p statsai, cargo clippy -p statsai-store -p statsai --all-targets -- -D warnings, cargo test -p statsai-store --lib quota::tests::weekly, and cargo test -p statsai --bin statsai merge_
Open in Web Open in Cursor 

cursoragent and others added 4 commits September 29, 2026 11:58
A Claude Code account can store one manual UTC weekly reset. Completed
weeks are emitted as the existing quota cycle contributions when this
device has attributed usage in the week or on a boundary UTC day. Weeks
with no such usage are omitted, and the cycle that contains now is never
emitted.

Anchors that differ by a whole number of weeks are the same schedule.
Merging accounts transfers a schedule, keeps one copy when the phases
match, and refuses the merge when they do not. Removing an account
treats a stored schedule as a reference.

Usage for these contributions is read only for the Claude Code account
and only on the boundary days. EXPLAIN QUERY PLAN showed the existing
provider/source index cannot bound that lookup, so this adds an index
on provider, account, and start time.

Co-authored-by: Dmitry Starkov <21260939+starkdmi@users.noreply.github.com>
Manual cycles now follow the same source, limit, and time filters as
reconstructed cycles. A query for another source, a provider limit, or a
date range that misses the week no longer returns that week's contribution.

Co-authored-by: Dmitry Starkov <21260939+starkdmi@users.noreply.github.com>
An OR of many UTC day ranges made bundled SQLite use only the provider
and account prefix, so each sync scanned the account's full history.
Each day is now its own indexed range, combined with UNION ALL.

Co-authored-by: Dmitry Starkov <21260939+starkdmi@users.noreply.github.com>
Anchor moves now share the merge transaction. An overlapping subscription
rejects the merge and leaves both accounts' schedules where they were.
Summary rewrites and sync-tracking clears join that transaction instead
of starting a second one.

Co-authored-by: Dmitry Starkov <21260939+starkdmi@users.noreply.github.com>
@starkdmi
starkdmi marked this pull request as ready for review September 29, 2026 15:18
@starkdmi
starkdmi merged commit b512f69 into main Sep 29, 2026
6 of 7 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.

2 participants