@say8425/cc-statusline 2.1.1 → 3.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.
Files changed (3) hide show
  1. package/README.md +11 -26
  2. package/dist/index.js +9 -6
  3. package/package.json +4 -4
package/README.md CHANGED
@@ -59,9 +59,9 @@ Add the following to `~/.claude/settings.json`:
59
59
  - **Worktree Support**: Shows real project name when running in a `cc --worktree` session
60
60
  - **TrueColor**: Dynamic colors based on thresholds
61
61
  - **Limit Reset Time**: Reset time display (HH:MM)
62
- - **Block Usage**: 5-hour utilization percentage (from server API)
62
+ - **Block Usage**: 5-hour utilization percentage
63
63
  - **Weekly Reset Timer**: Weekly limit reset time (MM/DD HH:MM)
64
- - **Weekly Usage**: 7-day utilization percentage (from server API)
64
+ - **Weekly Usage**: 7-day utilization percentage
65
65
 
66
66
  ## Emoji Guide
67
67
 
@@ -82,36 +82,21 @@ Add the following to `~/.claude/settings.json`:
82
82
 
83
83
  ## Usage Metrics
84
84
 
85
- Shows usage information from the Anthropic Usage API.
86
-
87
- > [!WARNING]
88
- > The `--show-usage` feature uses an unofficial, reverse-engineered Anthropic API endpoint to retrieve usage data. This is not an officially supported API, and may break or change at any time without notice. **Use at your own risk.** The author assumes no responsibility for any consequences, including but not limited to account restrictions or service disruptions, that may arise from the use of this feature.
89
-
90
- > [!NOTE]
91
- > This feature is **macOS only** as it reads the OAuth token from macOS Keychain (`Claude Code-credentials`).
85
+ Shows usage information from Claude Code's stdin JSON input.
92
86
 
93
87
  ### How It Works
94
88
 
95
- Calls the Anthropic Usage API (`/api/oauth/usage`) using the OAuth access token from macOS Keychain to retrieve:
96
-
97
- 1. **5-hour utilization** - Server-calculated usage percentage for the current billing block
98
- 2. **7-day utilization** - Server-calculated weekly usage percentage
99
- 3. **Reset timer** - Exact reset time from the server (`five_hour.resets_at`)
100
- 4. **Weekly reset timer** - Weekly limit reset time (`seven_day.resets_at`), shown as `MM/DD HH:MM` (e.g., `02/15 17:00`)
89
+ Claude Code passes `rate_limits` in the stdin JSON input (CLI 2.1.80+):
101
90
 
102
- ### Enable
91
+ 1. **5-hour utilization** - Usage percentage for the current billing block (`rate_limits.five_hour.used_percentage`)
92
+ 2. **7-day utilization** - Weekly usage percentage (`rate_limits.seven_day.used_percentage`)
93
+ 3. **Reset timer** - Exact reset time (`rate_limits.five_hour.resets_at`), shown as `HH:MM`
94
+ 4. **Weekly reset timer** - Weekly limit reset time (`rate_limits.seven_day.resets_at`), shown as `MM/DD HH:MM` (e.g., `02/15 17:00`)
103
95
 
104
- Usage metrics are **hidden by default**. To enable, use the `--show-usage` flag:
96
+ Usage metrics are **automatically displayed** when `rate_limits` is present in the stdin JSON. No additional flags or configuration needed.
105
97
 
106
- ```json
107
- {
108
- "statusLine": {
109
- "type": "command",
110
- "command": "bunx @say8425/cc-statusline --show-usage",
111
- "padding": 0
112
- }
113
- }
114
- ```
98
+ > [!NOTE]
99
+ > `rate_limits` is only available for Claude.ai subscribers (Pro/Max) after the first API response. See the [official statusline docs](https://code.claude.com/docs/en/statusline) for the full JSON schema.
115
100
 
116
101
  ## Dependencies
117
102
 
package/dist/index.js CHANGED
@@ -135,11 +135,6 @@ function renderStatusLine(ctx) {
135
135
  const sessionHrs = Math.floor(sessionSec / 3600);
136
136
  const sessionMins = Math.floor(sessionSec % 3600 / 60);
137
137
  const costUsd = ctx.claudeJson.cost?.total_cost_usd || 0;
138
- const usage = ctx.claudeJson.context_window?.current_usage;
139
- const contextSize = ctx.claudeJson.context_window?.context_window_size || 200000;
140
- const totalTokens = usage ? usage.input_tokens + usage.output_tokens + usage.cache_creation_input_tokens + usage.cache_read_input_tokens : 0;
141
- const contextPct = Math.round(totalTokens / contextSize * 100);
142
- const ctxColor = getUsageColor(contextPct);
143
138
  let line1;
144
139
  if (ctx.mainProjectName) {
145
140
  line1 = `${C.WHITE}\uD83D\uDCC1 ${ctx.mainProjectName}${C.RESET} | ${C.WHITE}\uD83C\uDF32 ${folder}${C.RESET}`;
@@ -150,7 +145,15 @@ function renderStatusLine(ctx) {
150
145
  line1 += ` | ${C.WHITE}\uD83C\uDF3F ${ctx.branch}${C.RESET}`;
151
146
  }
152
147
  lines.push(line1);
153
- const line2 = `${C.WHITE}\u23F1\uFE0F ${formatTime(sessionHrs, sessionMins)}${C.RESET}` + ` | ${C.WHITE}\uD83D\uDCB0 $${costUsd.toFixed(2)}${C.RESET}` + ` | ${ctxColor}\uD83E\uDDE0 ${formatNumber(totalTokens)} (${contextPct}%)${C.RESET}`;
148
+ let line2 = `${C.WHITE}\u23F1\uFE0F ${formatTime(sessionHrs, sessionMins)}${C.RESET}` + ` | ${C.WHITE}\uD83D\uDCB0 $${costUsd.toFixed(2)}${C.RESET}`;
149
+ const usedPercentage = ctx.claudeJson.context_window?.used_percentage;
150
+ if (usedPercentage != null) {
151
+ const usage = ctx.claudeJson.context_window?.current_usage;
152
+ const totalTokens = usage ? usage.input_tokens + usage.output_tokens + usage.cache_creation_input_tokens + usage.cache_read_input_tokens : 0;
153
+ const contextPct = Math.round(usedPercentage);
154
+ const ctxColor = getUsageColor(contextPct);
155
+ line2 += ` | ${ctxColor}\uD83E\uDDE0 ${formatNumber(totalTokens)} (${contextPct}%)${C.RESET}`;
156
+ }
154
157
  lines.push(line2);
155
158
  if (ctx.rateLimits) {
156
159
  const parts = [];
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@say8425/cc-statusline",
3
- "version": "2.1.1",
3
+ "version": "3.0.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/say8425/cc-statusline.git"
7
7
  },
8
8
  "devDependencies": {
9
- "@biomejs/biome": "^2.3.9",
10
- "@types/bun": "latest",
11
- "typescript": "^5.9.3"
9
+ "@biomejs/biome": "^2.4.11",
10
+ "@types/bun": "^1.3.12",
11
+ "typescript": "^6.0.2"
12
12
  },
13
13
  "bin": {
14
14
  "cc-statusline": "dist/index.js"