@daliovic/cc-statusline 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 +21 -0
- package/README.md +94 -0
- package/dist/statusline.js +234 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
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,94 @@
|
|
|
1
|
+
# Claude Code Statusline
|
|
2
|
+
|
|
3
|
+
A minimal, informative statusline for [Claude Code](https://claude.ai/claude-code) CLI.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
🤖 Opus 4.5 │ 📊 53% 106K │ ⏱ 26% 2h09 ▼1h32/46% 2d15 ▼1d04
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Model indicator** - Shows current model (Opus, Sonnet, Haiku)
|
|
12
|
+
- **Context usage** - Percentage + token count (turns orange at 75%)
|
|
13
|
+
- **Usage limits** - 5-hour session and 7-day limits with reset times
|
|
14
|
+
- **Budget delta** - Shows if you're under (▼ green) or over (▲ red) your expected usage rate
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
### npm (recommended)
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install -g @daliovic/claude-statusline
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### From source
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
git clone https://github.com/YOUR_USERNAME/claude-statusline.git
|
|
28
|
+
cd claude-statusline
|
|
29
|
+
npm install
|
|
30
|
+
npm run build
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Configuration
|
|
34
|
+
|
|
35
|
+
Add to `~/.claude/settings.json`:
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"statusLine": {
|
|
40
|
+
"type": "command",
|
|
41
|
+
"command": "claude-statusline",
|
|
42
|
+
"padding": 0
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Or if installed from source:
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"statusLine": {
|
|
51
|
+
"type": "command",
|
|
52
|
+
"command": "node /path/to/claude-statusline/dist/statusline.js",
|
|
53
|
+
"padding": 0
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Environment Variables
|
|
59
|
+
|
|
60
|
+
| Variable | Default | Description |
|
|
61
|
+
|----------|---------|-------------|
|
|
62
|
+
| `STATUSLINE_CACHE_TTL_MS` | `300000` | API cache duration (5 min) |
|
|
63
|
+
|
|
64
|
+
## How It Works
|
|
65
|
+
|
|
66
|
+
- Reads session data from Claude Code via stdin
|
|
67
|
+
- Calculates context usage from transcript file
|
|
68
|
+
- Fetches usage limits from Anthropic OAuth API (cached)
|
|
69
|
+
- Budget delta shows time ahead/behind ideal linear usage
|
|
70
|
+
|
|
71
|
+
## Output Format
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
🤖 Model │ 📊 Context% Tokens │ ⏱ 5hr% Time Delta/7day% Time Delta
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Colors:**
|
|
78
|
+
- Cyan: Model name and icons
|
|
79
|
+
- Gray: Percentages and times
|
|
80
|
+
- Orange: Context at 75%+
|
|
81
|
+
- Green ▼: Under budget
|
|
82
|
+
- Red ▲: Over budget
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
MIT License - Do whatever you want with this. Attribution appreciated but not required.
|
|
87
|
+
|
|
88
|
+
## Credits
|
|
89
|
+
|
|
90
|
+
Inspired by:
|
|
91
|
+
- [claude-dashboard](https://github.com/uppinote20/claude-dashboard)
|
|
92
|
+
- [claude-statusline-powerline](https://github.com/spences10/claude-statusline-powerline)
|
|
93
|
+
- [ccstatusline](https://github.com/sirmalloc/ccstatusline)
|
|
94
|
+
- [Claude Usage Reticle](https://github.com/KatsuJinCode/claude-usage-reticle) (budget delta concept)
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync, writeFileSync, existsSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
// === Configuration ===
|
|
6
|
+
const CONFIG = {
|
|
7
|
+
cacheTtlMs: parseInt(process.env.STATUSLINE_CACHE_TTL_MS || "300000"), // 5 minutes default
|
|
8
|
+
cacheFile: join(homedir(), ".claude", "statusline-cache.json"),
|
|
9
|
+
credentialsFile: join(homedir(), ".claude", ".credentials.json"),
|
|
10
|
+
};
|
|
11
|
+
// === ANSI Colors ===
|
|
12
|
+
const color = {
|
|
13
|
+
reset: "\x1b[0m",
|
|
14
|
+
orange: "\x1b[38;5;208m",
|
|
15
|
+
dim: "\x1b[2m",
|
|
16
|
+
gray: "\x1b[38;5;248m",
|
|
17
|
+
cyan: "\x1b[36m",
|
|
18
|
+
green: "\x1b[32m",
|
|
19
|
+
red: "\x1b[31m",
|
|
20
|
+
};
|
|
21
|
+
// === Helpers ===
|
|
22
|
+
function formatTokens(tokens) {
|
|
23
|
+
if (tokens >= 1000) {
|
|
24
|
+
return `${Math.round(tokens / 1000)}K`;
|
|
25
|
+
}
|
|
26
|
+
return String(tokens);
|
|
27
|
+
}
|
|
28
|
+
function formatContext(ctx) {
|
|
29
|
+
if (ctx === undefined)
|
|
30
|
+
return "";
|
|
31
|
+
const c = ctx.percent >= 75 ? color.orange : color.gray;
|
|
32
|
+
return `${c}\u{1F4CA} ${Math.round(ctx.percent)}%${color.dim} ${formatTokens(ctx.tokens)}${color.reset}`;
|
|
33
|
+
}
|
|
34
|
+
function formatTimeHoursMinutes(isoDate) {
|
|
35
|
+
const diffMs = new Date(isoDate).getTime() - Date.now();
|
|
36
|
+
if (diffMs <= 0)
|
|
37
|
+
return "0h00";
|
|
38
|
+
const totalMins = Math.floor(diffMs / (1000 * 60));
|
|
39
|
+
const hours = Math.floor(totalMins / 60);
|
|
40
|
+
const mins = totalMins % 60;
|
|
41
|
+
return `${hours}h${String(mins).padStart(2, "0")}`;
|
|
42
|
+
}
|
|
43
|
+
function formatTimeDaysHours(isoDate) {
|
|
44
|
+
const diffMs = new Date(isoDate).getTime() - Date.now();
|
|
45
|
+
if (diffMs <= 0)
|
|
46
|
+
return "0d00";
|
|
47
|
+
const totalHours = Math.floor(diffMs / (1000 * 60 * 60));
|
|
48
|
+
const days = Math.floor(totalHours / 24);
|
|
49
|
+
const hours = totalHours % 24;
|
|
50
|
+
return `${days}d${String(hours).padStart(2, "0")}`;
|
|
51
|
+
}
|
|
52
|
+
function calcDelta(utilization, resetAt, windowHours) {
|
|
53
|
+
const resetMs = new Date(resetAt).getTime();
|
|
54
|
+
const nowMs = Date.now();
|
|
55
|
+
const timeLeftMs = resetMs - nowMs;
|
|
56
|
+
const windowMs = windowHours * 60 * 60 * 1000;
|
|
57
|
+
const elapsedMs = windowMs - timeLeftMs;
|
|
58
|
+
const expectedPct = (elapsedMs / windowMs) * 100;
|
|
59
|
+
return utilization - expectedPct; // negative = under, positive = over
|
|
60
|
+
}
|
|
61
|
+
function formatDeltaTime(delta, windowHours) {
|
|
62
|
+
const absDelta = Math.abs(delta);
|
|
63
|
+
if (absDelta < 1)
|
|
64
|
+
return "";
|
|
65
|
+
// Convert percentage delta to hours
|
|
66
|
+
const deltaHours = (absDelta / 100) * windowHours;
|
|
67
|
+
let timeStr;
|
|
68
|
+
if (windowHours <= 5) {
|
|
69
|
+
// 5-hour window: show hours and minutes
|
|
70
|
+
const hours = Math.floor(deltaHours);
|
|
71
|
+
const mins = Math.round((deltaHours - hours) * 60);
|
|
72
|
+
timeStr = `${hours}h${String(mins).padStart(2, "0")}`;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
// 7-day window: show days and hours
|
|
76
|
+
const days = Math.floor(deltaHours / 24);
|
|
77
|
+
const hours = Math.round(deltaHours % 24);
|
|
78
|
+
timeStr = `${days}d${String(hours).padStart(2, "0")}`;
|
|
79
|
+
}
|
|
80
|
+
if (delta < 0) {
|
|
81
|
+
return ` ${color.dim}${color.green}\u{25BC}${timeStr}${color.reset}`;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
return ` ${color.dim}${color.red}\u{25B2}${timeStr}${color.reset}`;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Context window sizes by model
|
|
88
|
+
const CONTEXT_SIZES = {
|
|
89
|
+
"opus": 200000,
|
|
90
|
+
"sonnet": 200000,
|
|
91
|
+
"haiku": 200000,
|
|
92
|
+
};
|
|
93
|
+
function getContextFromTranscript(transcriptPath, modelId) {
|
|
94
|
+
try {
|
|
95
|
+
if (!existsSync(transcriptPath))
|
|
96
|
+
return undefined;
|
|
97
|
+
const content = readFileSync(transcriptPath, "utf-8");
|
|
98
|
+
const lines = content.trim().split("\n");
|
|
99
|
+
// Find last line with usage data
|
|
100
|
+
let lastUsage;
|
|
101
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
102
|
+
try {
|
|
103
|
+
const entry = JSON.parse(lines[i]);
|
|
104
|
+
if (entry.message?.usage) {
|
|
105
|
+
lastUsage = entry.message.usage;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (!lastUsage)
|
|
114
|
+
return undefined;
|
|
115
|
+
// Calculate total tokens
|
|
116
|
+
const totalTokens = (lastUsage.input_tokens || 0) +
|
|
117
|
+
(lastUsage.output_tokens || 0) +
|
|
118
|
+
(lastUsage.cache_read_input_tokens || 0) +
|
|
119
|
+
(lastUsage.cache_creation_input_tokens || 0);
|
|
120
|
+
// Get context size for model
|
|
121
|
+
const modelKey = modelId?.split("-")[1]?.toLowerCase() || "opus";
|
|
122
|
+
const contextSize = CONTEXT_SIZES[modelKey] || 200000;
|
|
123
|
+
return {
|
|
124
|
+
percent: (totalTokens / contextSize) * 100,
|
|
125
|
+
tokens: totalTokens,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// === OAuth Usage API ===
|
|
133
|
+
async function fetchUsageFromApi() {
|
|
134
|
+
try {
|
|
135
|
+
if (!existsSync(CONFIG.credentialsFile))
|
|
136
|
+
return null;
|
|
137
|
+
const creds = JSON.parse(readFileSync(CONFIG.credentialsFile, "utf-8"));
|
|
138
|
+
const token = creds.claudeAiOauth?.accessToken;
|
|
139
|
+
if (!token)
|
|
140
|
+
return null;
|
|
141
|
+
const res = await fetch("https://api.anthropic.com/api/oauth/usage", {
|
|
142
|
+
headers: {
|
|
143
|
+
Authorization: `Bearer ${token}`,
|
|
144
|
+
"anthropic-beta": "oauth-2025-04-20",
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
if (!res.ok)
|
|
148
|
+
return null;
|
|
149
|
+
return (await res.json());
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
async function getUsageData() {
|
|
156
|
+
// Check cache
|
|
157
|
+
if (existsSync(CONFIG.cacheFile)) {
|
|
158
|
+
try {
|
|
159
|
+
const cache = JSON.parse(readFileSync(CONFIG.cacheFile, "utf-8"));
|
|
160
|
+
if (cache.timestamp && Date.now() - cache.timestamp < CONFIG.cacheTtlMs) {
|
|
161
|
+
return cache.usage;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
// Cache invalid, fetch fresh
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// Fetch fresh data
|
|
169
|
+
const usage = await fetchUsageFromApi();
|
|
170
|
+
if (usage) {
|
|
171
|
+
const cacheData = { timestamp: Date.now(), usage };
|
|
172
|
+
try {
|
|
173
|
+
writeFileSync(CONFIG.cacheFile, JSON.stringify(cacheData));
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
// Ignore cache write errors
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return usage;
|
|
180
|
+
}
|
|
181
|
+
// === Main ===
|
|
182
|
+
async function main() {
|
|
183
|
+
// Read stdin
|
|
184
|
+
let stdin = {};
|
|
185
|
+
try {
|
|
186
|
+
const input = readFileSync(0, "utf-8");
|
|
187
|
+
stdin = JSON.parse(input);
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
// No stdin or invalid JSON
|
|
191
|
+
}
|
|
192
|
+
// Extract model info
|
|
193
|
+
const modelName = stdin.model?.display_name || stdin.model?.id?.split("-")[1] || "?";
|
|
194
|
+
const modelDisplay = modelName.charAt(0).toUpperCase() + modelName.slice(1);
|
|
195
|
+
// Extract context usage from transcript
|
|
196
|
+
let contextInfo;
|
|
197
|
+
if (stdin.transcript_path) {
|
|
198
|
+
contextInfo = getContextFromTranscript(stdin.transcript_path, stdin.model?.id);
|
|
199
|
+
}
|
|
200
|
+
// Get usage limits (async)
|
|
201
|
+
const usage = await getUsageData();
|
|
202
|
+
// Build segments
|
|
203
|
+
const segments = [];
|
|
204
|
+
// Model
|
|
205
|
+
segments.push(`${color.cyan}\u{1F916} ${modelDisplay}${color.reset}`);
|
|
206
|
+
// Context %
|
|
207
|
+
if (contextInfo !== undefined) {
|
|
208
|
+
segments.push(formatContext(contextInfo));
|
|
209
|
+
}
|
|
210
|
+
// Combined usage limits: ⏱ 18% 180 / 45% 48
|
|
211
|
+
if (usage?.five_hour || usage?.seven_day) {
|
|
212
|
+
const fiveHr = usage.five_hour;
|
|
213
|
+
const sevenDay = usage.seven_day;
|
|
214
|
+
const parts = [];
|
|
215
|
+
if (fiveHr?.utilization !== undefined && fiveHr.resets_at) {
|
|
216
|
+
const time = formatTimeHoursMinutes(fiveHr.resets_at);
|
|
217
|
+
const delta = calcDelta(fiveHr.utilization, fiveHr.resets_at, 5);
|
|
218
|
+
const deltaStr = formatDeltaTime(delta, 5);
|
|
219
|
+
parts.push(`${color.gray}${Math.round(fiveHr.utilization)}%${color.dim} ${time}${deltaStr}${color.reset}`);
|
|
220
|
+
}
|
|
221
|
+
if (sevenDay?.utilization !== undefined && sevenDay.resets_at) {
|
|
222
|
+
const time = formatTimeDaysHours(sevenDay.resets_at);
|
|
223
|
+
const delta = calcDelta(sevenDay.utilization, sevenDay.resets_at, 168);
|
|
224
|
+
const deltaStr = formatDeltaTime(delta, 168);
|
|
225
|
+
parts.push(`${color.gray}${Math.round(sevenDay.utilization)}%${color.dim} ${time}${deltaStr}${color.reset}`);
|
|
226
|
+
}
|
|
227
|
+
if (parts.length > 0) {
|
|
228
|
+
segments.push(`${color.cyan}\u{23F1}${color.reset} ${parts.join(`${color.dim}/${color.reset}`)}`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
// Output
|
|
232
|
+
console.log(segments.join(` ${color.dim}\u{2502}${color.reset} `));
|
|
233
|
+
}
|
|
234
|
+
main().catch(() => process.exit(1));
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@daliovic/cc-statusline",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Minimal Claude Code statusline with usage limits and budget tracking",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/statusline.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"cc-statusline": "dist/statusline.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"prepublishOnly": "npm run build"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/daliovic/cc-statusline.git"
|
|
20
|
+
},
|
|
21
|
+
"author": "daliovic",
|
|
22
|
+
"keywords": [
|
|
23
|
+
"claude",
|
|
24
|
+
"claude-code",
|
|
25
|
+
"statusline",
|
|
26
|
+
"cli",
|
|
27
|
+
"anthropic"
|
|
28
|
+
],
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18.0.0"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/daliovic/cc-statusline/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/daliovic/cc-statusline#readme",
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^22.0.0",
|
|
39
|
+
"typescript": "^5.0.0"
|
|
40
|
+
}
|
|
41
|
+
}
|