claude-pace 0.7.3 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +53 -17
  2. package/claude-pace.sh +33 -134
  3. package/package.json +11 -4
package/README.md CHANGED
@@ -1,17 +1,39 @@
1
1
  # Claude Pace
2
2
 
3
- Know your quota before you hit the wall. A statusline for Claude Code single Bash file, zero npm.
3
+ A lightweight Claude Code status line and rate limit tracker that shows your 5-hour and 7-day quota usage in real time. Pure Bash + jq, single file, zero npm.
4
4
 
5
- Most statuslines show "you used 60%." That number means nothing without context. 60% with 30 minutes left? Fine, the window resets soon. 60% with 4 hours left? You're about to hit the wall. claude-pace compares your usage rate to the time remaining and shows the delta. No Node.js, no npm, no lock files. Single Bash file.
5
+ If you are searching for a Claude Code statusline, a Claude Code quota monitor, or a Claude Code usage tracker, claude-pace is built for that narrow job. It shows not only how much quota you have used, but whether your current burn rate is sustainable before the window resets.
6
6
 
7
7
  ![claude-pace statusline demo](.github/claude-pace-demo.gif)
8
8
 
9
+ ## TL;DR
10
+
11
+ - Claude Code status line with `5h` and `7d` quota usage, reset countdowns, and pace delta
12
+ - Pace-aware rate limit tracking, `⇡15%` means overspending, `⇣15%` means headroom
13
+ - Pure Bash + jq, single file, no Node.js runtime and no lockfile churn
14
+ - Install as a Claude Code plugin, with `npx`, or as a single script
15
+
16
+ Most statuslines show "you used 60%." That number means nothing without context. 60% with 30 minutes left? Fine, the window resets soon. 60% with 4 hours left? You are about to hit the wall. claude-pace compares your burn rate to the time remaining and shows the delta.
17
+
9
18
  - **⇣15%** green = you've used 15% less than expected. Headroom. Keep going.
10
19
  - **⇡15%** red = you're burning 15% faster than sustainable. Slow down.
11
20
  - **15%** / **20%** = used in the 5h and 7d windows. **3h** = resets in 3 hours.
12
21
  - Top line: model, effort, project `(branch)`, `3f +24 -7` = git diff stats
13
22
 
