@abdallahaho/ccline 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Abdallah Othman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # ccline
2
+
3
+ A feature-rich statusline for [Claude Code](https://docs.anthropic.com/en/docs/claude-code) that helps you track session health, manage quota, and avoid burning through your Max plan.
4
+
5
+ ![demo](.github/demo.png)
6
+
7
+ ## What you get
8
+
9
+ **Line 1 — Identity & Project**
10
+ ```
11
+ O4.6 1M ● high | 📂 really-app (main*) 📝+147 -38 | → src/features/search
12
+ ```
13
+ - Compact model name with effort level
14
+ - Project root with git branch and dirty indicator
15
+ - Lines changed this session
16
+ - Current working directory (relative to project, fish-style if outside)
17
+
18
+ **Line 2 — Session Health**
19
+ ```
20
+ #84 turns | ⏱ 2h14m | 72% 720k/1m ctx compact? | $12.41
21
+ ```
22
+ - Turn counter (yellow at 30, red at 50 — time to start fresh)
23
+ - Session duration
24
+ - Context window usage with absolute tokens and compaction nudge at 60%+
25
+ - Running session cost (yellow at $5, red at $10)
26
+
27
+ **Lines 3-4 — Quota & Rate Limits**
28
+ ```
29
+ current ●●●●●●●○○○ 68% resets 3:42pm 🔥 PEAK til 8pm
30
+ weekly ●●●●●●●●○○ 81% resets apr 3, 7:00pm ~22%/day
31
+ ```
32
+ - 5-hour and 7-day rate limit bars via Anthropic OAuth API (cached, 60s TTL)
33
+ - Peak hour detection (05:00-11:00 PT) with local end time — only shows when active
34
+ - Weekly burn rate projection — green if on pace, yellow if tight, red if you'll hit the limit
35
+
36
+ ## Install
37
+
38
+ ```bash
39
+ npx @abdallahaho/ccline
40
+ ```
41
+
42
+ This copies the statusline script to `~/.claude/statusline.sh` and configures your `~/.claude/settings.json`. Restart Claude Code to see it.
43
+
44
+ If you already have a custom statusline, it's backed up to `statusline.sh.bak` first.
45
+
46
+ ## Requirements
47
+
48
+ - `jq`, `curl`, `git`
49
+ - Claude Code with an active Max/Pro subscription (for rate limit bars)
50
+
51
+ ```bash
52
+ # macOS
53
+ brew install jq
54
+
55
+ # Ubuntu/Debian
56
+ sudo apt install jq curl git
57
+ ```
58
+
59
+ ## Uninstall
60
+
61
+ ```bash
62
+ npx @abdallahaho/ccline --uninstall
63
+ ```
64
+
65
+ Restores your previous statusline if a backup exists, or removes it and cleans up settings.json.
66
+
67
+ ## How it works
68
+
69
+ Claude Code pipes a JSON blob to the statusline script on every render. The script extracts model info, context usage, session cost, and workspace data from that JSON. Rate limit data is fetched from the Anthropic OAuth API and cached for 60 seconds at `/tmp/claude/statusline-usage-cache.json`.
70
+
71
+ The OAuth token is resolved from (in order):
72
+ 1. `$CLAUDE_CODE_OAUTH_TOKEN` environment variable
73
+ 2. macOS Keychain
74
+ 3. `~/.claude/.credentials.json`
75
+ 4. Linux `secret-tool`
76
+
77
+ ## Credits
78
+
79
+ Heavily inspired by [kamranahmedse/claude-statusline](https://github.com/kamranahmedse/claude-statusline) by Kamran Ahmed.
80
+
81
+ ## License
82
+
83
+ MIT
package/bin/install.js ADDED
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const { execSync } = require("child_process");
6
+
7
+ const green = (t) => `\x1b[32m${t}\x1b[0m`;
8
+ const yellow = (t) => `\x1b[33m${t}\x1b[0m`;
9
+ const red = (t) => `\x1b[31m${t}\x1b[0m`;
10
+ const dim = (t) => `\x1b[2m${t}\x1b[0m`;
11
+
12
+ const ok = (msg) => console.log(` ${green("✓")} ${msg}`);
13
+ const warn = (msg) => console.log(` ${yellow("!")} ${msg}`);
14
+ const fail = (msg) => console.log(` ${red("✗")} ${msg}`);
15
+
16
+ const CLAUDE_DIR = path.join(process.env.HOME, ".claude");
17
+ const STATUSLINE_PATH = path.join(CLAUDE_DIR, "statusline.sh");
18
+ const SETTINGS_PATH = path.join(CLAUDE_DIR, "settings.json");
19
+ const SOURCE_PATH = path.resolve(__dirname, "statusline.sh");
20
+
21
+ const SETTINGS_ENTRY = {
22
+ type: "command",
23
+ command: 'bash "$HOME/.claude/statusline.sh"',
24
+ };
25
+
26
+ function checkDeps() {
27
+ const required = ["jq", "curl", "git"];
28
+ const missing = required.filter((cmd) => {
29
+ try {
30
+ execSync(`which ${cmd}`, { stdio: "ignore" });
31
+ return false;
32
+ } catch {
33
+ return true;
34
+ }
35
+ });
36
+
37
+ if (missing.length > 0) {
38
+ fail(`Missing dependencies: ${missing.join(", ")}`);
39
+ console.log(
40
+ `\n Install with: ${dim(`brew install ${missing.join(" ")}`)}`,
41
+ );
42
+ process.exit(1);
43
+ }
44
+ }
45
+
46
+ function readSettings() {
47
+ try {
48
+ return JSON.parse(fs.readFileSync(SETTINGS_PATH, "utf8"));
49
+ } catch {
50
+ return {};
51
+ }
52
+ }
53
+
54
+ function writeSettings(settings) {
55
+ fs.writeFileSync(SETTINGS_PATH, JSON.stringify(settings, null, 2) + "\n");
56
+ }
57
+
58
+ function install() {
59
+ console.log(`\n ${dim("claude-statusline")}\n`);
60
+
61
+ checkDeps();
62
+
63
+ fs.mkdirSync(CLAUDE_DIR, { recursive: true });
64
+
65
+ if (fs.existsSync(STATUSLINE_PATH)) {
66
+ fs.copyFileSync(STATUSLINE_PATH, `${STATUSLINE_PATH}.bak`);
67
+ warn("Backed up existing statusline.sh to statusline.sh.bak");
68
+ }
69
+
70
+ fs.copyFileSync(SOURCE_PATH, STATUSLINE_PATH);
71
+ fs.chmodSync(STATUSLINE_PATH, 0o755);
72
+ ok("Installed statusline.sh");
73
+
74
+ const settings = readSettings();
75
+ const current = JSON.stringify(settings.statusLine);
76
+ const expected = JSON.stringify(SETTINGS_ENTRY);
77
+
78
+ if (current !== expected) {
79
+ settings.statusLine = SETTINGS_ENTRY;
80
+ writeSettings(settings);
81
+ ok("Updated settings.json");
82
+ } else {
83
+ ok("settings.json already configured");
84
+ }
85
+
86
+ console.log(`\n ${green("Done!")} Restart Claude Code to see the new statusline.\n`);
87
+ }
88
+
89
+ function uninstall() {
90
+ console.log(`\n ${dim("claude-statusline --uninstall")}\n`);
91
+
92
+ const bakPath = `${STATUSLINE_PATH}.bak`;
93
+
94
+ if (fs.existsSync(bakPath)) {
95
+ fs.copyFileSync(bakPath, STATUSLINE_PATH);
96
+ fs.unlinkSync(bakPath);
97
+ ok("Restored previous statusline.sh from backup");
98
+ } else if (fs.existsSync(STATUSLINE_PATH)) {
99
+ fs.unlinkSync(STATUSLINE_PATH);
100
+ ok("Removed statusline.sh");
101
+ } else {
102
+ warn("No statusline.sh found");
103
+ }
104
+
105
+ if (fs.existsSync(SETTINGS_PATH)) {
106
+ const settings = readSettings();
107
+ if (settings.statusLine) {
108
+ delete settings.statusLine;
109
+ writeSettings(settings);
110
+ ok("Removed statusLine from settings.json");
111
+ }
112
+ }
113
+
114
+ console.log(`\n ${green("Done!")} Restart Claude Code to use the default statusline.\n`);
115
+ }
116
+
117
+ // ── Main ──
118
+ if (process.argv.includes("--uninstall")) {
119
+ uninstall();
120
+ } else {
121
+ install();
122
+ }
@@ -0,0 +1,458 @@
1
+ #!/bin/bash
2
+ set -f
3
+
4
+ input=$(cat)
5
+
6
+ if [ -z "$input" ]; then
7
+ printf "Claude"
8
+ exit 0
9
+ fi
10
+
11
+ # ── Colors ──────────────────────────────────────────────
12
+ blue='\033[38;2;0;153;255m'
13
+ orange='\033[38;2;255;176;85m'
14
+ green='\033[38;2;0;175;80m'
15
+ cyan='\033[38;2;86;182;194m'
16
+ red='\033[38;2;255;85;85m'
17
+ yellow='\033[38;2;230;200;0m'
18
+ white='\033[38;2;220;220;220m'
19
+ magenta='\033[38;2;180;140;255m'
20
+ dim='\033[2m'
21
+ reset='\033[0m'
22
+
23
+ sep=" ${dim}|${reset} "
24
+
25
+ # ── Helpers ─────────────────────────────────────────────
26
+ format_tokens() {
27
+ local num=$1
28
+ if [ "$num" -ge 1000000 ]; then
29
+ awk "BEGIN {printf \"%.1fm\", $num / 1000000}"
30
+ elif [ "$num" -ge 1000 ]; then
31
+ awk "BEGIN {printf \"%.0fk\", $num / 1000}"
32
+ else
33
+ printf "%d" "$num"
34
+ fi
35
+ }
36
+
37
+ color_for_pct() {
38
+ local pct=$1
39
+ if [ "$pct" -ge 90 ]; then printf "$red"
40
+ elif [ "$pct" -ge 70 ]; then printf "$yellow"
41
+ elif [ "$pct" -ge 50 ]; then printf "$orange"
42
+ else printf "$green"
43
+ fi
44
+ }
45
+
46
+ build_bar() {
47
+ local pct=$1
48
+ local width=$2
49
+ [ "$pct" -lt 0 ] 2>/dev/null && pct=0
50
+ [ "$pct" -gt 100 ] 2>/dev/null && pct=100
51
+
52
+ local filled=$(( pct * width / 100 ))
53
+ local empty=$(( width - filled ))
54
+ local bar_color
55
+ bar_color=$(color_for_pct "$pct")
56
+
57
+ local filled_str="" empty_str=""
58
+ for ((i=0; i<filled; i++)); do filled_str+="●"; done
59
+ for ((i=0; i<empty; i++)); do empty_str+="○"; done
60
+
61
+ printf "${bar_color}${filled_str}${dim}${empty_str}${reset}"
62
+ }
63
+
64
+ iso_to_epoch() {
65
+ local iso_str="$1"
66
+
67
+ local epoch
68
+ epoch=$(date -d "${iso_str}" +%s 2>/dev/null)
69
+ if [ -n "$epoch" ]; then
70
+ echo "$epoch"
71
+ return 0
72
+ fi
73
+
74
+ local stripped="${iso_str%%.*}"
75
+ stripped="${stripped%%Z}"
76
+ stripped="${stripped%%+*}"
77
+ stripped="${stripped%%-[0-9][0-9]:[0-9][0-9]}"
78
+
79
+ if [[ "$iso_str" == *"Z"* ]] || [[ "$iso_str" == *"+00:00"* ]] || [[ "$iso_str" == *"-00:00"* ]]; then
80
+ epoch=$(env TZ=UTC date -j -f "%Y-%m-%dT%H:%M:%S" "$stripped" +%s 2>/dev/null)
81
+ else
82
+ epoch=$(date -j -f "%Y-%m-%dT%H:%M:%S" "$stripped" +%s 2>/dev/null)
83
+ fi
84
+
85
+ if [ -n "$epoch" ]; then
86
+ echo "$epoch"
87
+ return 0
88
+ fi
89
+
90
+ return 1
91
+ }
92
+
93
+ format_reset_time() {
94
+ local iso_str="$1"
95
+ local style="$2"
96
+ [ -z "$iso_str" ] || [ "$iso_str" = "null" ] && return
97
+
98
+ local epoch
99
+ epoch=$(iso_to_epoch "$iso_str")
100
+ [ -z "$epoch" ] && return
101
+
102
+ local result=""
103
+ case "$style" in
104
+ time)
105
+ result=$(date -j -r "$epoch" +"%l:%M%p" 2>/dev/null | sed 's/^ //; s/\.//g' | tr '[:upper:]' '[:lower:]')
106
+ [ -z "$result" ] && result=$(date -d "@$epoch" +"%l:%M%P" 2>/dev/null | sed 's/^ //; s/\.//g')
107
+ ;;
108
+ datetime)
109
+ result=$(date -j -r "$epoch" +"%b %-d, %l:%M%p" 2>/dev/null | sed 's/ / /g; s/^ //; s/\.//g' | tr '[:upper:]' '[:lower:]')
110
+ [ -z "$result" ] && result=$(date -d "@$epoch" +"%b %-d, %l:%M%P" 2>/dev/null | sed 's/ / /g; s/^ //; s/\.//g')
111
+ ;;
112
+ *)
113
+ result=$(date -j -r "$epoch" +"%b %-d" 2>/dev/null | tr '[:upper:]' '[:lower:]')
114
+ [ -z "$result" ] && result=$(date -d "@$epoch" +"%b %-d" 2>/dev/null)
115
+ ;;
116
+ esac
117
+ printf "%s" "$result"
118
+ }
119
+
120
+ # ── Extract JSON data ───────────────────────────────────
121
+ model_name=$(echo "$input" | jq -r '.model.display_name // "Claude"')
122
+
123
+ # Shorten model: "Opus 4.6 (1M context)" -> "O4.6 1M"
124
+ model_short=$(echo "$model_name" | sed -E \
125
+ -e 's/Opus /O/' \
126
+ -e 's/Sonnet /S/' \
127
+ -e 's/Haiku /H/' \
128
+ -e 's/ *\(1M context\)/ 1M/' \
129
+ -e 's/ *\(200K context\)//')
130
+
131
+ size=$(echo "$input" | jq -r '.context_window.context_window_size // 200000')
132
+ [ "$size" -eq 0 ] 2>/dev/null && size=200000
133
+
134
+ input_tokens=$(echo "$input" | jq -r '.context_window.current_usage.input_tokens // 0')
135
+ cache_create=$(echo "$input" | jq -r '.context_window.current_usage.cache_creation_input_tokens // 0')
136
+ cache_read=$(echo "$input" | jq -r '.context_window.current_usage.cache_read_input_tokens // 0')
137
+ current=$(( input_tokens + cache_create + cache_read ))
138
+
139
+ used_tokens=$(format_tokens $current)
140
+ total_tokens=$(format_tokens $size)
141
+
142
+ if [ "$size" -gt 0 ]; then
143
+ pct_used=$(( current * 100 / size ))
144
+ else
145
+ pct_used=0
146
+ fi
147
+
148
+ # Cost & lines changed
149
+ session_cost=$(echo "$input" | jq -r '.cost.total_cost_usd // 0')
150
+ session_cost_fmt=$(awk "BEGIN {printf \"%.2f\", $session_cost}")
151
+ lines_added=$(echo "$input" | jq -r '.cost.total_lines_added // 0')
152
+ lines_removed=$(echo "$input" | jq -r '.cost.total_lines_removed // 0')
153
+
154
+ # Effort level
155
+ effort="default"
156
+ settings_path="$HOME/.claude/settings.json"
157
+ if [ -f "$settings_path" ]; then
158
+ effort=$(jq -r '.effortLevel // "default"' "$settings_path" 2>/dev/null)
159
+ fi
160
+
161
+ # ── Directory & git ────────────────────────────────────
162
+ cwd=$(echo "$input" | jq -r '.cwd // ""')
163
+ [ -z "$cwd" ] || [ "$cwd" = "null" ] && cwd=$(pwd)
164
+ project_dir=$(echo "$input" | jq -r '.workspace.project_dir // ""')
165
+ [ -z "$project_dir" ] || [ "$project_dir" = "null" ] && project_dir="$cwd"
166
+
167
+ # Project display name
168
+ if [ "$project_dir" = "$HOME" ]; then
169
+ project_name="~"
170
+ else
171
+ project_name=$(basename "$project_dir")
172
+ fi
173
+
174
+ # CWD relative to project (fish-style fallback if outside)
175
+ cwd_display=""
176
+ if [ "$cwd" != "$project_dir" ]; then
177
+ case "$cwd" in
178
+ "$project_dir"/*)
179
+ cwd_display="${cwd#$project_dir/}"
180
+ ;;
181
+ "$HOME"/*)
182
+ rel="${cwd#$HOME/}"
183
+ abbreviated=""
184
+ while [[ "$rel" == */* ]]; do
185
+ segment="${rel%%/*}"
186
+ abbreviated+="${segment:0:1}/"
187
+ rel="${rel#*/}"
188
+ done
189
+ cwd_display="~/${abbreviated}${rel}"
190
+ ;;
191
+ *)
192
+ cwd_display="$cwd"
193
+ ;;
194
+ esac
195
+ fi
196
+
197
+ git_branch=""
198
+ git_dirty=""
199
+ if git -C "$project_dir" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
200
+ git_branch=$(git -C "$project_dir" symbolic-ref --short HEAD 2>/dev/null)
201
+ if [ -n "$(git -C "$project_dir" status --porcelain 2>/dev/null)" ]; then
202
+ git_dirty="*"
203
+ fi
204
+ fi
205
+
206
+ # ── Turn counter ───────────────────────────────────────
207
+ turn_count=""
208
+ transcript_path=$(echo "$input" | jq -r '.transcript_path // empty')
209
+ if [ -n "$transcript_path" ] && [ -f "$transcript_path" ]; then
210
+ turn_count=$(grep -c '"type":"user"' "$transcript_path" 2>/dev/null || echo "0")
211
+ fi
212
+
213
+ # ── Session duration (from transcript file birthtime) ──
214
+ session_duration=""
215
+ if [ -n "$transcript_path" ] && [ -f "$transcript_path" ]; then
216
+ start_epoch=$(stat -f %B "$transcript_path" 2>/dev/null)
217
+ if [ -n "$start_epoch" ] && [ "$start_epoch" -gt 0 ] 2>/dev/null; then
218
+ now_epoch=$(date +%s)
219
+ elapsed=$(( now_epoch - start_epoch ))
220
+ if [ "$elapsed" -ge 3600 ]; then
221
+ session_duration="$(( elapsed / 3600 ))h$(( (elapsed % 3600) / 60 ))m"
222
+ elif [ "$elapsed" -ge 60 ]; then
223
+ session_duration="$(( elapsed / 60 ))m"
224
+ else
225
+ session_duration="${elapsed}s"
226
+ fi
227
+ fi
228
+ fi
229
+
230
+ # ── Peak detection (05:00-11:00 PT) ───────────────────
231
+ is_peak=false
232
+ peak_end_local=""
233
+ pt_hour=$(TZ="America/Los_Angeles" date +%-H 2>/dev/null)
234
+ if [ -n "$pt_hour" ] && [ "$pt_hour" -ge 5 ] && [ "$pt_hour" -lt 11 ]; then
235
+ is_peak=true
236
+ today_pt=$(TZ="America/Los_Angeles" date +%Y-%m-%d)
237
+ peak_end_epoch=$(TZ="America/Los_Angeles" date -j -f "%Y-%m-%d %H:%M:%S" "${today_pt} 11:00:00" +%s 2>/dev/null)
238
+ if [ -n "$peak_end_epoch" ]; then
239
+ peak_end_local=$(date -j -r "$peak_end_epoch" +"%l%p" 2>/dev/null | sed 's/^ //; s/\.//g' | tr '[:upper:]' '[:lower:]')
240
+ fi
241
+ fi
242
+
243
+ # ── LINE 1: Model+Effort | Project (branch) +lines | → cwd
244
+ line1=""
245
+
246
+ case "$effort" in
247
+ high) line1+="${blue}${model_short}${reset} ${magenta}● ${effort}${reset}" ;;
248
+ medium) line1+="${blue}${model_short}${reset} ${white}◑ ${effort}${reset}" ;;
249
+ low) line1+="${blue}${model_short}${reset} ${dim}◔ ${effort}${reset}" ;;
250
+ *) line1+="${blue}${model_short}${reset} ${dim}◑ ${effort}${reset}" ;;
251
+ esac
252
+
253
+ line1+="${sep}"
254
+
255
+ line1+="📂 ${cyan}${project_name}${reset}"
256
+ if [ -n "$git_branch" ]; then
257
+ line1+=" ${green}(${git_branch}${red}${git_dirty}${green})${reset}"
258
+ fi
259
+ if [ "$lines_added" -gt 0 ] || [ "$lines_removed" -gt 0 ]; then
260
+ line1+=" 📝${green}+${lines_added}${reset} ${red}-${lines_removed}${reset}"
261
+ fi
262
+
263
+ if [ -n "$cwd_display" ]; then
264
+ line1+="${sep}${dim}→${reset} ${white}${cwd_display}${reset}"
265
+ fi
266
+
267
+ # ── LINE 2: Session stats ─────────────────────────────
268
+ line2=""
269
+
270
+ if [ -n "$turn_count" ] && [ "$turn_count" -gt 0 ] 2>/dev/null; then
271
+ turn_color="$white"
272
+ [ "$turn_count" -ge 30 ] && turn_color="$yellow"
273
+ [ "$turn_count" -ge 50 ] && turn_color="$red"
274
+ line2+="${turn_color}#${turn_count}${reset} ${dim}turns${reset}"
275
+ fi
276
+
277
+ if [ -n "$session_duration" ]; then
278
+ [ -n "$line2" ] && line2+="${sep}"
279
+ line2+="⏱ ${white}${session_duration}${reset}"
280
+ fi
281
+
282
+ pct_color=$(color_for_pct "$pct_used")
283
+ [ -n "$line2" ] && line2+="${sep}"
284
+ line2+="${pct_color}${pct_used}%${reset} ${white}${used_tokens}/${total_tokens}${reset} ${dim}ctx${reset}"
285
+ if [ "$pct_used" -ge 60 ]; then
286
+ line2+=" ${yellow}compact?${reset}"
287
+ fi
288
+
289
+ if [ "$(awk "BEGIN {print ($session_cost > 0)}")" = "1" ]; then
290
+ line2+="${sep}"
291
+ cost_color="$white"
292
+ [ "$(awk "BEGIN {print ($session_cost >= 5)}")" = "1" ] && cost_color="$yellow"
293
+ [ "$(awk "BEGIN {print ($session_cost >= 10)}")" = "1" ] && cost_color="$red"
294
+ line2+="${cost_color}\$${session_cost_fmt}${reset}"
295
+ fi
296
+
297
+ # ── OAuth token resolution ──────────────────────────────
298
+ get_oauth_token() {
299
+ local token=""
300
+
301
+ if [ -n "$CLAUDE_CODE_OAUTH_TOKEN" ]; then
302
+ echo "$CLAUDE_CODE_OAUTH_TOKEN"
303
+ return 0
304
+ fi
305
+
306
+ if command -v security >/dev/null 2>&1; then
307
+ local blob
308
+ blob=$(security find-generic-password -s "Claude Code-credentials" -w 2>/dev/null)
309
+ if [ -n "$blob" ]; then
310
+ token=$(echo "$blob" | jq -r '.claudeAiOauth.accessToken // empty' 2>/dev/null)
311
+ if [ -n "$token" ] && [ "$token" != "null" ]; then
312
+ echo "$token"
313
+ return 0
314
+ fi
315
+ fi
316
+ fi
317
+
318
+ local creds_file="${HOME}/.claude/.credentials.json"
319
+ if [ -f "$creds_file" ]; then
320
+ token=$(jq -r '.claudeAiOauth.accessToken // empty' "$creds_file" 2>/dev/null)
321
+ if [ -n "$token" ] && [ "$token" != "null" ]; then
322
+ echo "$token"
323
+ return 0
324
+ fi
325
+ fi
326
+
327
+ if command -v secret-tool >/dev/null 2>&1; then
328
+ local blob
329
+ blob=$(timeout 2 secret-tool lookup service "Claude Code-credentials" 2>/dev/null)
330
+ if [ -n "$blob" ]; then
331
+ token=$(echo "$blob" | jq -r '.claudeAiOauth.accessToken // empty' 2>/dev/null)
332
+ if [ -n "$token" ] && [ "$token" != "null" ]; then
333
+ echo "$token"
334
+ return 0
335
+ fi
336
+ fi
337
+ fi
338
+
339
+ echo ""
340
+ }
341
+
342
+ # ── Fetch usage data (cached) ──────────────────────────
343
+ cache_file="/tmp/claude/statusline-usage-cache.json"
344
+ cache_max_age=60
345
+ mkdir -p /tmp/claude
346
+
347
+ needs_refresh=true
348
+ usage_data=""
349
+
350
+ if [ -f "$cache_file" ]; then
351
+ cache_mtime=$(stat -c %Y "$cache_file" 2>/dev/null || stat -f %m "$cache_file" 2>/dev/null)
352
+ now=$(date +%s)
353
+ cache_age=$(( now - cache_mtime ))
354
+ if [ "$cache_age" -lt "$cache_max_age" ]; then
355
+ needs_refresh=false
356
+ usage_data=$(cat "$cache_file" 2>/dev/null)
357
+ fi
358
+ fi
359
+
360
+ if $needs_refresh; then
361
+ token=$(get_oauth_token)
362
+ if [ -n "$token" ] && [ "$token" != "null" ]; then
363
+ response=$(curl -s --max-time 5 \
364
+ -H "Accept: application/json" \
365
+ -H "Content-Type: application/json" \
366
+ -H "Authorization: Bearer $token" \
367
+ -H "anthropic-beta: oauth-2025-04-20" \
368
+ -H "User-Agent: claude-code/2.1.34" \
369
+ "https://api.anthropic.com/api/oauth/usage" 2>/dev/null)
370
+ if [ -n "$response" ] && echo "$response" | jq -e '.five_hour' >/dev/null 2>&1; then
371
+ usage_data="$response"
372
+ echo "$response" > "$cache_file"
373
+ fi
374
+ fi
375
+ if [ -z "$usage_data" ] && [ -f "$cache_file" ]; then
376
+ usage_data=$(cat "$cache_file" 2>/dev/null)
377
+ fi
378
+ fi
379
+
380
+ # ── Rate limit lines ────────────────────────────────────
381
+ rate_lines=""
382
+
383
+ if [ -n "$usage_data" ] && echo "$usage_data" | jq -e . >/dev/null 2>&1; then
384
+ bar_width=8
385
+
386
+ # Current (5-hour)
387
+ five_hour_pct=$(echo "$usage_data" | jq -r '.five_hour.utilization // 0' | awk '{printf "%.0f", $1}')
388
+ five_hour_reset_iso=$(echo "$usage_data" | jq -r '.five_hour.resets_at // empty')
389
+ five_hour_reset=$(format_reset_time "$five_hour_reset_iso" "time")
390
+ five_hour_bar=$(build_bar "$five_hour_pct" "$bar_width")
391
+ five_hour_pct_color=$(color_for_pct "$five_hour_pct")
392
+ five_hour_pct_fmt=$(printf "%3d" "$five_hour_pct")
393
+
394
+ rate_lines+="${white}current${reset} ${five_hour_bar} ${five_hour_pct_color}${five_hour_pct_fmt}%${reset} ${dim}resets${reset} ${white}${five_hour_reset}${reset}"
395
+
396
+ if $is_peak; then
397
+ rate_lines+=" 🔥 ${red}PEAK${reset}"
398
+ if [ -n "$peak_end_local" ]; then
399
+ rate_lines+=" ${dim}til${reset} ${white}${peak_end_local}${reset}"
400
+ fi
401
+ fi
402
+
403
+ # Weekly (7-day)
404
+ seven_day_pct=$(echo "$usage_data" | jq -r '.seven_day.utilization // 0' | awk '{printf "%.0f", $1}')
405
+ seven_day_reset_iso=$(echo "$usage_data" | jq -r '.seven_day.resets_at // empty')
406
+ seven_day_reset=$(format_reset_time "$seven_day_reset_iso" "datetime")
407
+ seven_day_bar=$(build_bar "$seven_day_pct" "$bar_width")
408
+ seven_day_pct_color=$(color_for_pct "$seven_day_pct")
409
+ seven_day_pct_fmt=$(printf "%3d" "$seven_day_pct")
410
+
411
+ # Burn rate
412
+ burn_rate=""
413
+ if [ -n "$seven_day_reset_iso" ] && [ "$seven_day_pct" -gt 0 ]; then
414
+ reset_epoch=$(iso_to_epoch "$seven_day_reset_iso")
415
+ if [ -n "$reset_epoch" ]; then
416
+ now_epoch=$(date +%s)
417
+ secs_remaining=$(( reset_epoch - now_epoch ))
418
+ days_elapsed=$(awk "BEGIN {d = 7 - ($secs_remaining / 86400); if (d < 0.1) d = 0.1; printf \"%.1f\", d}")
419
+ burn_per_day=$(awk "BEGIN {printf \"%.0f\", $seven_day_pct / $days_elapsed}")
420
+ projected=$(awk "BEGIN {printf \"%.0f\", $burn_per_day * 7}")
421
+
422
+ burn_color="$green"
423
+ [ "$projected" -ge 80 ] 2>/dev/null && burn_color="$yellow"
424
+ [ "$projected" -ge 100 ] 2>/dev/null && burn_color="$red"
425
+
426
+ burn_rate="${burn_color}~${burn_per_day}%/day${reset}"
427
+ fi
428
+ fi
429
+
430
+ rate_lines+="\n${white}weekly${reset} ${seven_day_bar} ${seven_day_pct_color}${seven_day_pct_fmt}%${reset} ${dim}resets${reset} ${white}${seven_day_reset}${reset}"
431
+ if [ -n "$burn_rate" ]; then
432
+ rate_lines+=" ${burn_rate}"
433
+ fi
434
+
435
+ # Extra usage
436
+ extra_enabled=$(echo "$usage_data" | jq -r '.extra_usage.is_enabled // false')
437
+ if [ "$extra_enabled" = "true" ]; then
438
+ extra_pct=$(echo "$usage_data" | jq -r '.extra_usage.utilization // 0' | awk '{printf "%.0f", $1}')
439
+ extra_used=$(echo "$usage_data" | jq -r '.extra_usage.used_credits // 0' | awk '{printf "%.2f", $1/100}')
440
+ extra_limit=$(echo "$usage_data" | jq -r '.extra_usage.monthly_limit // 0' | awk '{printf "%.2f", $1/100}')
441
+ extra_bar=$(build_bar "$extra_pct" "$bar_width")
442
+ extra_pct_color=$(color_for_pct "$extra_pct")
443
+
444
+ extra_reset=$(date -v+1m -v1d +"%b %-d" 2>/dev/null | tr '[:upper:]' '[:lower:]')
445
+ if [ -z "$extra_reset" ]; then
446
+ extra_reset=$(date -d "$(date +%Y-%m-01) +1 month" +"%b %-d" 2>/dev/null | tr '[:upper:]' '[:lower:]')
447
+ fi
448
+
449
+ rate_lines+="\n${white}extra${reset} ${extra_bar} ${extra_pct_color}\$${extra_used}${dim}/${reset}${white}\$${extra_limit}${reset} ${dim}resets${reset} ${white}${extra_reset}${reset}"
450
+ fi
451
+ fi
452
+
453
+ # ── Output ──────────────────────────────────────────────
454
+ printf "%b\n" "$line1"
455
+ printf "%b\n" "$line2"
456
+ [ -n "$rate_lines" ] && printf "%b" "$rate_lines"
457
+
458
+ exit 0
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@abdallahaho/ccline",
3
+ "version": "1.0.0",
4
+ "description": "A feature-rich Claude Code statusline with session tracking, quota monitoring, peak hour detection, and burn rate projection",
5
+ "bin": {
6
+ "ccline": "bin/install.js"
7
+ },
8
+ "files": [
9
+ "bin/"
10
+ ],
11
+ "keywords": [
12
+ "claude",
13
+ "claude-code",
14
+ "statusline",
15
+ "cli",
16
+ "anthropic",
17
+ "developer-tools"
18
+ ],
19
+ "author": "Abdallah Othman",
20
+ "license": "MIT",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/AbdallahAHO/ccline.git"
24
+ },
25
+ "homepage": "https://github.com/AbdallahAHO/ccline",
26
+ "release-it": {
27
+ "git": {
28
+ "commitMessage": "chore: release v${version}",
29
+ "tagName": "v${version}"
30
+ },
31
+ "github": {
32
+ "release": true,
33
+ "releaseName": "v${version}"
34
+ },
35
+ "npm": {
36
+ "publish": true,
37
+ "publishArgs": [
38
+ "--access",
39
+ "public"
40
+ ]
41
+ },
42
+ "plugins": {
43
+ "@release-it/conventional-changelog": {
44
+ "preset": "angular",
45
+ "infile": "CHANGELOG.md"
46
+ }
47
+ },
48
+ "hooks": {
49
+ "before:init": [
50
+ "git log --oneline -5"
51
+ ]
52
+ }
53
+ }
54
+ }