Skip to content

Commit 51704ed

Browse files
duyetduyetbot
andcommitted
feat(statusline): fix context display and add configurable formats
- Fix context showing 0% when data available (fallback to total_input_tokens) - Hide empty values (Tools: None, Agents: None, Tasks: No tasks) - Add configurable 1/2/3 line formats via ~/.claude/statusline.config.json - Cache API usage data for 60s to avoid repeated API calls - Format tokens as "111k" instead of "111,223" - Use lowercase "ctx:" instead of "Context:" - Format model as "opus-4.5" instead of "Opus 4 5" - Rename /statusline:enable to /statusline:setup (interactive wizard) - Add test suite at scripts/test-statusline.sh - Add CLAUDE.md with dev notes and testing commands 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: duyetbot <duyetbot@users.noreply.github.com>
1 parent 9d94d54 commit 51704ed

9 files changed

Lines changed: 480 additions & 161 deletions

File tree

statusline/.claude-plugin/plugin.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "statusline",
3-
"version": "1.2.0",
4-
"description": "Real-time visibility into Claude Code sessions showing context usage, active tools, and task progress in compact one-line format",
3+
"version": "1.4.0",
4+
"description": "Configurable status bar showing context usage, API rate limits (5h/7d), git branch, and active tools. Supports 1/2/3 line layouts with smart hiding of empty values.",
55
"author": {
66
"name": "duyet"
77
}

statusline/CLAUDE.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Statusline Plugin Development Notes
2+
3+
> **IMPORTANT**: Keep this file updated when modifying the statusline script or commands!
4+
5+
## Architecture
6+
7+
The statusline has two components:
8+
1. **Plugin commands** (`commands/*.md`) - Claude Code plugin commands
9+
2. **Shell script** (`~/.claude/statusline-command.sh`) - The actual renderer called by Claude Code
10+
11+
The shell script is configured in `~/.claude/settings.json`:
12+
```json
13+
{
14+
"statusLine": {
15+
"type": "command",
16+
"command": "/Users/duet/.claude/statusline-command.sh"
17+
}
18+
}
19+
```
20+
21+
## Data Sources
22+
23+
The script gets data from two sources:
24+
25+
1. **Stdin (real-time)** - Claude Code pipes JSON on every render:
26+
- `context_window.total_input_tokens` - cumulative tokens
27+
- `context_window.current_usage.*` - current context usage
28+
- `model.id` - model name (e.g., "claude-opus-4-5-20251101")
29+
- `workspace.current_dir` - working directory
30+
- `version` - Claude Code version
31+
32+
2. **API fetch (cached)** - Fetches from Anthropic OAuth API:
33+
- 5-hour usage percentage
34+
- 7-day usage percentage
35+
- Reset timer
36+
- **Cached for 60 seconds** (configurable via `USAGE_CACHE_TTL`)
37+
38+
## Configuration
39+
40+
Config file: `~/.claude/statusline.config.json`
41+
42+
```json
43+
{
44+
"line_format": "1" | "2" | "3",
45+
"show_context": true,
46+
"show_rate_limits": true,
47+
"show_git_branch": true,
48+
"show_tools": true,
49+
"color_style": "colorful" | "minimal" | "plain"
50+
}
51+
```
52+
53+
## Testing
54+
55+
Run the test suite:
56+
```bash
57+
bash statusline/scripts/test-statusline.sh
58+
```
59+
60+
### Manual Testing
61+
62+
```bash
63+
# With full context data
64+
DEBUG_STATUSLINE=1 echo '{"workspace":{"current_dir":"/test"},"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
65+
66+
# Test null current_usage (should fallback to total_input_tokens)
67+
echo '{"context_window":{"total_input_tokens":43000,"context_window_size":200000,"current_usage":null}}' | ~/.claude/statusline-command.sh
68+
69+
# Test no context data (should hide context line)
70+
echo '{"context_window":{"total_input_tokens":0,"context_window_size":200000}}' | ~/.claude/statusline-command.sh
71+
72+
# Test line formats
73+
echo '{"line_format":"1"}' > ~/.claude/statusline.config.json
74+
echo '{"context_window":{"total_input_tokens":43000,"context_window_size":200000}}' | ~/.claude/statusline-command.sh
75+
76+
echo '{"line_format":"2"}' > ~/.claude/statusline.config.json
77+
echo '{"context_window":{"total_input_tokens":43000,"context_window_size":200000}}' | ~/.claude/statusline-command.sh
78+
79+
echo '{"line_format":"3"}' > ~/.claude/statusline.config.json
80+
echo '{"context_window":{"total_input_tokens":43000,"context_window_size":200000}}' | ~/.claude/statusline-command.sh
81+
```
82+
83+
## Environment Variables
84+
85+
- `DEBUG_STATUSLINE=1` - Show diagnostic output to stderr
86+
- `SKIP_RATE_LIMITS=1` - Skip API fetch (for testing)
87+
- `USAGE_CACHE_TTL=60` - Cache TTL in seconds (default: 60)
88+
89+
## Key Behaviors
90+
91+
1. **Context fallback**: If `current_usage` is null or all zeros, uses `total_input_tokens`
92+
2. **Hide empty values**: Doesn't show "Context: 0%", "Tools: None", "Agents: None", "Tasks: No tasks"
93+
3. **Line format**: Configurable 1/2/3 line display via config file
94+
4. **API caching**: Usage data cached for 60s to avoid repeated API calls
95+
5. **Model formatting**: "claude-opus-4-5-20251101" → "opus-4.5"
96+
97+
## Cache Files
98+
99+
- `~/.claude/statusline.config.json` - User configuration
100+
- `~/.claude/statusline-usage-cache.json` - Cached API usage data (auto-generated)
101+
102+
## Commands
103+
104+
- `/statusline:setup` - Interactive setup wizard
105+
- `/statusline:status` - Show current metrics
106+
- `/statusline:config` - Quick format change
107+
- `/statusline:disable` - Disable statusline
108+
109+
## Known Issues
110+
111+
- Rate limit API requires proper OAuth scope; may show "re-login needed" if token lacks permission
112+
- `current_usage` may be null on first message of session (falls back to total_input_tokens)
113+
- macOS uses `stat -f %m`, Linux uses `stat -c %Y` for cache age check

