Skip to content

Fix Claude plan-usage parse for new claude.ai page format#32

Merged
BlockedPath merged 2 commits into
mainfrom
fix/claude-usage-regex
May 22, 2026
Merged

Fix Claude plan-usage parse for new claude.ai page format#32
BlockedPath merged 2 commits into
mainfrom
fix/claude-usage-regex

Conversation

@BlockedPath

Copy link
Copy Markdown
Owner

Summary

  • Daemon was reporting `s:0, w:0` again because `claude-plan-usage.json` stopped refreshing — claude.ai changed the usage page wording so the old regexes never matched. Sessions can now show `Resets in 32 min` (no `hr` component) and the weekly window switched from `Resets Fri 7:00 PM` to `Resets in 12 hr 22 min`. Logs were full of `Claude usage text did not include recognizable plan usage` for ~5 hours.
  • Rewrote `parse_usage_text` to anchor on the "Current session" / "All models" section headers, then independently extract "X% used" and a reset window (either `Resets in [N hr] [M min]` or the legacy `Resets Fri 7:00 PM` form).
  • Tightened `claude_plan_usage_snapshot` to require both windows, matching the fix already applied to `claude_hook_limits_snapshot` in Fix Claude 0/0 usage with multi-source limits + auto-refresh #29 — otherwise a partial scrape would silently show 100% remaining for the missing window.

Test plan

  • `pytest -q` (11 passed)
  • `ruff check daemon/ scripts/` clean
  • Restart daemon, hit `http://localhost:9596/usage\` → `{"s":37,"sr":32,"w":78,"wr":742,"st":"5h 63% used · 7d 22% used"}` matches what the page renders right now.
  • Verify iOS app updates within ~2 min.

🤖 Generated with Claude Code

claude.ai changed the usage page wording. Sessions can now show
"Resets in 32 min" (no hr component) and the weekly window changed from
"Resets Fri 7:00 PM" to "Resets in 12 hr 22 min". The old regexes never
matched either, so claude-plan-usage.json stopped refreshing and the
daemon fell through to the 200k-token-budget path → s:0, w:0.

- Rewrite parse_usage_text to anchor on section headers then extract
  duration/wall-clock resets independently, accepting both new and
  legacy phrasings.
- Make claude_plan_usage_snapshot require both windows so a partial
  payload can't show a phantom 100% remaining for the missing one
  (same fix already applied to claude_hook_limits_snapshot).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ea0ff80522

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/claude-plan-usage-cache.py Outdated
`_parse_duration_reset() or _parse_weekday_reset()` evaluated the
duration result as falsy when it was 0, dropping valid boundary cases
like "Resets in 0 min" and emitting a partial payload that
claude_plan_usage_snapshot now rejects. Use an explicit None check.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@BlockedPath
BlockedPath merged commit 2db21bc into main May 22, 2026
4 checks passed
@BlockedPath
BlockedPath deleted the fix/claude-usage-regex branch May 22, 2026 16:44
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