Skip to content

Commit 0f9a12c

Browse files
committed
feat(statusline): add JSON rate_limits parsing and enhanced setup interview
Parse rate_limits directly from Claude Code's stdin JSON input, avoiding separate API calls when data is available. Add priority cascade: JSON input → file cache → API fetch. Update setup interview with context style, separator, and section visibility options. Update config command with sub-menu for targeted configuration changes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent baae0d9 commit 0f9a12c

2 files changed

Lines changed: 91 additions & 95 deletions

File tree

statusline/commands/config.md

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,97 @@
11
# /statusline:config
22

3-
Configure the statusline display format.
3+
Configure the statusline display format and preferences.
44

55
## Action Required
66

7-
When this command is invoked, you MUST use the AskUserQuestion tool to ask:
7+
When this command is invoked, ask the user what they want to change using AskUserQuestion:
88

9-
### Question: Line Format
9+
### Question: What to Configure
1010

11-
Ask the user which display format they prefer:
11+
**Header**: "Config"
12+
**Question**: "What would you like to configure?"
13+
**Options**:
14+
1. **Layout** — Number of lines (1/2/3)
15+
2. **Sections** — Which info to show/hide
16+
3. **Context style** — How context usage is displayed
17+
4. **Reset to defaults**
1218

13-
**Header**: "Lines"
14-
**Question**: "How many lines should the statusline display?"
19+
### If Layout selected:
1520

21+
**Header**: "Layout"
22+
**Question**: "How many lines should the statusline display?"
1623
**Options**:
17-
1. **1 line (Compact)**`dir (branch) │ ModelCtx% │ RateTasks`
24+
1. **1 line (Compact)**`dir │ modelctx% │ ratetasks`
1825
2. **2 lines** — Line 1: location/model, Line 2: all metrics
19-
3. **3 lines (Default)** — Full layout with progress bar, token details, and activity
26+
3. **3 lines** — Full layout with progress bar, token details, activity
27+
28+
### If Sections selected:
29+
30+
**Header**: "Sections"
31+
**Question**: "Which sections should be visible?"
32+
**multiSelect**: true
33+
**Options**:
34+
1. **Context usage** — Token count and percentage
35+
2. **Rate limits** — API usage percentages and reset timers
36+
3. **Git branch** — Current branch name
37+
4. **Active tools** — Running MCP servers
38+
39+
### If Context style selected:
40+
41+
**Header**: "Context"
42+
**Question**: "How should context usage be displayed?"
43+
**Options**:
44+
1. **Compact**`ctx: 21%`
45+
2. **With tokens**`ctx: 21% 43k/200k`
46+
3. **Progress bar**`██░░░░░░░░ 21% (43k/200k)`
2047

2148
### Save Configuration
2249

23-
After the user answers, save their choice to `~/.claude/statusline.config.json`:
50+
Update `~/.claude/statusline.config.json` with the new values. Keep existing values for any settings not changed:
2451

2552
```json
2653
{
27-
"line_format": "1"
54+
"line_format": "2",
55+
"show_context": true,
56+
"show_rate_limits": true,
57+
"show_git_branch": true,
58+
"show_tools": true,
59+
"context_style": "tokens",
60+
"separator": "pipe"
2861
}
2962
```
3063

31-
Use values: `"1"`, `"2"`, or `"3"`
32-
3364
### Confirm
3465

3566
Output:
3667
```
37-
✓ Statusline configured: [N]-line format
68+
✓ Statusline updated: [setting changed]
3869
Config saved to ~/.claude/statusline.config.json
3970
```
4071

41-
## Example Outputs
42-
43-
**Anthropic** (Claude, Opus, Sonnet):
72+
## Example Outputs by Provider
4473

45-
1-line:
74+
**Anthropic** (2-line, tokens style):
4675
```
47-
claude-plugins (master) │ Opus 4.5 │ ctx: 21% 43k/200k │ 5h: 42% 7d: 28%
76+
claude-plugins (master) │ claude-opus-4-5-20251101 │ v2.0.76
77+
ctx: 21% 43k/200k │ 5h: 42% │ 7d: 28% │ Tasks: 2/5
4878
```
4979

