- Shell 100%
jq's strflocaltime gets the offset wrong in the repeated hour when daylight saving time ends (2026-10-25 02:00 CEST printed as +0100). Times stay Unix seconds internally; messages and logs now print them as UTC (...Z). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|---|---|---|
| config.json | ||
| install.sh | ||
| LICENSE | ||
| README.md | ||
| SKILL.md | ||
| test.sh | ||
| usage-pacing.sh | ||
usage-pacing
A Claude Code skill with hooks that paces autonomous work against the subscription's rate limits: the weekly budget is used evenly up to its reset, and agents never run into the 5-hour limit mid-task.
- The status line records the rate limits Claude Code hands it and shows
5h 50%/76% (-26) · week 10%/47% (-37)(used/target (distance); a distance above target in red as+N), plus each model-specific weekly limit (e.g.· Fable 0%/63% (-63)) where the plan has one;<name> resetfor a window that has ended and(N min ago)once the oldest value is 5 min old. - Hooks tell each session (and each subagent) its pacing state —
behind,tight,ahead,reserve, … — and wake idle sessions when it changes. SKILL.mdtells agents what each state means and how to react.
Requirements
- A Pro or Max plan: only then does Claude Code pass
rate_limitsto the status line (from the first answer of a session on). bash,jq, coreutils,setsid(util-linux); theclaudeCLI inPATHfor background refreshes.
Installation
Clone the repository as a skill directory:
git clone <repository URL> ~/.claude/skills/usage-pacing
(or copy its files there; keep the scripts executable). Update later
with git -C ~/.claude/skills/usage-pacing pull; running sessions pick the
new script up with their next hook call and are told to load a changed
SKILL.md again. Then run, in a terminal or in a
session with the ! prefix:
~/.claude/skills/usage-pacing/install.sh --dry-run # show the diff
~/.claude/skills/usage-pacing/install.sh
It adds the entries below to ~/.claude/settings.json (or
$CLAUDE_CONFIG_DIR/settings.json): it keeps every other hook, replaces
only its own entries (so it can run again, e.g. after an update), writes
through a symlinked settings file, asks before replacing a status line of
yours and keeps a backup in ~/.claude/usage-pacing/. Without a terminal
to ask on (possibly the ! prefix), the question reads no answer and your
status line stays; yes | install.sh replaces it. To add them by hand
instead (merge with existing hooks):
{
"statusLine": {
"type": "command",
"command": "~/.claude/skills/usage-pacing/usage-pacing.sh --statusline",
"refreshInterval": 60
},
"hooks": {
"SessionStart": [{ "hooks": [{ "type": "command",
"command": "~/.claude/skills/usage-pacing/usage-pacing.sh --watch" }] }],
"CwdChanged": [{ "hooks": [{ "type": "command",
"command": "~/.claude/skills/usage-pacing/usage-pacing.sh --watch" }] }],
"PostToolUse": [{ "hooks": [{ "type": "command",
"command": "~/.claude/skills/usage-pacing/usage-pacing.sh --check" }] }],
"SubagentStart": [{ "hooks": [{ "type": "command",
"command": "~/.claude/skills/usage-pacing/usage-pacing.sh --check" }] }],
"UserPromptSubmit": [{ "hooks": [{ "type": "command",
"command": "~/.claude/skills/usage-pacing/usage-pacing.sh --check" }] }],
"FileChanged": [{ "hooks": [{ "type": "command",
"command": "~/.claude/skills/usage-pacing/usage-pacing.sh --wake",
"asyncRewake": true }] }]
}
}
Notes:
- The script must be executable (
chmod +x *.sh) when copied instead of cloned;cp -rmay drop the bit. - Claude Code has one status line.
install.shasks before replacing an existing one; to keep yours, callusage-pacing.sh --statuslinefrom your own status line script with the same JSON on stdin and print its output where you want it. Without the status line nothing is recorded except what the background fetch finds. - Hooks are user-level so that every project and every subagent gets them;
hooks in a project's
.claude/settings.jsonwork too, but only there. - Changes apply to sessions started afterwards. The status line shows
numbers from the first answer of a session on (before that Claude Code
has no
rate_limitsto pass).
Optionally point agents at the skill in ~/.claude/CLAUDE.md, e.g.:
"Before dispatching subagents, workflows or long autonomous work, follow
the skill usage-pacing." The skill's description triggers it already;
skip the line where CLAUDE.md has to stay small.
For agents
Do not edit the user's settings, hooks, status line or CLAUDE.md yourself
to install this skill: Claude Code's auto mode refuses that as
self-modification, and after a refusal it may block related reads too.
Hand the user the command instead (! ~/.claude/skills/usage-pacing/install.sh),
or get their explicit permission to change your own configuration first.
How the messages reach agents
--checkruns as PostToolUse hook in the main session and in every subagent (Claude Code passesagent_idthere); its message arrives asadditionalContextright after the tool result, so the agent sees it with its next step. Each session and subagent is told separately.- A subagent has no status line: its first report, at SubagentStart (or,
without that hook, after its first tool call), names every limit with
the session's targets, grants included, whatever the state; after a
--grantfor its session (orall) it gets this report again. - A new counter anomaly (
anomalies.log) is reported once to the main sessions asUSAGE ANOMALY; it also wakes idle ones. - UserPromptSubmit adds the message to the user's prompt (main session).
- An idle session (no tool calls, no prompts) is reached through
--wake: the status line writes state changes to the signal file, FileChanged fires, and exit code 2 withasyncRewakewakes the session with the message.--watch(SessionStart, CwdChanged) registers that file; without CwdChanged the watch is lost after a change of directory. - The messages are self-contained (state, numbers, what to do), so
subagents that never loaded
SKILL.mdstill know how to react.
Verifying the installation
- Start a new session and send one prompt: the status line shows
5h …%/…% (…) · week …%/…% (…), and~/.claude/usage-pacing/usage.jsonexists. - Hook output:
echo '{"session_id":"probe"}' | ~/.claude/skills/usage-pacing/usage-pacing.sh --checkprints a JSONadditionalContextunless the state isplan(then nothing). Remove~/.claude/usage-pacing/sessions/probeandsessions/skill-probeafterwards. - Waking: take an idle session started after the installation, and from
another terminal (a tool call inside that session would run
--checkfirst and report the state itself) set its line in~/.claude/usage-pacing/sessions/<session id>tobehind 0, thenecho probe > ~/.claude/usage-pacing/signal. Within seconds the session wakes with aUSAGE:message, provided the current state is tighter thanbehind(anything butbehindandplan). ./test.shchecks the computation itself.
How it works
| Mode | Hook | Does |
|---|---|---|
--statusline |
status line | Records changed rate limits, prints the line, writes state changes to the signal file. |
--check |
PostToolUse, SubagentStart, UserPromptSubmit | Reports the state to the session at once when it got tighter or a reported brake was released, otherwise at most every 30 min; a subagent's first report gives every limit with the session's targets. Tells each session and subagent once when SKILL.md changed while it runs (unchanged for 10 s, so a copy in progress does not count), to load the skill again. |
--watch |
SessionStart, CwdChanged | Registers the signal file for FileChanged. |
--wake |
FileChanged (asyncRewake) |
Wakes an idle session when the state got tighter or a brake was released. |
--grant |
— | Records a user's grant (see SKILL.md, "Grants from the user"): for a time, a limit's target raised to at least N % (=N: exactly N, as the maximum), by N points, rising linearly to N % (to=N), or to the plan of a later time already now (now); for all sessions (all) or one session and its subagents; pushing ("behind" counts from it) or only permitting. --grant <id> off or --push/--no-push changes one by its id. |
--list |
— | Lists the live grants with their ids, forms, ends, push and targets now. |
--config |
— | Shows the configuration in effect, or sets or resets one key of it (see "Configuration"). |
--fetch |
— | Experimental: reads /usage through claude -p (local command, no model call, no tokens) and records every configured limit it reports, model-specific ones included. Started in the background when nothing was fetched yet or a recorded limit is older than intervals.fetch (5 min), about once per interval on a machine, whatever the number of sessions. |
Every rate limit is one entry of the list limits in config.json and
goes through the same steps (see SKILL.md): its target starts with an
offset available at once and rises linearly to target (90 %) at the
reset, the rest is left to the user. Limits for all work (5 hours, week)
decide the general state; a model's own limit brakes only work on that
model. The status line passes five_hour and seven_day; /usage names
them session and weekly_all and adds weekly_scoped per model.
Configuration
config.json holds the defaults, which apply whenever no grant does;
anything limited in time is a grant (--grant). Change the defaults with
--config, not by editing a file; it writes only the keys you set into
~/.claude/usage-pacing/config.json, which is merged over the defaults and
applies to all sessions on the machine:
usage-pacing.sh --config # the configuration in effect
usage-pacing.sh --config limits.seven_day.offset # one key
usage-pacing.sh --config limits.seven_day.offset 86400
usage-pacing.sh --config limits.seven_day.offset default
A key is a dotted path of a default below; limits.<kind>.<key> takes any
key one kind has (e.g. limits.five_hour.behind). Values must have the
default's type (numbers at least 0); anything else is refused, and so is
a result with seconds that are not whole, a length of 0, an offset beyond
its length, a target above 100, or tight_off below tight_on (faults a
change does not add, e.g. in a file edited by hand, do not block it; the
message names the keys at fault).
limits.<kind>, one entry per kind of limit (five_hour, seven_day,
weekly_scoped; a further kind that the status line or /usage reports
is picked up once it has an entry):
| Key | Defaults (5h / week / model) | Meaning |
|---|---|---|
label |
5h / week / weekly limit |
Name in the status line and messages (a model's limit is shown under the model's name). |
length |
18000 / 604800 / 604800 | Window length in seconds. |
offset |
7200 / 21600 / 21600 | Seconds of budget free at the window's start. |
target |
90 | Target in percent at the reset; from there on the rest is the user's reserve. |
release |
3 / 1 / 1 | Points below the target at which an "ahead" brake releases. |
tight_on / tight_off |
– / 3, 4 / 3, 4 | Points below the target for the early warning (optional; tight_off at least tight_on, without it the same as tight_on; to raise both, raise tight_off first). |
behind |
– / 5 / – | Points below the target that ask for more parallel work (optional; a limit without it objects to that only within release points of its target). |
| Key | Default | Meaning |
|---|---|---|
intervals.fetch |
300 | Seconds before a recorded limit counts as old enough to fetch; 0 turns background fetching off. |
intervals.stale |
900 | Seconds after which a value counts as stale. |
intervals.remind |
1800 | Seconds between repeated reports of an unchanged state. |
anomaly.drop |
3 | Points a counter may drop in a fetch without a reset before it is logged. |
anomaly.tolerance |
300 | Seconds a reset time may move without counting as moved. |
grants.push |
true | Whether new grants push ("behind" counts from the granted target) unless --push/--no-push says otherwise; a maximum (=N) pushes only with --push; each grant records its own. |
SKILL.md quotes the defaults only as such ("(defaults)"): agents read
targets and distances from the messages or --statusline.
Files
Runtime state lives in ~/.claude/usage-pacing/ (override with
USAGE_PACING_STATE), per machine. Times are Unix seconds throughout; messages and
logs print them in UTC (…Z), never in local time (jq's strflocaltime
gets the offset wrong in the repeated hour when daylight saving time ends):
| File | Content |
|---|---|
config.json |
The keys set with --config, merged over the defaults. |
settings.json.<time> |
Backups that install.sh made of the settings. |
usage.json |
Recorded limits (limits.<id>: kind, scope, pct, resets_at, at) and fetched_at. |
rule.json |
Active brakes (hysteresis). |
grants/ |
Per scope with grants: all.json (every session) or <session id>.json (limits.<id>: target, cap, plus, to with from and since, or early; until, push), and a session's own brakes (<session id>.rule); removed by the next --grant once every grant in it has ended. |
signal |
Last state, watched by the FileChanged hook. |
sessions/ |
Per session and subagent: last reported state, severity and time (<id>), the SKILL.md checksum it last saw (skill-<id>), the status line's last values (statusline-<session id>); removed after a day idle. |
anomalies.log |
Counter anomalies, with anomalies.log.reported. |
fetch.stamp |
Time of the last background fetch. |
Limitations
- Tested on Linux. The background fetch needs
setsid(util-linux), which macOS lacks: there it never starts and only the status line records values. The rest needs jq and GNU options (date -dfor a grant's end,stat -cfor the reload hint,readlink -f,find -delete); without GNU coreutils, grants and the reload hint do not work. - Silent when it cannot work: without
jqthe script exits 0 and prints nothing, so that a session is never broken by it; without a Pro/Max plan nothing is ever recorded and the hooks stay silent too. No numbers in the status line means nothing is being recorded. --fetchis experimental: it readsusage_report.rate_limitsfromclaude -p /usage --output-format stream-json --verbose, which is not documented. Measured with Claude Code 2.1.296: the result reportstotal_cost_usd: 0, zero tokens andnum_turns: 0. If the output changes, only the status line records values; setintervals.fetchto 0 to turn fetching off.- A model-specific weekly limit (
weekly_scopedin/usage, e.g. for one model; not every plan has one) comes from the background fetch only, since the status line does not receive it: withintervals.fetch0, or when a fetch stops reporting it, it keeps its last value until its window ends (it does not make the state stale). - Values only rise between fetches: from the status line, a lower value
for the same reset time, or a reset time that moves earlier, is taken as
stale; only a fetch accepts it (within
intervals.fetch; with fetching off, not before the window's scheduled reset — the brakes then err on the safe side). A reset off schedule that starts a window with a later reset time is recorded at once and logged as an anomaly. - Session grants do not wake: the signal file is shared and keeps the
state with the global grants only, so a session is told that its own
grant ended with its next tool call or prompt, not while it is idle; the
same holds for a changed
SKILL.md. A grant ends with its limit's window at the latest. - State per machine: the limits belong to the account, but each machine records them on its own; sessions on other machines are not told.
- Waking shows as an error: Claude Code labels the wake-up as "Stop hook
blocking error from command FileChanged". That is the mechanism working
(exit code 2 of
--wake), not a failure. - Sessions running at installation watch no signal file until they
restart or change directory; only
--checkreaches them meanwhile.
Uninstall
Run ~/.claude/skills/usage-pacing/install.sh --uninstall (it removes the
status line and the hooks that run usage-pacing.sh, nothing else), then
remove the line in CLAUDE.md if you added one, the skill directory and
the state directory ~/.claude/usage-pacing/.
Test
./test.sh
Checks, with fixed times in a scratch directory: the targets at the start
and end of both windows, every state and the hysteresis of the brakes,
recording with a window missing, numbers as strings and ISO 8601 times
with any offset, freshness after a new answer, stale lower values from a
new session or an earlier window, the fetch (with a stand-in claude),
several model-specific limits, anomaly logging and its report once, waking
on a released brake (also after a stale report), malformed input,
fetch: 0, an old model value, grants (fixed and added, ramps (to=N)
and early use, global ones and their precedence, push per grant, --list
and ids, a model's (also a name with a space) and one no longer recorded,
subagents, other sessions unaffected, ending with the window, the release
of a global maximum, refusals), --config (set, reset, refusals, a lone
tight_on edited by hand), the reload hint for a changed SKILL.md, and
install.sh (new and symlinked settings, foreign hook and status line
kept, second run unchanged, dry run, uninstall).
License
MIT, see LICENSE.