14
- ## Install
23
+ Claude Code supports custom status lines through its `statusLine` setting and `/statusline` workflow in the official docs:
24
+
25
+ - [Customize your status line](https://code.claude.com/docs/en/statusline)
26
+ - [Claude Code settings](https://docs.anthropic.com/en/docs/claude-code/settings)
27
+
28
+ ## Table of Contents
29
+
30
+ - [Install This Claude Code Statusline](#install-this-claude-code-statusline)
31
+ - [Upgrade](#upgrade)
32
+ - [Claude Code Statusline Comparison](#claude-code-statusline-comparison)
33
+ - [How Claude Pace Tracks Quota](#how-claude-pace-tracks-quota)
34
+ - [Claude Code Statusline FAQ](#claude-code-statusline-faq)
35
+
36
+ ## Install This Claude Code Statusline
15
37
 
16
38
  Requires `jq`.
17
39
 
@@ -65,36 +87,48 @@ To remove: delete the `statusLine` block from `~/.claude/settings.json`.
65
87
 
66
88
  Release notifications: Watch this repo → Custom → Releases.
67
89
 
68
- ## How It Compares
90
+ ## Claude Code Statusline Comparison
69
91
 
70
- | | claude-pace | Node.js/TypeScript statuslines | Rust/Go statuslines |
71
- |---|---|---|---|
72
- | Runtime | `jq` | Node.js 18+ / npm | Compiled binary |
73
- | Codebase | Single file | 1000+ lines + node_modules | Compiled, not inspectable |
74
- | Execution | ~10ms, 3% of refresh cycle | ~90ms, 30% of refresh cycle | ~5ms (est.) |
75
- | Memory | ~2 MB | ~57 MB | ~3 MB (est.) |
76
- | Failure modes | Read-only, worst case prints "Claude" | Runtime dependency, package manager | Generally stable |
77
- | Pace tracking | Usage rate vs time remaining | Trend-only or none | None |
92
+ | | claude-pace | [claude-hud](https://github.com/jarrodwatts/claude-hud) | [CCometixLine](https://github.com/Haleclipse/CCometixLine) | [ccstatusline](https://github.com/sirmalloc/ccstatusline) |
93
+ |---|---|---|---|---|
94
+ | Runtime | `jq` | Node.js 18+ / npm | Compiled (Rust) | Node.js / npm |
95
+ | Codebase | Single Bash file | 1000+ lines + node_modules | Compiled binary | 1000+ lines + node_modules |
96
+ | Rate limit tracking | 5h + 7d usage %, pace delta, reset countdown | Usage % | Usage % (planned) | None (formatting only) |
97
+ | Execution | ~10ms | ~90ms | ~5ms | ~90ms |
98
+ | Memory | ~2 MB | ~57 MB | ~3 MB | ~57 MB |
78
99
 
79
- Execution and memory measured on Apple Silicon, 300 runs, same stdin JSON. Rust/Go values are estimates.
100
+ Execution and memory measured on Apple Silicon, 300 runs, same stdin JSON.
80
101
 
81
102
  Need themes, powerline aesthetics, or TUI config? Try [ccstatusline](https://github.com/sirmalloc/ccstatusline). The entire source of claude-pace is [one file](claude-pace.sh). Read it.
82
103
 
83
- ## Under the Hood
104
+ ## How Claude Pace Tracks Quota
84
105
 
85
106
  Claude Code polls the statusline every ~300ms:
86
107
 
87
108
  | Data | Source | Cache |
88
109
  |------|--------|-------|
89
110
  | Model, context, cost | stdin JSON (single `jq` call) | None needed |
90
- | Quota (5h, 7d, pace) | stdin `rate_limits` (CC >= 2.1.80) | None needed (real-time) |
91
- | Quota fallback | Anthropic Usage API (CC < 2.1.80) | Private cache dir, 300s TTL, async background refresh |
111
+ | Quota (5h, 7d, pace) | stdin `rate_limits`; fallback to last-known private cache when `rate_limits` is absent | Private cache root, accepted only before cached reset |
92
112
  | Git branch + diff | `git` commands | Private cache dir, 5s TTL |
93
113
 
94
- On Claude Code >= 2.1.80, usage data comes directly from stdin. No network calls. On older versions, it falls back to the Usage API in a background subshell so the statusline never blocks.
114
+ Best experience is on Claude Code `2.1.80+`, where `rate_limits` is available in statusline stdin. When a later statusline run omits `rate_limits`, claude-pace can reuse the last known stdin quota snapshot from its private cache until either cached reset time expires.
95
115
 
96
116
  Cache files live in a private per-user directory (`$XDG_RUNTIME_DIR/claude-pace` or `~/.cache/claude-pace`, mode 700). All cache reads are validated before use. No files are ever written to shared `/tmp`.
97
117
 
118
+ ## Claude Code Statusline FAQ
119
+
120
+ **Does it need Node.js?**
121
+ No. Only `jq` (available via `brew install jq` or your package manager). No npm, no node_modules, no lock files.
122
+
123
+ **How does pace tracking work?**
124
+ claude-pace compares your current usage percentage to the fraction of time elapsed in each window (5-hour and 7-day). If you've used 40% of your quota but only 30% of the time has passed, the pace delta shows ⇡10% (red, burning too fast). If you've used 30% with 40% of time elapsed, it shows ⇣10% (green, headroom).
125
+
126
+ **Does it make network calls?**
127
+ No. Quota data comes from stdin `rate_limits` on Claude Code `2.1.80+`. If a later statusline run omits `rate_limits`, claude-pace can reuse the last known stdin quota snapshot from its private cache as long as that snapshot's reset times are still in the future. Otherwise it falls back to `--` and may still show the local session cost.
128
+
129
+ **Can I inspect the source?**
130
+ The entire tool is [one Bash file](claude-pace.sh). Read it before you install it.
131
+
98
132
  ## Also by the Author
99
133
 
100
134
  [**diffpane**](https://github.com/Astro-Han/diffpane) - Real-time TUI diff viewer for AI coding agents. See what Claude Code changes as it happens.
@@ -102,3 +136,5 @@ Cache files live in a private per-user directory (`$XDG_RUNTIME_DIR/claude-pace`
102
136
  ## License
103
137
 
104
138
  MIT
139
+
140
+ *Last updated: 2026-04-13 · v0.8.0*
package/claude-pace.sh CHANGED
@@ -74,6 +74,16 @@ _minutes_until() {
74
74
  ((mins < 0)) && mins=0
75
75
  printf '%s\n' "$mins"
76
76
  }
77
+ # Valid quota snapshots must contain integer usage values and future reset
78
+ # epochs for both windows. Partial or expired snapshots never enter the cache.
79
+ _valid_quota_snapshot() {
80
+ local u5="$1" u7="$2" r5="$3" r7="$4"
81
+ [[ "$u5" =~ ^[0-9]+$ ]] || return 1
82
+ [[ "$u7" =~ ^[0-9]+$ ]] || return 1
83
+ [[ "$r5" =~ ^[0-9]+$ ]] || return 1
84
+ [[ "$r7" =~ ^[0-9]+$ ]] || return 1
85
+ ((r5 > NOW && r7 > NOW))
86
+ }
77
87
  # Collects live Git metadata for DIR. On non-repos, leaves defaults in place
78
88
  # and returns non-zero so callers can decide whether to cache the empty result.
79
89
  _collect_git_info() {
@@ -101,6 +111,8 @@ for _BASE in "${XDG_RUNTIME_DIR:-}" "${HOME}/.cache"; do
101
111
  CACHE_OK=1
102
112
  break
103
113
  done
114
+ QC=""
115
+ [[ "$CACHE_OK" == "1" ]] && QC="${_CD}/claude-sl-quota"
104
116
  # Returns true (exit 0) when file is missing or older than $2 seconds.
105
117
  _stale() { [ ! -f "$1" ] || [ $((NOW - $(stat -f%m "$1" 2>/dev/null || stat -c%Y "$1" 2>/dev/null || echo 0))) -gt "$2" ]; }
106
118
 
@@ -194,142 +206,34 @@ elif [[ "$IS_WT" == "1" ]]; then
194
206
  ((${#L1R} > 25)) && L1R="${L1R:0:25}…"
195
207
  fi
196
208
 
197
- # Usage data: prefer stdin rate_limits (CC >=2.1.80), fall back to API polling
209
+ # Usage data: read stdin rate_limits when available, otherwise show session cost.
198
210
  SHOW_COST=0
199
211
  if [[ "$HAS_RL" == "1" ]]; then
200
212
  # Stdin path: real-time, no network. U5/U7 already set by jq read above.
201
- # Guard: resets_at=0 means field missing, leave RM empty so _pace/_rc skip it
213
+ # Guard: resets_at=0 means field missing, leave RM empty so _usage skips it.
202
214
  RM5=$(_minutes_until "$R5")
203
215
  RM7=$(_minutes_until "$R7")
204
- # Extra usage (XO/XU/XL) only available via API fallback; stdin lacks this data
205
- elif [[ "${CLAUDE_PACE_API_FALLBACK:-1}" != "0" ]]; then
206
- # ── API fallback (disable via CLAUDE_PACE_API_FALLBACK=0) ──
207
- UC="" UL=""
208
- [[ "$CACHE_OK" == "1" ]] && {
209
- UC="${_CD}/claude-sl-usage"
210
- UL="${_CD}/claude-sl-usage.lock"
211
- }
212
-
213
- # ── _get_token: credential source priority ──
214
- # Check in order: env var → macOS Keychain → credentials file → secret-tool (Linux).
215
- _get_token() {
216
- [ -n "$CLAUDE_CODE_OAUTH_TOKEN" ] && {
217
- printf '%s' "$CLAUDE_CODE_OAUTH_TOKEN"
218
- return
219
- }
220
- local b=""
221
- command -v security >/dev/null &&
222
- b=$(security find-generic-password -s "Claude Code-credentials" -w 2>/dev/null)
223
- [ -z "$b" ] && [ -f ~/.claude/.credentials.json ] && b=$(<~/.claude/.credentials.json)
224
- [ -z "$b" ] && command -v secret-tool >/dev/null &&
225
- b=$(timeout 2 secret-tool lookup service "Claude Code-credentials" 2>/dev/null)
226
- [ -n "$b" ] && jq -j '.claudeAiOauth.accessToken//empty' <<<"$b" 2>/dev/null
227
- }
228
-
229
- # ── _fetch_usage_api: direct API read into usage globals ──
230
- # Used by both the cached background refresh path and the no-cache fallback.
231
- _fetch_usage_api() {
232
- local tk resp
233
- # Command substitution strips trailing newlines. Append a sentinel byte only
234
- # on success so malformed tokens with a trailing LF remain detectable here.
235
- tk=$(_get_token && printf '\001') || return 1
236
- [[ "$tk" == *$'\001' ]] || return 1
237
- tk=${tk%$'\001'}
238
- [ -n "$tk" ] || return 1
239
- # OAuth bearer tokens must remain a single header line. Reject malformed
240
- # credentials up front instead of letting curl parse injected CR/LF bytes.
241
- case "$tk" in *$'\n'* | *$'\r'*) return 1 ;; esac
242
- # Feed headers through process substitution so the bearer token stays out
243
- # of curl argv while preserving literal bytes like quotes and backslashes.
244
- resp=$(curl -s --max-time 3 \
245
- -H @<(
246
- printf 'Authorization: Bearer %s\n' "$tk"
247
- printf '%s\n' 'anthropic-beta: oauth-2025-04-20'
248
- printf '%s\n' 'Content-Type: application/json'
249
- ) \
250
- "https://api.anthropic.com/api/oauth/usage" 2>/dev/null)
251
- IFS=$'\t' read -r U5 U7 XO XU XL RM5 RM7 < <(jq -r '
252
- def rmins: if . and . != "" then (sub("\\.[0-9]+"; "") | sub("\\+00:00$"; "Z") | fromdateiso8601) - (now|floor) | ./60|floor | if .<0 then 0 else . end else null end;
253
- [(.five_hour.utilization|floor),(.seven_day.utilization|floor),
254
- (if .extra_usage.is_enabled then 1 else 0 end),
255
- (.extra_usage.used_credits//0|floor),(.extra_usage.monthly_limit//0|floor),
256
- (.five_hour.resets_at|rmins//""),(.seven_day.resets_at|rmins//"")]|@tsv' \
257
- <<<"$resp" 2>/dev/null) || return 1
258
- }
259
-
260
- # ── _fetch_usage: background stale-while-revalidate fetch ──
261
- # Runs in a subshell (&) so the main process returns immediately with cached data.
262
- # On API failure, writes placeholder values once so the UI stays stable and
263
- # avoids repeated refresh attempts until the cache TTL expires.
264
- _fetch_usage() {
265
- (
266
- trap 'rm -f "$UL"' EXIT
267
- if _fetch_usage_api; then
268
- _write_cache_record "$UC" "$U5" "$U7" "$XO" "$XU" "$XL" "$RM5" "$RM7"
269
- else
270
- if [ ! -f "$UC" ] || [[ $(head -c2 "$UC") == -- ]]; then
271
- _write_cache_record "$UC" "--" "--" "0" "0" "0" "" ""
272
- fi
273
- fi
274
- ) &
275
- }
276
-
277
- # ── Lock mechanism (noclobber mutex) ──
278
- # `set -o noclobber` makes `>` fail atomically if the file already exists,
279
- # providing a lock without external tools. The stale-lock check (10s) ensures
280
- # a crashed worker can't block refreshes indefinitely.
281
- if [[ "$CACHE_OK" == "1" ]] && _stale "$UC" 300; then
282
- if (
283
- set -o noclobber
284
- echo $$ >"$UL"
285
- ) 2>/dev/null; then
286
- _fetch_usage
287
- elif [ -f "$UL" ] && _stale "$UL" 10; then
288
- rm -f "$UL"
289
- (
290
- set -o noclobber
291
- echo $$ >"$UL"
292
- ) 2>/dev/null && _fetch_usage
293
- fi
294
- fi
295
-
296
- # ── Read cache + drift correction ──
297
- # The cache stores countdown minutes at write time; subtract elapsed seconds
298
- # (in whole minutes) since the file was written to keep the countdown accurate
299
- # between 300s refresh cycles without a network call.
300
- U5="--" U7="--" XO=0 XU=0 XL=0 RM5="" RM7=""
301
- if [[ "$CACHE_OK" == "1" ]]; then
302
- if _load_cache_record_file "$UC"; then
303
- U5=${CACHE_FIELDS[0]:---}
304
- U7=${CACHE_FIELDS[1]:---}
305
- XO=${CACHE_FIELDS[2]:-0}
306
- XU=${CACHE_FIELDS[3]:-0}
307
- XL=${CACHE_FIELDS[4]:-0}
308
- RM5=${CACHE_FIELDS[5]:-}
309
- RM7=${CACHE_FIELDS[6]:-}
310
- fi
311
- if [[ "$RM5" =~ ^[0-9]+$ ]] && [ -f "$UC" ]; then
312
- _CA=$((NOW - $(stat -f%m "$UC" 2>/dev/null || stat -c%Y "$UC" 2>/dev/null || echo "$NOW")))
313
- RM5=$((RM5 - _CA / 60))
314
- ((RM5 < 0)) && RM5=0
315
- [[ "$RM7" =~ ^[0-9]+$ ]] && {
316
- RM7=$((RM7 - _CA / 60))
317
- ((RM7 < 0)) && RM7=0
318
- }
319
- fi
320
- [ ! -f "$UC" ] && SHOW_COST=1
321
- elif ! _fetch_usage_api; then
322
- SHOW_COST=1
216
+ if [[ -n "$QC" ]] && _valid_quota_snapshot "$U5" "$U7" "$R5" "$R7"; then
217
+ _write_cache_record "$QC" "$U5" "$U7" "$R5" "$R7" || true
323
218
  fi
324
- U5=${U5%%.*} U7=${U7%%.*} XU=${XU%%.*} XL=${XL%%.*}
325
- # Reject cache corruption or malformed API data before arithmetic formatting.
326
- [[ "$XO" =~ ^[01]$ ]] || XO=0
327
- [[ "$XU" =~ ^[0-9]+$ ]] || XU=0
328
- [[ "$XL" =~ ^[0-9]+$ ]] || XL=0
329
- # ── End API fallback ──
330
219
  else
331
- # No stdin rate_limits and API fallback not enabled; show session cost only.
220
+ U5="--" U7="--" RM5="" RM7=""
332
221
  SHOW_COST=1
222
+ if [[ -n "$QC" ]] && _load_cache_record_file "$QC"; then
223
+ _CU5=${CACHE_FIELDS[0]:-}
224
+ _CU7=${CACHE_FIELDS[1]:-}
225
+ _CR5=${CACHE_FIELDS[2]:-}
226
+ _CR7=${CACHE_FIELDS[3]:-}
227
+ if _valid_quota_snapshot "$_CU5" "$_CU7" "$_CR5" "$_CR7"; then
228
+ U5="$_CU5"
229
+ U7="$_CU7"
230
+ R5="$_CR5"
231
+ R7="$_CR7"
232
+ RM5=$(_minutes_until "$R5")
233
+ RM7=$(_minutes_until "$R7")
234
+ SHOW_COST=0
235
+ fi
236
+ fi
333
237
  fi
334
238
 
335
239
  # Combined usage formatter: used% [pace delta] (countdown)
@@ -359,8 +263,6 @@ _usage() {
359
263
  }
360
264
 
361
265
  # ── Output Assembly (symmetric single-pipe alignment) ──
362
- # Default XO/XU/XL for stdin path (extra usage only available via API fallback).
363
- : "${XO:=0}" "${XU:=0}" "${XL:=0}"
364
266
 
365
267
  # Build plain-text left sections for width measurement (no ANSI codes).
366
268
  L1_PLAIN="${MODEL} ${EF}"
@@ -379,10 +281,7 @@ L1="${C}${MODEL} ${EF}${N}${PAD1} ${D}|${N} ${L1R}"
379
281
 
380
282
  # Line 2: bar pct% CL | 5h used% ... 7d used% ...
381
283
  L2="${BC}${BAR}${N} ${PCT}% ${CL}${PAD2} ${D}|${N} 5h $(_usage "$U5" "$RM5" 300) 7d $(_usage "$U7" "$RM7" 10080)"
382
- # Extra usage: only when enabled and has actual spending (API fallback only)
383
- [ "$XO" = 1 ] && ((XU > 0)) &&
384
- printf -v _XS " ${Y}\$%d.%02d${N}/\$%d.%02d" $((XU / 100)) $((XU % 100)) $((XL / 100)) $((XL % 100)) && L2+="$_XS"
385
- # Session cost: only when this run has no readable usage cache data.
284
+ # Session cost: only when usage data is unavailable in stdin.
386
285
  if [[ "$SHOW_COST" == "1" ]]; then
387
286
  printf -v _CS "\$%.2f" "$COST" 2>/dev/null
388
287
  [[ "$_CS" != "\$0.00" ]] && L2+=" $_CS"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "claude-pace",
3
- "version": "0.7.3",
4
- "description": "A statusline for Claude Code. Pure Bash + jq, single file.",
3
+ "version": "0.8.1",
4
+ "description": "Claude Code statusline and rate limit tracker. Pure Bash + jq, single file.",
5
5
  "bin": {
6
6
  "claude-pace": "cli.js"
7
7
  },
@@ -15,16 +15,23 @@
15
15
  },
16
16
  "keywords": [
17
17
  "claude-code",
18
+ "claude-code-statusline",
19
+ "claude-code-plugin",
18
20
  "statusline",
21
+ "status-line",
22
+ "rate-limit-tracker",
19
23
  "quota",
24
+ "quota-tracker",
20
25
  "usage",
26
+ "usage-monitor",
21
27
  "pace-tracking",
22
- "bash"
28
+ "bash",
29
+ "jq"
23
30
  ],
24
31
  "license": "MIT",
25
32
  "repository": {
26
33
  "type": "git",
27
- "url": "https://github.com/Astro-Han/claude-pace"
34
+ "url": "git+https://github.com/Astro-Han/claude-pace.git"
28
35
  },
29
36
  "engines": {
30
37
  "node": ">=16"