50-
2-line:
80+
**z.ai GLM** (2-line, tokens style):
5181
```
52-
claude-plugins (master) │ Opus 4.5 │ v2.0.76
53-
ctx: 21% 43k/200k │ 5h: 42% │ 7d: 28% │ Tasks: 2/5 (40%)
82+
claude-plugins (master) │ glm-5.1 │ v2.0.76
83+
ctx: 21% 43k/200k │ tokens: 15% │ tools: 11% (883 left) Web:35 ZRead:82
5484
```
5585

56-
3-line:
86+
**Anthropic** (3-line, progress_bar style):
5787
```
58-
claude-plugins (master) │ Opus 4.5 │ v2.0.76 │ explanatory
88+
claude-plugins (master) │ claude-opus-4-5-20251101 │ v2.0.76 │ explanatory
5989
ctx: ██░░░░░░░░ 21% (43k/200k tokens) │ 5h: 42% │ 7d: 28%
6090
Tools: Seq Ctx7 │ Agents: 2 active │ Tasks: 1/5 (20%)
6191
```
6292

63-
**z.ai GLM** (glm-5.1, glm-4, etc.):
64-
65-
1-line:
66-
```
67-
claude-plugins (master) │ GLM 5.1 │ ctx: 21% 43k/200k │ tokens: 15% │ tools: 11% (883 left)
68-
```
69-
70-
2-line:
71-
```
72-
claude-plugins (master) │ GLM 5.1 │ v2.0.76
73-
ctx: 21% 43k/200k │ tokens: 15% │ tools: 11% (883 left) Web:35 ZRead:82
74-
```
75-
76-
3-line:
77-
```
78-
claude-plugins (master) │ GLM 5.1 │ v2.0.76 │ explanatory
79-
ctx: ██░░░░░░░░ 21% (43k/200k tokens) │ tokens: 15% │ tools: 11% (883 left) Web:35 ZRead:82
80-
Tools: Seq Ctx7 │ Agents: 1 active
81-
```
82-
83-
**Note**: Empty values are automatically hidden (no "None", no "0%", no "No tasks").
84-
Provider is auto-detected from the model name.
85-
8693
## Related Commands
8794

95+
- `/statusline:setup` — Full interactive setup wizard
8896
- `/statusline:status` — View current metrics
8997
- `/statusline:disable` — Disable monitoring

statusline/commands/setup.md

Lines changed: 37 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,57 +8,65 @@ When this command is invoked, conduct an interview using AskUserQuestion, then g
88

99
### Interview Questions
1010

11-
Use AskUserQuestion to ask these questions (can ask multiple in one call):
11+
Use AskUserQuestion to ask these questions (up to 4 at a time):
1212

1313
#### Q1: Line Format
14-
**Header**: "Lines"
14+
**Header**: "Layout"
1515
**Question**: "How many lines should the statusline display?"
1616
**Options**:
1717
1. **1 line (Compact)** — Everything on one line
1818
2. **2 lines** — Location/model + metrics (Recommended)
19-
3. **3 lines** — Full layout with separate sections
19+
3. **3 lines** — Full layout with progress bar and token details
2020

21-
#### Q2: Information to Show
21+
#### Q2: Information Sections
2222
**Header**: "Show"
2323
**Question**: "What information do you want to see?"
2424
**multiSelect**: true
2525
**Options**:
26-
1. **Context usage** — Token count and percentage
27-
2. **Rate limits**5-hour and 7-day API usage
26+
1. **Context usage** — Token count, percentage, progress bar
27+
2. **Rate limits**API usage (5h/7d for Anthropic, tokens/tools for GLM)
2828
3. **Git branch** — Current branch name
29-
4. **Active tools** — Running MCP servers/tools
29+
4. **Active tools** — Running MCP servers and tool counts
3030

31-
#### Q3: Color Style
32-
**Header**: "Colors"
33-
**Question**: "What color style do you prefer?"
31+
#### Q3: Context Display Style
32+
**Header**: "Context"
33+
**Question**: "How should context usage be displayed?"
3434
**Options**:
35-
1. **Colorful**Full color with health indicators (Recommended)
36-
2. **Minimal**Muted colors, less visual noise
37-
3. **Plain**No colors (for simple terminals)
35+
1. **Compact**Just percentage: `ctx: 21%`
36+
2. **With tokens**Percentage + token counts: `ctx: 21% 43k/200k`
37+
3. **Progress bar**Visual bar + details: `██░░ 21% (43k/200k)`
3838

39-
### Generate Statusline Script
39+
#### Q4: Separator Style
40+
**Header**: "Separator"
41+
**Question**: "What separator style between sections?"
42+
**Options**:
43+
1. **Pipe**`` vertical bar (Recommended)
44+
2. **Slash**`/` forward slash
45+
3. **Dot**`·` middle dot
46+
4. **Arrow**`` arrow
4047

41-
Based on answers, generate `~/.claude/statusline-command.sh` with the user's preferences:
48+
### Generate Statusline Script
4249

43-
1. Read the current script at `~/.claude/statusline-command.sh`
44-
2. Modify the configuration section based on answers:
45-
- Set `line_format` based on Q1
46-
- Enable/disable sections based on Q2
47-
- Set color intensity based on Q3
48-
3. Save the updated script
50+
Based on answers, update `~/.claude/statusline.config.json`:
4951

50-
Also save config to `~/.claude/statusline.config.json`:
5152
```json
5253
{
5354
"line_format": "2",
5455
"show_context": true,
5556
"show_rate_limits": true,
5657
"show_git_branch": true,
5758
"show_tools": true,
59+
"show_agents": true,
60+
"show_tasks": true,
61+
"context_style": "compact",
62+
"separator": "pipe",
5863
"color_style": "colorful"
5964
}
6065
```
6166

67+
**Context style values**: `"compact"`, `"tokens"`, `"progress_bar"`
68+
**Separator values**: `"pipe"`, `"slash"`, `"dot"`, `"arrow"`
69+
6270
### Configure Claude Code Settings
6371

6472
Ensure `~/.claude/settings.json` has the statusLine configuration:
@@ -73,9 +81,9 @@ Ensure `~/.claude/settings.json` has the statusLine configuration:
7381

7482
### Show Preview
7583

76-
After setup, show a preview of the statusline output by running:
84+
After setup, show a preview by running:
7785
```bash
78-
echo '{"workspace":{"current_dir":"'$(pwd)'"},"model":{"id":"claude-opus-4-5-20251101"},"version":"2.0.76","context_window":{"total_input_tokens":43000,"context_window_size":200000}}' | ~/.claude/statusline-command.sh
86+
echo '{"workspace":{"current_dir":"'$(pwd)'"},"model":{"id":"claude-opus-4-5-20251101"},"version":"2.0.76","context_window":{"total_input_tokens":43000,"context_window_size":200000,"current_usage":{"input_tokens":35000,"cache_creation_input_tokens":5000,"cache_read_input_tokens":3000}},"rate_limits":{"five_hour":{"used_percentage":45},"seven_day":{"used_percentage":28}}}' | ~/.claude/statusline-command.sh
7987
```
8088

8189
### Confirm Setup
@@ -85,40 +93,20 @@ Output:
8593
✓ Statusline configured successfully!
8694
8795
Your settings:
88-
Format: [N]-line layout
96+
Layout: 2-line
8997
• Showing: Context, Rate limits, Git branch, Tools
90-
• Colors: Colorful
98+
• Context style: With tokens
99+
• Separator: Pipe (│)
91100
92101
Preview:
93102
[show the actual statusline output]
94103
95104
The statusline will update automatically during your session.
96-
Use /statusline:config to change settings anytime.
97-
```
98-
99-
## Example Interview Flow
100-
101-
```
102-
Q1: How many lines should the statusline display?
103-
→ User selects: 2 lines
104-
105-
Q2: What information do you want to see?
106-
→ User selects: Context usage, Rate limits, Git branch
107-
108-
Q3: What color style do you prefer?
109-
→ User selects: Colorful
110-
111-
✓ Generating your statusline...
112-
✓ Config saved to ~/.claude/statusline.config.json
113-
✓ Script updated at ~/.claude/statusline-command.sh
114-
115-
Preview:
116-
claude-plugins (master) │ Opus 4 5 │ v2.0.76
117-
Context: 21% (43,000 tokens) │ 5h: 14% 7d: 46%
105+
Use /statusline:config to change layout anytime.
118106
```
119107

120108
## Related Commands
121109

122110
- `/statusline:status` — View current metrics
123-
- `/statusline:config` — Quick config change (just line format)
111+
- `/statusline:config` — Quick layout change
124112
- `/statusline:disable` — Disable statusline

0 commit comments

Comments
 (0)