TIL: You can read Claude Code quota locally (no scraping, no API)

  • Posted 3 hours ago by micaeked
  • 3 points
~/.claude/settings.json:

  {
    "statusLine": {
      "type": "command",
      "command": "cat > ~/.claude/statusline_raw.tmp && mv ~/.claude/statusline_raw.tmp ~/.claude/statusline_raw.json; exit 0"
    }
  }
cat ~/.claude/statusline_raw.json | jq '.rate_limits'

  {
    "five_hour": {
      "used_percentage": 105,
      "resets_at": 1776441600
    },
    "seven_day": {
      "used_percentage": 34,
      "resets_at": 1776970800
    }
  }
A couple implementation details:

- The command must exit 0, otherwise Claude Code treats it as a failure

- It should not write anything to stdout, or it will show up in the UI

- Writing with `tmp && mv` avoids partial reads if something else is consuming the file

- The quota data is not present until the first request comes back

This is actually somewhat documented (the `statusLine` command receives structured JSON on stdin, including `rate_limits`), but I didn't notice till recently.

I was trying to build a small widget that shows current quota usage, updates live, and notifies me when the 5-hour window resets if I've run out.

1 comments

    Loading..