statusline/commands/config.md

Lines changed: 44 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,67 @@
11
# /statusline:config
22

3-
Configure the statusline plugin with your preferences through interactive questions.
3+
Configure the statusline display format.
44

5-
## Usage
5+
## Action Required
66

7-
```
8-
/statusline:config
9-
```
7+
When this command is invoked, you MUST use the AskUserQuestion tool to ask:
108

11-
## What It Does
9+
### Question: Line Format
1210

13-
This command walks you through a series of questions to configure how statusline displays information in your Claude Code session:
11+
Ask the user which display format they prefer:
1412

15-
- **Display Frequency** — How often to update metrics (1-60 seconds)
16-
- **Display Format** — Compact, standard, or detailed output
17-
- **Metrics to Show** — Choose which metrics are important to you
18-
- **Color Theme** — Terminal-aware theme selection
19-
- **Auto-Start** — Enable monitoring automatically on session start
13+
**Header**: "Lines"
14+
**Question**: "How many lines should the statusline display?"
2015

21-
## Configuration Questions
16+
**Options**:
17+
1. **1 line (Compact)**`dir (branch) │ Model │ Ctx% │ 5h/7d │ Tasks`
18+
2. **2 lines** — Line 1: location/model, Line 2: all metrics
19+
3. **3 lines (Default)** — Full layout with separate lines for location, metrics, and activity
2220

23-
The interactive setup includes:
21+
### Save Configuration
2422

25-
1. **Update Interval** — How frequently should statusline refresh?
26-
- Fast (1-3 seconds) for active monitoring
27-
- Standard (5-10 seconds) for balanced view
28-
- Slow (15-60 seconds) for minimal updates
23+
After the user answers, save their choice to `~/.claude/statusline.config.json`:
2924

30-
2. **Display Mode** — How should metrics be displayed?
31-
- **Compact** — Single line summary (default)
32-
- **Standard** — Multi-line detailed view
33-
- **Detailed** — Full breakdown with charts
25+
```json
26+
{
27+
"line_format": "1"
28+
}
29+
```
3430

35-
3. **Show Metrics** — Which information matters most?
36-
- Context health
37-
- Active tools
38-
- Running agents
39-
- Task progress
40-
- Session duration
31+
Use values: `"1"`, `"2"`, or `"3"`
4132

42-
4. **Color Theme** — Terminal color preference?
43-
- Auto (detects terminal)
44-
- Dark background
45-
- Light background
46-
- No colors (plain text)
33+
### Confirm
34+
35+
Output:
36+
```
37+
✓ Statusline configured: [N]-line format
38+
Config saved to ~/.claude/statusline.config.json
39+
```
4740

48-
5. **Auto-Start** — Enable monitoring on session start?
49-
- Enabled (recommended)
50-
- Disabled
41+
## Example Outputs
5142

52-
## Example Session
43+
**1-line format**:
44+
```
45+
claude-plugins (master) │ Opus 4 5 │ Ctx: 21% │ 5h: 14% 7d: 46%
46+
```
5347

48+
**2-line format**:
5449
```
55-
$ /statusline:config
56-
57-
⚙️ Statusline Configuration Wizard
58-
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
59-
60-
Q1: Update Interval?
61-
▶ Standard (5-10 seconds)
62-
○ Fast (1-3 seconds)
63-
○ Slow (15-60 seconds)
64-
65-
Q2: Display Mode?
66-
▶ Compact (single line)
67-
○ Standard (multi-line)
68-
○ Detailed (with charts)
69-
70-
Q3: Show metrics (select multiple)?
71-
☑ Context health
72-
☑ Active tools
73-
☑ Running agents
74-
☑ Task progress
75-
☑ Duration
76-
77-
Q4: Color theme?
78-
▶ Auto (auto-detect)
79-
○ Dark
80-
○ Light
81-
○ None
82-
83-
Q5: Auto-start monitoring?
84-
▶ Enabled
85-
○ Disabled
86-
87-
✓ Configuration saved!
88-
→ Statusline will update every 5 seconds in compact mode
89-
→ Monitoring enabled on session start
90-
→ Use /statusline:status to view metrics anytime
91-
→ Empty values automatically hidden (no "None", no empty lists)
50+
claude-plugins (master) │ Opus 4 5 │ v2.0.76
51+
Ctx: 21% │ 5h: 14% 7d: 46% │ Tasks: 2/5
9252
```
9353

94-
## Configuration File
54+
**3-line format** (default):
55+
```
56+
claude-plugins (master) │ Opus 4 5 │ v2.0.76
57+
Context: 21% (43,000 tokens) │ 5h: 14% 7d: 46%
58+
Tools: Sequential │ Tasks: 2/5
59+
```
9560

96-
Your settings are saved to `.statusline.config.json` in your project root. You can also manually edit this file if needed.
61+
**Note**: Empty values are automatically hidden (no "None", no "0%", no "No tasks").
9762

9863
## Related Commands
9964

100-
- `/statusline:status` — View current metrics immediately
101-
- `/statusline:enable [interval]` — Enable with custom interval
102-
- `/statusline:disable`Pause monitoring
65+
- `/statusline:status` — View current metrics
66+
- `/statusline:enable` — Enable monitoring
67+
- `/statusline:disable`Disable monitoring

statusline/commands/enable.md

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)