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:
@@ -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()
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user