AI tips · No. 5
2026-10-13

Read every AI plan's real usage, and queue work for what's left

Every vendor already has a usage counter you can read for free. Read it, then give the capacity you'd otherwise lose to a queue.

This replaces No. 3, which estimated usage from tokens and my own readings. Using an AI agent? Point it at this page; there is a section for it at the bottom.

The problem

I pay for four AI plans: Claude, ChatGPT (for Codex), SuperGrok and Google AI Pro. Each has a weekly limit and most have a five-hour one, and every one resets on its own clock. For a month my meter estimated two of them from token counts and the numbers I copied off /usage now and then.

Then I checked it. The meter said 53% of my Claude week was gone. Claude said 32%. It had the five-hour block ending at 18:30 when the real one reset at 22:19, because it could only see the sessions on one of my three machines. And Grok's week had quietly moved from Tuesday night to Tuesday morning, so the meter showed 30% used of a week that had already reset.

An estimate that far off is worse than none. I wanted to queue work for the spare capacity, and that only works if the number is real.

Ask the vendor

Each vendor's own command-line tool already knows the real numbers, because its usage screen has to show them. All four can be asked from a script, with the login you already have, for no tokens and no API key:

  • Claude: GET /api/oauth/usage on api.anthropic.com, with Claude Code's own login token, which is the call /usage makes. It returns the five-hour session, the week, and the per-model weekly limit, each with its percentage and exact reset time. /api/oauth/profile names the plan: Max 20x, Max 5x, Pro.
  • Codex: start codex app-server and send it one JSON-RPC request, account/rateLimits/read. Back come the five-hour and weekly percentages, the resets, and planType. These are the server's numbers, so they include use from your other machines and from ChatGPT's own apps.
  • Grok: start grok agent stdio and send _x.ai/billing. It returns the weekly limit's percentage and the exact week, and _x.ai/auth/check_subscription names the plan.
  • Gemini, through Antigravity: agy -p /usage --output-format json reports the weekly and five-hour windows of each model group. It doesn't name the plan.

One script reads all four in about five seconds, every 20 minutes, and between reads the meter adds the tokens spent since. The plan names come through too. I change plans often, so the price of each one is looked up from the plan the vendor reports, and a plan the meter has never seen gets flagged instead of priced with a guess. The live numbers are on moraineworks.com.

The queue

A weekly limit that resets with room left is money spent on nothing. So I keep a queue of jobs, and each evening it spends what I haven't used, by one rule:

line = 10% × the day of that plan's week (counted from its own reset), at most 70%
room = line − what's already used
  • My own use counts first. On a heavy day the room is zero and the queue does nothing. On a quiet day it fills the gap. A week ends near 70%, and the last 30% is always mine.
  • It spends after 9 pm, and in the last two hours before a plan's own reset, when the alternative is losing it.
  • One job at a time, each with a time limit. Every five minutes the runner reads the counters again and stops a job whose plan has gone past the line.
  • Every job runs in a fresh copy of the repo, behind a wall: no SSH or GitHub keys, so a push is impossible rather than merely forbidden. Nothing on my network is reachable, only the internet. CPU and memory are capped.
  • Results come back as a branch for review. Nothing is merged unread, and nothing is ever pushed by the queue.
  • I add jobs from my phone, in a tab of my task board, and drag them into order.

What bit

  • Never refresh the login yourself. Read the token Claude Code keeps, and skip the read if it has expired. A refresh rotates the token under every session that's running, and the next Claude session refreshes it anyway.
  • Codex's protocol has a "spend a reset credit" call right beside the read. Don't let a script anywhere near it.
  • Grok's extension methods need a leading underscore. x.ai/billing answers "method not found"; _x.ai/billing works.
  • A window you've never opened reports a reset that slides. Antigravity says 100% left, resetting "a week from now", every time you ask. That isn't a reset time, so store none.
  • One machine's logs aren't the account. The whole reason for the old meter's 21-point error.
  • Claude Code wouldn't start an unattended Claude for me. When my session tried to launch a Claude worker for the queue's first test, its safety check refused, and it was right to. Whether agents run unsupervised is the owner's decision, so that first run is mine to start.

The result

The meter matches every vendor's own page, on every plan, and I no longer copy numbers off /usage. The capacity that used to expire now goes to a queue that knows exactly how much it may spend.

For your AI agent

This part is written for your agent. Paste something like this into Claude Code:

Read https://jacobkunselman.com/tips/real-usage-and-a-spare-capacity-queue/agent.md
and set up the real-usage readers for the AI plans I have. Then build the
queue, with its sandbox, but leave its timer off until I say.

agent.md is the plain-text spec: each vendor's call and the fields it returns, the safety rules, the budget rule, the sandbox, and acceptance tests. The reference files:

  • plan-usage.py: reads all four counters (Python, standard library only)
  • budget.py: the line, the room, and when a plan may spend
  • sandbox.py: the wall each job runs behind (bubblewrap inside a systemd scope)