Claude Code skill: pace autonomous work against the subscription's 5-hour and weekly rate limits (status line + hooks)
Find a file
Florian Schlegel e8f4720273 Print times in UTC, not local time
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>
2026-10-26 20:15:35 +01:00
config.json Grants: grants.push configures whether end=N and now push; ids with spaces 2026-10-23 10:01:12 +02:00
install.sh Subagents get every limit with the session's targets at their first report 2026-10-19 15:36:40 +02:00
LICENSE usage-pacing: pace Claude Code work against the subscription's rate limits 2026-10-17 16:04:17 +02:00
README.md Print times in UTC, not local time 2026-10-26 20:15:35 +01:00
SKILL.md SKILL.md: replace a grant while the old one is live, or to=N starts from the plan 2026-10-26 19:45:00 +01:00
test.sh Print times in UTC, not local time 2026-10-26 20:15:35 +01:00
usage-pacing.sh Print times in UTC, not local time 2026-10-26 20:15:35 +01:00

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> reset for 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.md tells agents what each state means and how to react.

Requirements

  • A Pro or Max plan: only then does Claude Code pass rate_limits to the status line (from the first answer of a session on).
  • bash, jq, coreutils, setsid (util-linux); the claude CLI in PATH for 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 -r may drop the bit.
  • Claude Code has one status line. install.sh asks before replacing an existing one; to keep yours, call usage-pacing.sh --statusline from 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.json work 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_limits to 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

  • --check runs as PostToolUse hook in the main session and in every subagent (Claude Code passes agent_id there); its message arrives as additionalContext right 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 --grant for its session (or all) it gets this report again.
  • A new counter anomaly (anomalies.log) is reported once to the main sessions as USAGE 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 with asyncRewake wakes 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.md still know how to react.

Verifying the installation

  1. Start a new session and send one prompt: the status line shows 5h …%/…% (…) · week …%/…% (…), and ~/.claude/usage-pacing/usage.json exists.
  2. Hook output: echo '{"session_id":"probe"}' | ~/.claude/skills/usage-pacing/usage-pacing.sh --check prints a JSON additionalContext unless the state is plan (then nothing). Remove ~/.claude/usage-pacing/sessions/probe and sessions/skill-probe afterwards.
  3. Waking: take an idle session started after the installation, and from another terminal (a tool call inside that session would run --check first and report the state itself) set its line in ~/.claude/usage-pacing/sessions/<session id> to behind 0, then echo probe > ~/.claude/usage-pacing/signal. Within seconds the session wakes with a USAGE: message, provided the current state is tighter than behind (anything but behind and plan).
  4. ./test.sh checks 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 -d for a grant's end, stat -c for the reload hint, readlink -f, find -delete); without GNU coreutils, grants and the reload hint do not work.
  • Silent when it cannot work: without jq the 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.
  • --fetch is experimental: it reads usage_report.rate_limits from claude -p /usage --output-format stream-json --verbose, which is not documented. Measured with Claude Code 2.1.296: the result reports total_cost_usd: 0, zero tokens and num_turns: 0. If the output changes, only the status line records values; set intervals.fetch to 0 to turn fetching off.
  • A model-specific weekly limit (weekly_scoped in /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: with intervals.fetch 0, 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 --check reaches 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.