Last active
April 29, 2026 18:51
-
-
Save itsdevdom/764d70af1b7fefdf8b3cf46f072395f3 to your computer and use it in GitHub Desktop.
Claude Statusline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * HOW TO USE | |
| * | |
| * Copy `statusline.js` (e.g. into your `.claude` folder), and remember its <ABSOLUTE PATH>. | |
| * Then, add the following configuration to your `.claude/settings.json` file: | |
| * ```json | |
| * "statusLine": { | |
| * "type": "command", | |
| * "command": "node --no-warnings <ABSOLUTE_PATH>/statusline.js", | |
| * "refreshInterval": 60000 | |
| * } | |
| * ```json | |
| */ | |
| const DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; | |
| const toDate = (value) => { | |
| if (typeof value !== 'number' || !Number.isFinite(value)) { | |
| return null; | |
| } | |
| return new Date(value * 1000); | |
| }; | |
| const formatRemaining = (value) => { | |
| const date = toDate(value); | |
| if (!date) { | |
| return null; | |
| } | |
| const diffMs = date.getTime() - Date.now(); | |
| if (diffMs <= 0) { | |
| return null; | |
| } | |
| const totalMinutes = Math.round(diffMs / 60000); | |
| const hours = Math.floor(totalMinutes / 60); | |
| const minutes = totalMinutes % 60; | |
| return hours > 0 ? `${hours}h ${minutes}m` : `${minutes}m`; | |
| }; | |
| const formatDayTime = (value) => { | |
| const date = toDate(value); | |
| if (!date || date.getTime() <= Date.now()) { | |
| return null; | |
| } | |
| const hours = String(date.getHours()).padStart(2, '0'); | |
| const minutes = String(date.getMinutes()).padStart(2, '0'); | |
| return `${DAYS[date.getDay()]} ${hours}:${minutes}`; | |
| }; | |
| let data = ''; | |
| process.stdin.on('data', (chunk) => (data += chunk)); | |
| process.stdin.on('end', () => { | |
| let output = 'Claude'; | |
| try { | |
| const status = JSON.parse(data); | |
| const model = status.model?.display_name ?? 'Claude'; | |
| const fiveHour = status.rate_limits?.five_hour?.used_percentage; | |
| const fiveHourReset = status.rate_limits?.five_hour?.resets_at; | |
| const sevenDay = status.rate_limits?.seven_day?.used_percentage; | |
| const sevenDayReset = status.rate_limits?.seven_day?.resets_at; | |
| const context = status.context_window?.used_percentage; | |
| const modelLabel = typeof context === 'number' ? `${model} [${Math.round(context)}%]` : model; | |
| const parts = []; | |
| if (typeof fiveHour === 'number') { | |
| const remaining = formatRemaining(fiveHourReset); | |
| parts.push(remaining ? `5h: ${Math.round(fiveHour)}% (${remaining})` : `5h: ${Math.round(fiveHour)}%`); | |
| } | |
| if (typeof sevenDay === 'number') { | |
| const reset = formatDayTime(sevenDayReset); | |
| parts.push(reset ? `7d: ${Math.round(sevenDay)}% (${reset})` : `7d: ${Math.round(sevenDay)}%`); | |
| } | |
| output = parts.length ? `${modelLabel} | ${parts.join(' | ')}` : modelLabel; | |
| } catch {} | |
| process.stdout.write(output); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment