claude-pace 0.7.3 → 0.8.0

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 +27 -13
  2. package/claude-pace.sh +3 -134
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -1,8 +1,8 @@
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 status line for Claude Code that tracks your 5-hour and 7-day rate limit 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
+ 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 burn rate to the time remaining and shows the delta: are you ahead of pace or behind?
6
6
 
7
7
  ![claude-pace statusline demo](.github/claude-pace-demo.gif)
8
8
 
@@ -67,16 +67,15 @@ Release notifications: Watch this repo → Custom → Releases.
67
67
 
68
68
  ## How It Compares
69
69
 
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 |
70
+ | | claude-pace | [claude-hud](https://github.com/jarrodwatts/claude-hud) | [CCometixLine](https://github.com/Haleclipse/CCometixLine) | [ccstatusline](https://github.com/sirmalloc/ccstatusline) |
71
+ |---|---|---|---|---|
72
+ | Runtime | `jq` | Node.js 18+ / npm | Compiled (Rust) | Node.js / npm |
73
+ | Codebase | Single Bash file | 1000+ lines + node_modules | Compiled binary | 1000+ lines + node_modules |
74
+ | Rate limit tracking | 5h + 7d usage %, pace delta, reset countdown | Usage % | Usage % (planned) | None (formatting only) |
75
+ | Execution | ~10ms | ~90ms | ~5ms | ~90ms |
76
+ | Memory | ~2 MB | ~57 MB | ~3 MB | ~57 MB |
78
77
 
79
- Execution and memory measured on Apple Silicon, 300 runs, same stdin JSON. Rust/Go values are estimates.
78
+ Execution and memory measured on Apple Silicon, 300 runs, same stdin JSON.
80
79
 
81
80
  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
81
 
@@ -88,13 +87,26 @@ Claude Code polls the statusline every ~300ms:
88
87
  |------|--------|-------|
89
88
  | Model, context, cost | stdin JSON (single `jq` call) | None needed |
90
89
  | 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 |
92
90
  | Git branch + diff | `git` commands | Private cache dir, 5s TTL |
93
91
 
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.
92
+ Usage tracking requires Claude Code `2.1.80+`, where `rate_limits` is available in statusline stdin. claude-pace does not call the Anthropic Usage API.
95
93
 
96
94
  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
95
 
96
+ ## FAQ
97
+
98
+ **Does it need Node.js?**
99
+ No. Only `jq` (available via `brew install jq` or your package manager). No npm, no node_modules, no lock files.
100
+
101
+ **How does pace tracking work?**
102
+ 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).
103
+
104
+ **Does it make network calls?**
105
+ No. All displayed quota data comes from stdin. If `rate_limits` is missing, claude-pace shows `--` for quota and can still show the local session cost.
106
+
107
+ **Can I inspect the source?**
108
+ The entire tool is [one Bash file](claude-pace.sh). Read it before you install it.
109
+
98
110
  ## Also by the Author
99
111
 
100
112
  [**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 +114,5 @@ Cache files live in a private per-user directory (`$XDG_RUNTIME_DIR/claude-pace`
102
114
  ## License
103
115
 
104
116
  MIT
117
+
118
+ *Last updated: 2026-04-13 · v0.8.0*
package/claude-pace.sh CHANGED
@@ -194,141 +194,15 @@ elif [[ "$IS_WT" == "1" ]]; then
194
194
  ((${#L1R} > 25)) && L1R="${L1R:0:25}…"
195
195
  fi
196
196
 
197
- # Usage data: prefer stdin rate_limits (CC >=2.1.80), fall back to API polling
197
+ # Usage data: read stdin rate_limits when available, otherwise show session cost.
198
198
  SHOW_COST=0
199
199
  if [[ "$HAS_RL" == "1" ]]; then
200
200
  # Stdin path: real-time, no network. U5/U7 already set by jq read above.
201
201
  # Guard: resets_at=0 means field missing, leave RM empty so _pace/_rc skip it
202
202
  RM5=$(_minutes_until "$R5")
203
203
  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
323
- 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
204
  else
331
- # No stdin rate_limits and API fallback not enabled; show session cost only.
205
+ U5="--" U7="--" RM5="" RM7=""
332
206
  SHOW_COST=1
333
207
  fi
334
208
 
@@ -359,8 +233,6 @@ _usage() {
359
233
  }
360
234
 
361
235
  # ── 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
236
 
365
237
  # Build plain-text left sections for width measurement (no ANSI codes).
366
238
  L1_PLAIN="${MODEL} ${EF}"
@@ -379,10 +251,7 @@ L1="${C}${MODEL} ${EF}${N}${PAD1} ${D}|${N} ${L1R}"
379
251
 
380
252
  # Line 2: bar pct% CL | 5h used% ... 7d used% ...
381
253
  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.
254
+ # Session cost: only when usage data is unavailable in stdin.
386
255
  if [[ "$SHOW_COST" == "1" ]]; then
387
256
  printf -v _CS "\$%.2f" "$COST" 2>/dev/null
388
257
  [[ "$_CS" != "\$0.00" ]] && L2+=" $_CS"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-pace",
3
- "version": "0.7.3",
3
+ "version": "0.8.0",
4
4
  "description": "A statusline for Claude Code. Pure Bash + jq, single file.",
5
5
  "bin": {
6
6
  "claude-pace": "cli.js"
@@ -24,7 +24,7 @@
24
24
  "license": "MIT",
25
25
  "repository": {
26
26
  "type": "git",
27
- "url": "https://github.com/Astro-Han/claude-pace"
27
+ "url": "git+https://github.com/Astro-Han/claude-pace.git"
28
28
  },
29
29
  "engines": {
30
30
  "node": ">=16"