cc-context-stats 1.3.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 (72) hide show
  1. package/.claude/commands/context-stats.md +17 -0
  2. package/.claude/settings.local.json +85 -0
  3. package/.editorconfig +60 -0
  4. package/.eslintrc.json +35 -0
  5. package/.github/dependabot.yml +44 -0
  6. package/.github/workflows/ci.yml +255 -0
  7. package/.github/workflows/release.yml +149 -0
  8. package/.pre-commit-config.yaml +74 -0
  9. package/.prettierrc +33 -0
  10. package/.shellcheckrc +10 -0
  11. package/CHANGELOG.md +100 -0
  12. package/CONTRIBUTING.md +240 -0
  13. package/PUBLISHING_GUIDE.md +69 -0
  14. package/README.md +179 -0
  15. package/config/settings-example.json +7 -0
  16. package/config/settings-node.json +7 -0
  17. package/config/settings-python.json +7 -0
  18. package/docs/configuration.md +83 -0
  19. package/docs/context-stats.md +132 -0
  20. package/docs/installation.md +195 -0
  21. package/docs/scripts.md +116 -0
  22. package/docs/troubleshooting.md +189 -0
  23. package/images/claude-statusline-token-graph.gif +0 -0
  24. package/images/claude-statusline.png +0 -0
  25. package/images/context-status-dumbzone.png +0 -0
  26. package/images/context-status.png +0 -0
  27. package/images/statusline-detail.png +0 -0
  28. package/images/token-graph.jpeg +0 -0
  29. package/images/token-graph.png +0 -0
  30. package/install +344 -0
  31. package/install.sh +272 -0
  32. package/jest.config.js +11 -0
  33. package/npm-publish.sh +33 -0
  34. package/package.json +36 -0
  35. package/publish.sh +24 -0
  36. package/pyproject.toml +113 -0
  37. package/requirements-dev.txt +12 -0
  38. package/scripts/context-stats.sh +970 -0
  39. package/scripts/statusline-full.sh +241 -0
  40. package/scripts/statusline-git.sh +32 -0
  41. package/scripts/statusline-minimal.sh +11 -0
  42. package/scripts/statusline.js +350 -0
  43. package/scripts/statusline.py +312 -0
  44. package/show_raw_claude_code_api.js +11 -0
  45. package/src/claude_statusline/__init__.py +11 -0
  46. package/src/claude_statusline/__main__.py +6 -0
  47. package/src/claude_statusline/cli/__init__.py +1 -0
  48. package/src/claude_statusline/cli/context_stats.py +379 -0
  49. package/src/claude_statusline/cli/statusline.py +172 -0
  50. package/src/claude_statusline/core/__init__.py +1 -0
  51. package/src/claude_statusline/core/colors.py +55 -0
  52. package/src/claude_statusline/core/config.py +98 -0
  53. package/src/claude_statusline/core/git.py +67 -0
  54. package/src/claude_statusline/core/state.py +266 -0
  55. package/src/claude_statusline/formatters/__init__.py +1 -0
  56. package/src/claude_statusline/formatters/time.py +50 -0
  57. package/src/claude_statusline/formatters/tokens.py +70 -0
  58. package/src/claude_statusline/graphs/__init__.py +1 -0
  59. package/src/claude_statusline/graphs/renderer.py +346 -0
  60. package/src/claude_statusline/graphs/statistics.py +58 -0
  61. package/tests/bash/test_install.bats +29 -0
  62. package/tests/bash/test_statusline_full.bats +109 -0
  63. package/tests/bash/test_statusline_git.bats +42 -0
  64. package/tests/bash/test_statusline_minimal.bats +37 -0
  65. package/tests/fixtures/json/high_usage.json +17 -0
  66. package/tests/fixtures/json/low_usage.json +17 -0
  67. package/tests/fixtures/json/medium_usage.json +17 -0
  68. package/tests/fixtures/json/valid_full.json +30 -0
  69. package/tests/fixtures/json/valid_minimal.json +9 -0
  70. package/tests/node/statusline.test.js +199 -0
  71. package/tests/python/conftest.py +84 -0
  72. package/tests/python/test_statusline.py +154 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "statusLine": {
3
+ "type": "command",
4
+ "command": "~/.claude/statusline.sh",
5
+ "padding": 0
6
+ }
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "statusLine": {
3
+ "type": "command",
4
+ "command": "~/.claude/statusline.js",
5
+ "padding": 0
6
+ }
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "statusLine": {
3
+ "type": "command",
4
+ "command": "~/.claude/statusline.py",
5
+ "padding": 0
6
+ }
7
+ }
@@ -0,0 +1,83 @@
1
+ # Configuration
2
+
3
+ The configuration file `~/.claude/statusline.conf` is automatically created with default settings on first run.
4
+
5
+ Windows location: `%USERPROFILE%\.claude\statusline.conf`
6
+
7
+ ## Settings
8
+
9
+ ```bash
10
+ # Autocompact setting - sync with Claude Code's /config
11
+ autocompact=true # (default) Show reserved buffer for compacting
12
+ autocompact=false # When autocompact is disabled via /config
13
+
14
+ # Token display format
15
+ token_detail=true # (default) Show exact token count: 64,000 free
16
+ token_detail=false # Show abbreviated tokens: 64.0k free
17
+
18
+ # Show token delta since last refresh
19
+ show_delta=true # (default) Show delta like [+2,500]
20
+ show_delta=false # Disable delta display
21
+
22
+ # Show session_id in status line
23
+ show_session=true # (default) Show session ID
24
+ show_session=false # Hide session ID
25
+ ```
26
+
27
+ ## Status Line Components
28
+
29
+ ```
30
+ [Opus 4.5] my-project | main [3] | 64,000 free (32.0%) [+2,500] [AC:45k] session_id
31
+ ```
32
+
33
+ | Component | Description | Color |
34
+ | ------------- | ------------------------ | ---------------- |
35
+ | `[Opus 4.5]` | Current AI model | Dim |
36
+ | `my-project` | Current directory | Blue |
37
+ | `main` | Git branch | Magenta |
38
+ | `[3]` | Uncommitted changes | Cyan |
39
+ | `64,000 free` | Available tokens | Green/Yellow/Red |
40
+ | `(32.0%)` | Context usage percentage | - |
41
+ | `[+2,500]` | Token delta | - |
42
+ | `[AC:45k]` | Autocompact buffer | Dim |
43
+ | `session_id` | Current session | Dim |
44
+
45
+ ## Token Colors
46
+
47
+ Context availability is color-coded:
48
+
49
+ | Availability | Color |
50
+ | ------------ | ------ |
51
+ | > 50% | Green |
52
+ | > 25% | Yellow |
53
+ | <= 25% | Red |
54
+
55
+ ## Autocompact Display
56
+
57
+ - `[AC:45k]` - Autocompact enabled, 45k tokens reserved
58
+ - `[AC:off]` - Autocompact disabled
59
+
60
+ ## Token Display Formats
61
+
62
+ | Setting | Display |
63
+ | -------------------- | -------------------------------- |
64
+ | `token_detail=true` | `64,000 free (32.0%)` `[+2,500]` |
65
+ | `token_detail=false` | `64.0k free (32.0%)` `[+2.5k]` |
66
+
67
+ ## Token Delta
68
+
69
+ The `[+X,XXX]` indicator shows tokens consumed since last refresh:
70
+
71
+ - Only positive deltas are shown
72
+ - First run shows no delta (no baseline yet)
73
+ - Each session has its own state file to avoid conflicts
74
+
75
+ ## Session ID
76
+
77
+ The session ID at the end helps:
78
+
79
+ - Identify sessions when running multiple Claude Code instances
80
+ - Correlate logs with specific sessions
81
+ - Debug session-specific issues
82
+
83
+ Double-click to select and copy. Set `show_session=false` to hide.
@@ -0,0 +1,132 @@
1
+ # Context Stats
2
+
3
+ Real-time context monitoring for Claude Code sessions. Know when you're in the Smart Zone, Dumb Zone, or Wrap Up Zone.
4
+
5
+ ## Context Zones
6
+
7
+ Context Stats tracks your context usage and warns you as performance degrades:
8
+
9
+ | Zone | Context Used | Status | Message |
10
+ | ------------------- | ------------ | -------- | ----------------------------------------------- |
11
+ | 🟢 **Smart Zone** | < 40% | Optimal | "You are in the smart zone" |
12
+ | 🟡 **Dumb Zone** | 40-80% | Degraded | "You are in the dumb zone - Dex Horthy says so" |
13
+ | 🔴 **Wrap Up Zone** | > 80% | Critical | "Better to wrap up and start a new session" |
14
+
15
+ ## Usage
16
+
17
+ By default, `context-stats` runs in live monitoring mode:
18
+
19
+ ```bash
20
+ # Live monitoring (default, refreshes every 2s)
21
+ context-stats
22
+
23
+ # Custom refresh interval
24
+ context-stats -w 5
25
+
26
+ # Show once and exit
27
+ context-stats --no-watch
28
+
29
+ # Show specific session
30
+ context-stats <session_id>
31
+ ```
32
+
33
+ ### Graph Types
34
+
35
+ ```bash
36
+ context-stats --type delta # Context growth per interaction (default)
37
+ context-stats --type cumulative # Total context usage over time
38
+ context-stats --type both # Show both graphs
39
+ context-stats --type io # Input/output token breakdown
40
+ context-stats --type all # Show all graphs
41
+ ```
42
+
43
+ ## Output
44
+
45
+ ```
46
+ Context Stats (my-project • abc123def)
47
+
48
+ Context Growth Per Interaction
49
+ Max: 4,787 Min: 0 Points: 254
50
+
51
+ 4,787 │ ●
52
+ │ ● ▒
53
+ │ ●● ● ▒ ░
54
+ │ ● ░ ░
55
+ 2,052 │ ░ ● ● ● ░ ░ ●
56
+ │ ░ ▒ ● ● ● ● ● ● ●░ ░ ▒ ●●
57
+ │●●●●●●●●●●●●●●●●●●●●●●●●●●● ●●●●●●●●●●●●●●●●●●●●●●
58
+ 0 │●●●●●░▒●●●●▒▒●●▒░●●░▒▒▒▒▒●●●▒●▒●●▒●▒░●●▒●░●●▒●▒▒●▒
59
+ └─────────────────────────────────────────────────
60
+ 10:40 11:29 12:01
61
+
62
+ Session Summary
63
+ ----------------------------------------------------------------------------
64
+ >>> DUMB ZONE <<< (You are in the dumb zone - Dex Horthy says so)
65
+
66
+ Context Remaining: 43,038 (21%)
67
+ Input Tokens: 59,015
68
+ Output Tokens: 43,429
69
+ Session Duration: 2h 29m
70
+
71
+ Powered by claude-statusline v1.2.0 - https://github.com/luongnv89/cc-context-stats
72
+ ```
73
+
74
+ ## Features
75
+
76
+ - **Live Monitoring**: Automatic refresh every 2 seconds (configurable)
77
+ - **Zone Awareness**: Color-coded status based on context usage
78
+ - **Project Display**: Shows project name and session ID
79
+ - **ASCII Graphs**: Smooth area charts with gradient fills
80
+ - **Minimal Output**: Clean summary with just the essential info
81
+
82
+ ## Graph Symbols
83
+
84
+ | Symbol | Meaning |
85
+ | ------ | ----------------------- |
86
+ | `●` | Trend line |
87
+ | `▒` | Medium fill (near line) |
88
+ | `░` | Light fill (area below) |
89
+ | `│` | Y-axis |
90
+ | `└─` | X-axis |
91
+
92
+ ## Watch Mode
93
+
94
+ By default, context-stats runs in watch mode. Press `Ctrl+C` to exit.
95
+
96
+ Features:
97
+
98
+ - **Flicker-free updates**: Uses cursor repositioning for smooth redraws
99
+ - **Live timestamp**: Shows refresh indicator in header
100
+ - **Hidden cursor**: Clean display without cursor blinking
101
+ - **Auto-adapt**: Responds to terminal size changes
102
+
103
+ To disable watch mode and show graphs once:
104
+
105
+ ```bash
106
+ context-stats --no-watch
107
+ ```
108
+
109
+ ## Data Source
110
+
111
+ Reads from `~/.claude/statusline/statusline.<session_id>.state` files, automatically created by the status line script.
112
+
113
+ ## CLI Reference
114
+
115
+ ```
116
+ context-stats [session_id] [options]
117
+
118
+ ARGUMENTS:
119
+ session_id Optional session ID. If not provided, uses the latest session.
120
+
121
+ OPTIONS:
122
+ --type <type> Graph type to display:
123
+ - delta: Context growth per interaction (default)
124
+ - cumulative: Total context usage over time
125
+ - io: Input/output tokens over time
126
+ - both: Show cumulative and delta graphs
127
+ - all: Show all graphs including I/O
128
+ -w [interval] Set refresh interval in seconds (default: 2)
129
+ --no-watch Show graphs once and exit (disable live monitoring)
130
+ --no-color Disable color output
131
+ --help Show help message
132
+ ```
@@ -0,0 +1,195 @@
1
+ # Installation Guide
2
+
3
+ ## Quick Install
4
+
5
+ ### One-Line Install (Recommended)
6
+
7
+ ```bash
8
+ curl -fsSL https://raw.githubusercontent.com/luongnv89/claude-statusline/main/install.sh | bash
9
+ ```
10
+
11
+ This downloads and runs the installer directly from GitHub. In non-interactive mode, it installs the **full** statusline script by default.
12
+
13
+ ### Interactive Install
14
+
15
+ To choose a different script variant:
16
+
17
+ ```bash
18
+ bash <(curl -fsSL https://raw.githubusercontent.com/luongnv89/claude-statusline/main/install.sh)
19
+ ```
20
+
21
+ This runs the installer interactively, allowing you to select from:
22
+
23
+ 1. minimal - Simple: model + directory
24
+ 2. git - With git branch info
25
+ 3. full - Full featured with context usage (recommended)
26
+ 4. python - Python version (full featured)
27
+ 5. node - Node.js version (full featured)
28
+
29
+ ### Install from Source
30
+
31
+ ```bash
32
+ git clone https://github.com/luongnv89/cc-context-stats.git
33
+ cd claude-statusline
34
+ ./install.sh
35
+ ```
36
+
37
+ The installer will:
38
+
39
+ 1. Install the statusline script to `~/.claude/`
40
+ 2. Install `context-stats` CLI tool to `~/.local/bin/`
41
+ 3. Create default configuration at `~/.claude/statusline.conf`
42
+ 4. Update `~/.claude/settings.json`
43
+
44
+ ### Windows
45
+
46
+ Use the Python or Node.js version (no `jq` required):
47
+
48
+ ```powershell
49
+ git clone https://github.com/luongnv89/cc-context-stats.git
50
+ copy claude-statusline\scripts\statusline.py %USERPROFILE%\.claude\statusline.py
51
+ ```
52
+
53
+ Or with Node.js:
54
+
55
+ ```powershell
56
+ copy claude-statusline\scripts\statusline.js %USERPROFILE%\.claude\statusline.js
57
+ ```
58
+
59
+ ## Manual Installation
60
+
61
+ ### macOS / Linux
62
+
63
+ ```bash
64
+ cp scripts/statusline-full.sh ~/.claude/statusline.sh
65
+ chmod +x ~/.claude/statusline.sh
66
+ ```
67
+
68
+ ### Context Stats CLI (Optional)
69
+
70
+ ```bash
71
+ cp scripts/context-stats.sh ~/.local/bin/context-stats
72
+ chmod +x ~/.local/bin/context-stats
73
+ ```
74
+
75
+ Ensure `~/.local/bin` is in your PATH:
76
+
77
+ ```bash
78
+ # For zsh
79
+ echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
80
+ source ~/.zshrc
81
+
82
+ # For bash
83
+ echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
84
+ source ~/.bashrc
85
+ ```
86
+
87
+ ## Configure Claude Code
88
+
89
+ Add to your Claude Code settings:
90
+
91
+ **File location:**
92
+
93
+ - macOS/Linux: `~/.claude/settings.json`
94
+ - Windows: `%USERPROFILE%\.claude\settings.json`
95
+
96
+ ### Bash (macOS/Linux)
97
+
98
+ ```json
99
+ {
100
+ "statusLine": {
101
+ "type": "command",
102
+ "command": "~/.claude/statusline.sh"
103
+ }
104
+ }
105
+ ```
106
+
107
+ ### Python (All Platforms)
108
+
109
+ ```json
110
+ {
111
+ "statusLine": {
112
+ "type": "command",
113
+ "command": "python ~/.claude/statusline.py"
114
+ }
115
+ }
116
+ ```
117
+
118
+ Windows:
119
+
120
+ ```json
121
+ {
122
+ "statusLine": {
123
+ "type": "command",
124
+ "command": "python %USERPROFILE%\\.claude\\statusline.py"
125
+ }
126
+ }
127
+ ```
128
+
129
+ ### Node.js (All Platforms)
130
+
131
+ ```json
132
+ {
133
+ "statusLine": {
134
+ "type": "command",
135
+ "command": "node ~/.claude/statusline.js"
136
+ }
137
+ }
138
+ ```
139
+
140
+ Windows:
141
+
142
+ ```json
143
+ {
144
+ "statusLine": {
145
+ "type": "command",
146
+ "command": "node %USERPROFILE%\\.claude\\statusline.js"
147
+ }
148
+ }
149
+ ```
150
+
151
+ ## Requirements
152
+
153
+ ### macOS
154
+
155
+ ```bash
156
+ brew install jq
157
+ ```
158
+
159
+ ### Linux (Debian/Ubuntu)
160
+
161
+ ```bash
162
+ sudo apt install jq
163
+ ```
164
+
165
+ ### Linux (Fedora/RHEL)
166
+
167
+ ```bash
168
+ sudo dnf install jq
169
+ ```
170
+
171
+ ### Windows
172
+
173
+ No additional requirements for Python/Node.js scripts.
174
+
175
+ For bash scripts via WSL:
176
+
177
+ ```bash
178
+ sudo apt install jq
179
+ ```
180
+
181
+ ## Verify Installation
182
+
183
+ Test your statusline script:
184
+
185
+ ```bash
186
+ # macOS/Linux
187
+ echo '{"model":{"display_name":"Test"}}' | ~/.claude/statusline.sh
188
+
189
+ # Windows (Python)
190
+ echo {"model":{"display_name":"Test"}} | python %USERPROFILE%\.claude\statusline.py
191
+ ```
192
+
193
+ You should see output like: `[Test] directory`
194
+
195
+ Restart Claude Code to see the status line.
@@ -0,0 +1,116 @@
1
+ # Available Scripts
2
+
3
+ ## Overview
4
+
5
+ | Script | Platform | Requirements | Features |
6
+ | ----------------------- | ------------ | ------------ | --------------------------------- |
7
+ | `statusline-full.sh` | macOS, Linux | `jq` | Full-featured with all indicators |
8
+ | `statusline-git.sh` | macOS, Linux | `jq` | Git branch and changes |
9
+ | `statusline-minimal.sh` | macOS, Linux | `jq` | Model + directory only |
10
+ | `statusline.py` | All | Python 3 | Cross-platform, full-featured |
11
+ | `statusline.js` | All | Node.js | Cross-platform, full-featured |
12
+ | `context-stats.sh` | macOS, Linux | None | Token usage visualization |
13
+
14
+ ## Bash Scripts
15
+
16
+ ### statusline-full.sh (Recommended)
17
+
18
+ Complete status line with all features:
19
+
20
+ - Model name
21
+ - Current directory
22
+ - Git branch and changes
23
+ - Token usage with color coding
24
+ - Token delta tracking
25
+ - Autocompact indicator
26
+ - Session ID
27
+
28
+ ### statusline-git.sh
29
+
30
+ Lighter version with git info:
31
+
32
+ - Model name
33
+ - Current directory
34
+ - Git branch and changes
35
+
36
+ ### statusline-minimal.sh
37
+
38
+ Minimal footprint:
39
+
40
+ - Model name
41
+ - Current directory
42
+
43
+ ## Cross-Platform Scripts
44
+
45
+ ### statusline.py
46
+
47
+ Python implementation matching `statusline-full.sh` functionality. Works on Windows, macOS, and Linux without additional dependencies beyond Python 3.
48
+
49
+ ### statusline.js
50
+
51
+ Node.js implementation matching `statusline-full.sh` functionality. Works on all platforms with Node.js installed.
52
+
53
+ ## Utility Scripts
54
+
55
+ ### context-stats.sh
56
+
57
+ Standalone CLI tool for visualizing token consumption. See [Context Stats](context-stats.md) for details.
58
+
59
+ ## Output Format
60
+
61
+ All statusline scripts produce consistent output:
62
+
63
+ ```
64
+ [Model] directory | branch [changes] | XXk free (XX%) [+delta] [AC:XXk] session_id
65
+ ```
66
+
67
+ ## Architecture
68
+
69
+ ```mermaid
70
+ graph LR
71
+ A[Claude Code] -->|JSON stdin| B[Statusline Script]
72
+ B -->|Parse| C[Model Info]
73
+ B -->|Parse| D[Context Info]
74
+ B -->|Check| E[Git Status]
75
+ B -->|Read| F[Config File]
76
+ B -->|Write| G[State File]
77
+ C --> H[Format Output]
78
+ D --> H
79
+ E --> H
80
+ F --> H
81
+ H -->|stdout| A
82
+ ```
83
+
84
+ ## Input Format
85
+
86
+ Scripts receive JSON via stdin from Claude Code:
87
+
88
+ ```json
89
+ {
90
+ "model": {
91
+ "display_name": "Opus 4.5"
92
+ },
93
+ "cwd": "/path/to/project",
94
+ "session_id": "abc123",
95
+ "context": {
96
+ "tokens_remaining": 64000,
97
+ "context_window": 200000,
98
+ "autocompact_buffer_tokens": 45000
99
+ }
100
+ }
101
+ ```
102
+
103
+ ## Color Codes
104
+
105
+ All scripts use consistent ANSI colors:
106
+
107
+ | Color | Code | Usage |
108
+ | ------- | ------------ | -------------------------- |
109
+ | Blue | `\033[0;34m` | Directory |
110
+ | Magenta | `\033[0;35m` | Git branch |
111
+ | Cyan | `\033[0;36m` | Changes count |
112
+ | Green | `\033[0;32m` | High availability (>50%) |
113
+ | Yellow | `\033[0;33m` | Medium availability (>25%) |
114
+ | Red | `\033[0;31m` | Low availability (<=25%) |
115
+ | Dim | `\033[2m` | Model, AC indicator |
116
+ | Reset | `\033[0m` | Reset formatting |