feat(ratelimit): persist window token counters across restarts

Save window state (resets_at + token counts) to ~/.claude/ on shutdown
and every poll cycle. On startup, restore counters if the window hasn't
rolled over. Fixes token counters resetting to zero on deploy.
This commit is contained in:
Alexander
2026-04-14 14:07:28 +02:00
parent b864092dad
commit 273213cbed
2 changed files with 92 additions and 1 deletions
+3 -1
View File
@@ -45,14 +45,16 @@ func NewTracker(tokenFn func() string) *Tracker {
// Start begins the background poll loop.
func (t *Tracker) Start(ctx context.Context) {
go func() {
// Poll immediately on start
t.poll(ctx)
t.Restore()
for {
select {
case <-ctx.Done():
t.Save()
return
case <-time.After(5 * time.Minute):
t.poll(ctx)
t.Save()
}
}
}()