@amadeus19/cc-statusline 3.2.1 → 3.2.3
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.
- package/README.md +854 -0
- package/bin/.gitkeep +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,854 @@
|
|
|
1
|
+
# Claude Code Statusline Pro
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/@amadeus19/cc-statusline)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://nodejs.org/)
|
|
6
|
+
[](https://github.com/amadeus19/cc-statusline)
|
|
7
|
+
|
|
8
|
+
[中文](#使用指南) | [English](#user-guide)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 使用指南
|
|
13
|
+
|
|
14
|
+
**Claude Code Statusline Pro** - 为Claude Code量身定制的智能状态栏系统。
|
|
15
|
+
|
|
16
|
+
### ✨ 核心特性
|
|
17
|
+
|
|
18
|
+
- 🎯 **三大主题系统**: Classic、Powerline、Capsule 主题,自适应终端能力
|
|
19
|
+
- 🛠️ **灵活的配置系统**: 支持TOML配置文件和命令行参数覆盖
|
|
20
|
+
- 📊 **精准Token计算**: 与Claude官方API完全一致的token统计,支持渐变可视化进度条
|
|
21
|
+
- 🧠 **智能状态识别**: 基于tokens数量精准识别Thinking vs Ready状态
|
|
22
|
+
- 🚀 **预设系统**: 通过字母组合快速配置组件排布 (`PMBTUS`, `MT`, `BT`)
|
|
23
|
+
- 🌈 **跨平台兼容**: Windows、macOS、Linux智能适配,支持各种终端
|
|
24
|
+
- 🧩 **多行小组件系统**: 支持网格布局、静态/ API 数据源、检测与过滤器,自由扩展状态栏
|
|
25
|
+
- ⚡ **高性能优化**: 缓存机制,300ms更新间隔,符合Claude Code官方建议
|
|
26
|
+
- 🌐 **双语支持**: 中英双语配置界面和错误提示
|
|
27
|
+
- 🦀 **Rust 引擎**: 提供原生 Rust 内核,更快更稳
|
|
28
|
+
|
|
29
|
+
### 🦀 Rust 重写优化亮点
|
|
30
|
+
|
|
31
|
+
- 原生 `git2` 仓库分析:直接获取分支、状态、stash 等信息,避免频繁 Shell 调用,在大型仓库中依然流畅
|
|
32
|
+
- 多层缓存体系:组件级内存缓存结合会话持久化存储,减少重复解析配置与历史数据的 IO
|
|
33
|
+
- Tokio 异步运行时:多线程调度渲染与文件操作,维持官方推荐的 300ms 更新节奏并提升稳定性
|
|
34
|
+
- 增量 Transcript 解析:按偏移量增量读取 `.jsonl`,并通过原子写入持久化快照,避免大型日志反复全量扫描
|
|
35
|
+
- 配置与扩展缓存:合并配置结果可复用并附带差异报告,多行组件缓存上次 Widget 内容以降低 I/O 和网络抖动
|
|
36
|
+
|
|
37
|
+
### 📋 系统要求
|
|
38
|
+
|
|
39
|
+
在开始使用之前,请确保您的系统满足以下要求:
|
|
40
|
+
|
|
41
|
+
#### 必需条件
|
|
42
|
+
|
|
43
|
+
- **Claude Code**: 版本 ≥ 1.0.71
|
|
44
|
+
- **Node.js**: 版本 ≥ 18.0.0 ([下载安装](https://nodejs.org/))
|
|
45
|
+
- **npm**: 通常随Node.js自动安装
|
|
46
|
+
|
|
47
|
+
#### 检查当前版本
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# 检查Claude Code版本
|
|
51
|
+
claude --version
|
|
52
|
+
|
|
53
|
+
# 检查Node.js版本
|
|
54
|
+
node --version
|
|
55
|
+
|
|
56
|
+
# 检查npm版本
|
|
57
|
+
npm --version
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 🚀 快速开始
|
|
61
|
+
|
|
62
|
+
#### 一步配置,即刻使用
|
|
63
|
+
|
|
64
|
+
只需要在Claude Code的配置文件中添加一行配置,无需预先安装:
|
|
65
|
+
|
|
66
|
+
**在项目根目录或 $USER 目录创建 `.claude/settings.json`:**
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"statusLine": {
|
|
71
|
+
"type": "command",
|
|
72
|
+
"command": "npx @amadeus19/cc-statusline@latest"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
> 💡 **兼容说明**:旧命令 `npx @amadeus19/cc-statusline@latest` 仍会继续工作并自动调用新包,但将显示迁移提示。建议尽快将现有配置更新为 `npx @amadeus19/cc-statusline@latest` 以保持一致。
|
|
78
|
+
|
|
79
|
+
保存文件后,重新打开Claude Code即可看到专业版状态栏!
|
|
80
|
+
|
|
81
|
+
#### 验证安装
|
|
82
|
+
|
|
83
|
+
打开Claude Code,你应该看到类似这样的状态栏:
|
|
84
|
+
|
|
85
|
+
```text
|
|
86
|
+
📁 my-project | 🤖 S4 | 🌿 main | 📊 [████████████░░░] 80.1%(160k/200k) | $21.07 | ✅ Ready
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 🎯 快速配置指南
|
|
90
|
+
|
|
91
|
+
#### 预设系统 - 字母组合配置
|
|
92
|
+
|
|
93
|
+
通过简单的字母组合快速定制状态栏显示内容:
|
|
94
|
+
|
|
95
|
+
- **P** = Project (项目名称)
|
|
96
|
+
- **M** = Model (模型信息)
|
|
97
|
+
- **B** = Branch (Git分支)
|
|
98
|
+
- **T** = Tokens (Token使用情况)
|
|
99
|
+
- **U** = Usage (使用量统计)
|
|
100
|
+
- **S** = Status (状态信息)
|
|
101
|
+
|
|
102
|
+
#### 快速配置命令
|
|
103
|
+
|
|
104
|
+
注:这些命令全部是写在settings.json中的,并不是在终端直接执行使用(直接执行会打印出预览结果)
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# 显示所有组件(推荐)
|
|
108
|
+
npx @amadeus19/cc-statusline@latest --preset PMBTUS --theme powerline
|
|
109
|
+
|
|
110
|
+
# 只显示模型、Token和使用量
|
|
111
|
+
npx @amadeus19/cc-statusline@latest --preset MTU --theme classic
|
|
112
|
+
|
|
113
|
+
# 只显示分支和Token信息
|
|
114
|
+
npx @amadeus19/cc-statusline@latest --preset BT --theme capsule
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### 🧩 多行小组件系统
|
|
118
|
+
|
|
119
|
+
多行系统可以把状态栏扩展为网格布局,嵌入多个可独立刷新的小组件。
|
|
120
|
+
|
|
121
|
+
- **网格布局**:使用 `row`(从1开始)和 `col`(从0开始)控制每个小组件的位置,支持跨行/列排布。
|
|
122
|
+
- **小组件类型**:内置 `static`(静态文本)与 `api`(HTTP 请求)两种类型,API 小组件支持模板渲染、环境变量替换。
|
|
123
|
+
- **自动检测**:通过 `detection` 段读取环境变量,可配置 `equals` / `contains` / `pattern` 触发条件,也可以配合 `force` 手动开启或关闭。
|
|
124
|
+
- **结果过滤**:`filter` 支持 JSONPath + `equals` / `contains` / `pattern` 匹配,只在命中关键字时刷新;可用于最近请求等场景。
|
|
125
|
+
- **模板示例**:项目内提供 `configs/components/usage.template.toml` 与 `rust/configs/components/usage.template.toml`,复制到 `~/.claude/statusline-pro/components/usage.toml` 后按需改写。
|
|
126
|
+
|
|
127
|
+
#### 快速启用
|
|
128
|
+
|
|
129
|
+
在 `config.toml` 中开启多行模式并指定要加载的组件文件:
|
|
130
|
+
|
|
131
|
+
```toml
|
|
132
|
+
[multiline]
|
|
133
|
+
enabled = true
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
执行 `npx @amadeus19/cc-statusline@latest config init -w` 可以一次性生成主配置并复制所有小组件模板。
|
|
137
|
+
|
|
138
|
+
### 🎨 三大主题系统
|
|
139
|
+
|
|
140
|
+
#### Classic 主题 - 最大兼容性
|
|
141
|
+
|
|
142
|
+
Classic主题支持三种图标模式,默认会根据终端能力自动选择:
|
|
143
|
+
|
|
144
|
+
##### 🎯 Nerd Font 模式(推荐)
|
|
145
|
+
|
|
146
|
+

|
|
147
|
+
|
|
148
|
+
**需要安装Nerd Font字体,并在对应的终端中选择使用字体**,推荐使用 [Hack Nerd Font](https://github.com/ryanoasis/nerd-fonts/releases/download/v3.2.3/Hack.zip)
|
|
149
|
+
|
|
150
|
+
##### 😊 Emoji 模式
|
|
151
|
+
|
|
152
|
+

|
|
153
|
+
|
|
154
|
+
适合支持Emoji但没有Nerd Font的终端
|
|
155
|
+
|
|
156
|
+
##### 📝 文本模式
|
|
157
|
+
|
|
158
|
+

|
|
159
|
+
|
|
160
|
+
最大兼容性,适合所有终端环境
|
|
161
|
+
|
|
162
|
+
#### Powerline主题 - 现代化设计(需要Nerd Font字体)
|
|
163
|
+
|
|
164
|
+

|
|
165
|
+
|
|
166
|
+
箭头无缝连接设计,需要Nerd Font支持,提供最佳视觉体验。
|
|
167
|
+
|
|
168
|
+
#### Capsule主题 - 胶囊样式(需要Nerd Font字体)
|
|
169
|
+
|
|
170
|
+

|
|
171
|
+
|
|
172
|
+
胶囊形状包装,现代化UI设计,适合追求简洁美观的用户。
|
|
173
|
+
|
|
174
|
+
#### 强制启用特定模式
|
|
175
|
+
|
|
176
|
+
如果你的终端本就支持某种图标(例如Nerd Font),但没有自动启用,则可强制指定启用该图标能力
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
# 强制启用Nerd Font图标(需要安装字体,否则会显示乱码)
|
|
180
|
+
npx @amadeus19/cc-statusline@latest --force-nerd-font
|
|
181
|
+
|
|
182
|
+
# 强制启用Emoji图标(需要终端确实支持Emoji,如MacOS,否则会显示乱码)
|
|
183
|
+
npx @amadeus19/cc-statusline@latest --force-emoji
|
|
184
|
+
|
|
185
|
+
# 强制启用纯文本模式
|
|
186
|
+
npx @amadeus19/cc-statusline@latest --force-text
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### 📊 Token计算准确性
|
|
190
|
+
|
|
191
|
+
#### 与Claude官方API完全一致
|
|
192
|
+
|
|
193
|
+
状态栏的token计算与Claude官方API保持完全一致,确保显示数据的准确性:
|
|
194
|
+
|
|
195
|
+

|
|
196
|
+
|
|
197
|
+
**如图所示**:
|
|
198
|
+
|
|
199
|
+
- 状态栏显示:`183.3k/200k (91.7%)`
|
|
200
|
+
- Claude API报错:`183559 + 21333 > 200000`
|
|
201
|
+
- 计算结果:`183559 ≈ 183.3k` ✅ 完全一致
|
|
202
|
+
|
|
203
|
+
#### Token计算公式
|
|
204
|
+
|
|
205
|
+
```javascript
|
|
206
|
+
contextUsedTokens = usage.input_tokens +
|
|
207
|
+
usage.cache_creation_input_tokens +
|
|
208
|
+
usage.cache_read_input_tokens +
|
|
209
|
+
usage.output_tokens;
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
这确保了状态栏显示的token使用量与Claude官方统计完全一致。
|
|
213
|
+
|
|
214
|
+
### 💰 Cost计算说明
|
|
215
|
+
|
|
216
|
+
#### 智能成本追踪系统
|
|
217
|
+
|
|
218
|
+
状态栏提供两种成本计算模式,可在 `config.toml` 中配置:
|
|
219
|
+
|
|
220
|
+
##### 🔄 Session 模式(会话模式)
|
|
221
|
+
|
|
222
|
+
- **计算范围**: 从您打开 Claude Code 开始,到使用 `/clear` 命令或关闭应用为止
|
|
223
|
+
- **计算逻辑**: 基于当前会话的所有 token 消耗
|
|
224
|
+
- **适用场景**: 单次工作会话的成本控制
|
|
225
|
+
- **重置方式**: 使用 `/clear` 命令或重启 Claude Code
|
|
226
|
+
|
|
227
|
+
##### 🔗 Conversation 模式(对话模式)
|
|
228
|
+
|
|
229
|
+
- **计算范围**: 追踪完整对话链的累计消耗
|
|
230
|
+
- **智能追踪**: 即使关闭并重新打开 Claude Code,仍能追踪同一项目的历史消耗
|
|
231
|
+
- **Session 无关**: 自动在本地缓存以记录每次中断/恢复/压缩的 token 变化,保持连续性追踪
|
|
232
|
+
- **适用场景**: 长对话(可能含多次压缩)的完整成本分析
|
|
233
|
+
|
|
234
|
+
##### ⚙️ 配置方式
|
|
235
|
+
|
|
236
|
+
在 `config.toml` 中设置:
|
|
237
|
+
|
|
238
|
+
```toml
|
|
239
|
+
[components.usage]
|
|
240
|
+
mode = "conversation" # 或 "session"
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
##### 📊 成本计算公式
|
|
244
|
+
|
|
245
|
+
```javascript
|
|
246
|
+
cost = (inputTokens * inputPrice + outputTokens * outputPrice +
|
|
247
|
+
cacheTokens * cachePrice) / 200_000
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
**注意**: 状态栏的成本计算与 `/cost` 命令采用不同逻辑和时间范围,确保各自场景的准确性。
|
|
251
|
+
|
|
252
|
+
### 🛠️ 高级配置
|
|
253
|
+
|
|
254
|
+
#### 智能配置管理系统
|
|
255
|
+
|
|
256
|
+
##### 📂 配置文件层级
|
|
257
|
+
|
|
258
|
+
状态栏采用两级配置系统,支持灵活的配置管理:
|
|
259
|
+
|
|
260
|
+
**项目级配置** (优先级: 高)
|
|
261
|
+
|
|
262
|
+
- 路径: `~/.claude/projects/{project-hash}/statusline-pro/config.toml`
|
|
263
|
+
- 适用: 特定项目的个性化配置
|
|
264
|
+
- 初始化: `npx @amadeus19/cc-statusline@latest config init`
|
|
265
|
+
- 初始化并复制组件模板: `npx @amadeus19/cc-statusline@latest config init -w`
|
|
266
|
+
|
|
267
|
+
**用户级配置** (优先级: 低)
|
|
268
|
+
|
|
269
|
+
- 路径: `~/.claude/statusline-pro/config.toml`
|
|
270
|
+
- 适用: 全局默认配置,适用于所有项目
|
|
271
|
+
- 初始化: `npx @amadeus19/cc-statusline@latest config init -g`
|
|
272
|
+
- 初始化并复制组件模板: `npx @amadeus19/cc-statusline@latest config init -w -g`
|
|
273
|
+
|
|
274
|
+
##### ⚡ 智能终端检测和配置初始化
|
|
275
|
+
|
|
276
|
+
运行初始化命令时,系统会自动检测您的终端能力:
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
# 初始化项目级配置(推荐)
|
|
280
|
+
npx @amadeus19/cc-statusline@latest config init
|
|
281
|
+
|
|
282
|
+
# 初始化项目级配置并复制组件模板
|
|
283
|
+
npx @amadeus19/cc-statusline@latest config init -w
|
|
284
|
+
|
|
285
|
+
# 初始化全局配置
|
|
286
|
+
npx @amadeus19/cc-statusline@latest config init -g
|
|
287
|
+
|
|
288
|
+
# 强制重新初始化(覆盖现有配置)
|
|
289
|
+
npx @amadeus19/cc-statusline@latest config init --force
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
> 提示:`-w` 等同于 `--with-components`,会把组件多行模板一并复制到配置目录,方便直接在本地调整。
|
|
293
|
+
|
|
294
|
+
**智能检测功能:**
|
|
295
|
+
|
|
296
|
+
- 🎨 **Nerd Font 检测**: 自动识别终端是否支持 Nerd Font 图标
|
|
297
|
+
- 😊 **Emoji 支持检测**: 检测终端的 Emoji 渲染能力
|
|
298
|
+
- 🌈 **颜色支持检测**: 识别终端的颜色显示能力
|
|
299
|
+
- 🎯 **主题自动选择**: 根据终端能力自动选择最佳主题
|
|
300
|
+
|
|
301
|
+
##### 📝 配置文件详解
|
|
302
|
+
|
|
303
|
+
系统初始化后会生成完整的 `config.toml` 配置文件:
|
|
304
|
+
|
|
305
|
+
```toml
|
|
306
|
+
# 默认预设和主题
|
|
307
|
+
preset = "PMBTUS"
|
|
308
|
+
theme = "powerline"
|
|
309
|
+
|
|
310
|
+
# 主题特性配置
|
|
311
|
+
[themes.powerline]
|
|
312
|
+
enable_gradient = true
|
|
313
|
+
ignore_separator = true
|
|
314
|
+
fine_progress = true
|
|
315
|
+
|
|
316
|
+
# 组件顺序配置
|
|
317
|
+
[components]
|
|
318
|
+
order = ["project", "model", "branch", "tokens", "usage", "status"]
|
|
319
|
+
|
|
320
|
+
# Token组件详细配置
|
|
321
|
+
[components.tokens]
|
|
322
|
+
show_gradient = true # 启用彩色渐变进度条
|
|
323
|
+
show_progress_bar = true # 显示进度条
|
|
324
|
+
show_percentage = true # 显示百分比
|
|
325
|
+
progress_width = 15 # 进度条宽度
|
|
326
|
+
|
|
327
|
+
# Token阈值配置
|
|
328
|
+
[components.tokens.thresholds]
|
|
329
|
+
warning = 60 # 60%显示黄色警告
|
|
330
|
+
danger = 85 # 85%显示红色危险
|
|
331
|
+
backup = 85 # 后备区域开始
|
|
332
|
+
critical = 95 # 95%显示🔥临界
|
|
333
|
+
|
|
334
|
+
# 终端兼容配置
|
|
335
|
+
[terminal]
|
|
336
|
+
force_nerd_font = false # 强制启用Nerd Font
|
|
337
|
+
force_emoji = false # 强制启用Emoji
|
|
338
|
+
force_text = false # 强制文本模式
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### 🖥️ 终端兼容性
|
|
342
|
+
|
|
343
|
+
智能检测并自动适配不同终端环境:
|
|
344
|
+
|
|
345
|
+
- **Windows Terminal** ✅ 完全支持所有特性
|
|
346
|
+
- **VS Code Terminal** ✅ 完全支持所有特性
|
|
347
|
+
- **iTerm2 (macOS)** ✅ 完全支持所有特性
|
|
348
|
+
- **Git Bash** ✅ 完全支持所有特性
|
|
349
|
+
- **PowerShell** ✅ 完全支持所有特性
|
|
350
|
+
- **CMD** ⚠️ 自动回退到安全文本模式
|
|
351
|
+
|
|
352
|
+
### 🔧 故障排除
|
|
353
|
+
|
|
354
|
+
#### 版本兼容性问题
|
|
355
|
+
|
|
356
|
+
##### **Q: 状态栏完全不显示或显示错误**
|
|
357
|
+
|
|
358
|
+
```bash
|
|
359
|
+
# 错误示例:status line command failed: npx @amadeus19/cc-statusline@latest
|
|
360
|
+
# 解决方案:升级Claude Code到最新版本
|
|
361
|
+
npm install -g @anthropic-ai/claude-code@latest
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
##### **Q: 提示"command not found: npx"或Node.js相关错误**
|
|
365
|
+
|
|
366
|
+
```bash
|
|
367
|
+
# 错误示例:/bin/sh: npx: command not found
|
|
368
|
+
# 解决方案:安装或更新Node.js环境
|
|
369
|
+
# 访问官网下载最新版本:https://nodejs.org/
|
|
370
|
+
# 或使用包管理器安装:
|
|
371
|
+
|
|
372
|
+
# macOS (使用Homebrew)
|
|
373
|
+
brew install node
|
|
374
|
+
|
|
375
|
+
# Ubuntu/Debian
|
|
376
|
+
sudo apt update && sudo apt install nodejs npm
|
|
377
|
+
|
|
378
|
+
# Windows
|
|
379
|
+
# 请访问 https://nodejs.org/ 下载安装包
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
##### **Q: Claude Code版本过旧导致的兼容性问题**
|
|
383
|
+
|
|
384
|
+
```bash
|
|
385
|
+
# 检查Claude Code版本
|
|
386
|
+
claude --version
|
|
387
|
+
|
|
388
|
+
# 如果版本低于1.0.71,请更新
|
|
389
|
+
npm install -g @anthropic-ai/claude-code@latest
|
|
390
|
+
|
|
391
|
+
# 更新后重启终端并重新打开Claude Code
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
##### **Q: Linux 上提示 `libssl.so.3` 找不到**
|
|
395
|
+
|
|
396
|
+
自 v3.0.2 起,Linux x64/ARM64 平台包改为 **musl** 静态链接构建,不再依赖系统自带的 OpenSSL;请执行以下步骤:
|
|
397
|
+
|
|
398
|
+
1. 确认使用最新版本:`npx @amadeus19/cc-statusline@latest --version`
|
|
399
|
+
2. 若仍提示旧二进制,可清理 npm 缓存后重试:
|
|
400
|
+
```bash
|
|
401
|
+
npm cache clean --force
|
|
402
|
+
npx @amadeus19/cc-statusline@latest --version
|
|
403
|
+
```
|
|
404
|
+
3. 仍需手动安装依赖的老版本用户,可按发行说明安装 `libssl3` 或升级系统,但建议尽快迁移到 3.0.2+。
|
|
405
|
+
|
|
406
|
+
#### 显示问题
|
|
407
|
+
|
|
408
|
+
##### **Q: 图标显示为方框或乱码**
|
|
409
|
+
|
|
410
|
+
```bash
|
|
411
|
+
# 检查终端是否支持Nerd Font,强制使用Emoji模式
|
|
412
|
+
npx @amadeus19/cc-statusline@latest --force-emoji
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
##### **Q: 颜色显示异常**
|
|
416
|
+
|
|
417
|
+
```bash
|
|
418
|
+
# 检查终端颜色支持,可以禁用颜色
|
|
419
|
+
npx @amadeus19/cc-statusline@latest --no-color
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
##### **Q: 状态栏不更新**
|
|
423
|
+
|
|
424
|
+
```bash
|
|
425
|
+
# 检查Claude Code配置文件是否正确
|
|
426
|
+
cat ~/.claude/settings.json
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
#### 测试命令
|
|
430
|
+
|
|
431
|
+
```bash
|
|
432
|
+
# 测试基本功能
|
|
433
|
+
echo '{"model":{"id":"claude-sonnet-4"}}' | npx @amadeus19/cc-statusline@latest
|
|
434
|
+
|
|
435
|
+
# 测试特定预设和主题
|
|
436
|
+
echo '{"model":{"id":"claude-sonnet-4"}}' | npx @amadeus19/cc-statusline@latest --preset MT --theme classic
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
---
|
|
440
|
+
|
|
441
|
+
## User Guide
|
|
442
|
+
|
|
443
|
+
**Claude Code Professional Status Bar** - Smart status bar system specifically designed for Claude Code.
|
|
444
|
+
|
|
445
|
+
### ✨ Core Features
|
|
446
|
+
|
|
447
|
+
- 🎯 **Three Theme System**: Classic, Powerline, and Capsule themes with adaptive terminal capabilities
|
|
448
|
+
- 🛠️ **Flexible Configuration System**: Support for TOML configuration files and command-line parameter overrides
|
|
449
|
+
- 📊 **Precise Token Calculation**: Token statistics fully consistent with Claude's official API, supporting gradient visualization progress bar
|
|
450
|
+
- 🧠 **Smart Status Recognition**: Precise identification of Thinking vs Ready status based on token count
|
|
451
|
+
- 🚀 **Preset System**: Quick component configuration through letter combinations (`PMBTUS`, `MT`, `BT`)
|
|
452
|
+
- 🌈 **Cross-platform Compatibility**: Smart adaptation for Windows, macOS, Linux, supporting various terminals
|
|
453
|
+
- 🧩 **Multiline Widget System**: Grid-based widgets with static/API sources, auto-detection, and JSONPath filters
|
|
454
|
+
- ⚡ **High Performance Optimization**: Caching mechanism, 300ms update interval, following Claude Code official recommendations
|
|
455
|
+
- 🌐 **Bilingual Support**: Chinese and English configuration interface with error messages
|
|
456
|
+
- 🦀 **Rust Engine**: Native Rust core for faster, more stable statusline updates
|
|
457
|
+
|
|
458
|
+
### 🦀 Rust Rewrite Highlights
|
|
459
|
+
|
|
460
|
+
- Native `git2` repository analysis: reads branch status, stash counts, and operations without spawning shells, keeping large repos responsive
|
|
461
|
+
- Layered caching system: in-memory component caches plus persisted session storage to avoid redundant config/history IO
|
|
462
|
+
- Tokio-powered async runtime: multi-threaded scheduling separates rendering from file work, maintaining the 300ms refresh cadence with higher stability
|
|
463
|
+
- Incremental transcript parsing: seeks to the last processed offset and persists snapshots atomically so large `.jsonl` logs no longer stall refreshes
|
|
464
|
+
- Cached config and widgets: merged configurations are reused with diff reports, while multiline widgets memoize their last render to smooth IO and API calls
|
|
465
|
+
|
|
466
|
+
### 📋 System Requirements
|
|
467
|
+
|
|
468
|
+
Before getting started, please ensure your system meets the following requirements:
|
|
469
|
+
|
|
470
|
+
#### Prerequisites
|
|
471
|
+
|
|
472
|
+
- **Claude Code**: Version ≥ 1.0.71
|
|
473
|
+
- **Node.js**: Version ≥ 18.0.0 ([Download](https://nodejs.org/))
|
|
474
|
+
- **npm**: Usually installed automatically with Node.js
|
|
475
|
+
|
|
476
|
+
#### Check Current Versions
|
|
477
|
+
|
|
478
|
+
```bash
|
|
479
|
+
# Check Claude Code version
|
|
480
|
+
claude --version
|
|
481
|
+
|
|
482
|
+
# Check Node.js version
|
|
483
|
+
node --version
|
|
484
|
+
|
|
485
|
+
# Check npm version
|
|
486
|
+
npm --version
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
### 🚀 Quick Start
|
|
490
|
+
|
|
491
|
+
#### One-Step Configuration, Instant Use
|
|
492
|
+
|
|
493
|
+
Simply add one line to your Claude Code configuration file, no pre-installation required:
|
|
494
|
+
|
|
495
|
+
**Create `.claude/settings.json` in your project root or home directory:**
|
|
496
|
+
|
|
497
|
+
```json
|
|
498
|
+
{
|
|
499
|
+
"statusLine": {
|
|
500
|
+
"type": "command",
|
|
501
|
+
"command": "npx @amadeus19/cc-statusline@latest"
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
> 💡 **Compatibility Note**: The legacy command `npx @amadeus19/cc-statusline@latest` still works and forwards to the new package, but will emit a migration warning. Updating existing configs to `npx @amadeus19/cc-statusline@latest` keeps future upgrades smooth.
|
|
507
|
+
|
|
508
|
+
Save the file and restart Claude Code to see the professional status bar!
|
|
509
|
+
|
|
510
|
+
#### Verify Installation
|
|
511
|
+
|
|
512
|
+
Open Claude Code and you should see a status bar like this:
|
|
513
|
+
|
|
514
|
+
```text
|
|
515
|
+
📁 my-project | 🤖 S4 | 🌿 main | 📊 [████████████░░░] 80.1%(160k/200k) | $21.07 | ✅ Ready
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
### 🎯 Quick Configuration Guide
|
|
519
|
+
|
|
520
|
+
#### Preset System - Letter Combination Configuration
|
|
521
|
+
|
|
522
|
+
Quickly customize status bar content through simple letter combinations:
|
|
523
|
+
|
|
524
|
+
- **P** = Project (project name)
|
|
525
|
+
- **M** = Model (model information)
|
|
526
|
+
- **B** = Branch (Git branch)
|
|
527
|
+
- **T** = Tokens (token usage)
|
|
528
|
+
- **U** = Usage (usage statistics)
|
|
529
|
+
- **S** = Status (status information)
|
|
530
|
+
|
|
531
|
+
#### Quick Configuration Commands
|
|
532
|
+
|
|
533
|
+
Note: These commands are all written in settings.json, not executed directly in the terminal (direct execution will print preview results)
|
|
534
|
+
|
|
535
|
+
```bash
|
|
536
|
+
# Show all components (recommended)
|
|
537
|
+
npx @amadeus19/cc-statusline@latest --preset PMBTUS --theme powerline
|
|
538
|
+
|
|
539
|
+
# Show only model, tokens, and usage
|
|
540
|
+
npx @amadeus19/cc-statusline@latest --preset MTU --theme classic
|
|
541
|
+
|
|
542
|
+
# Show only branch and token information
|
|
543
|
+
npx @amadeus19/cc-statusline@latest --preset BT --theme capsule
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
### 🧩 Multiline Widget System
|
|
547
|
+
|
|
548
|
+
The multiline engine turns the status bar into a grid of independently refreshing widgets.
|
|
549
|
+
|
|
550
|
+
- **Grid layout**: Use `row` (1-based) and `col` (0-based) to place each widget and build multi-row layouts.
|
|
551
|
+
- **Widget types**: Built-in `static` (text) and `api` (HTTP request) widgets with template rendering and environment variable substitution.
|
|
552
|
+
- **Auto detection**: `detection` blocks read environment variables and support `equals` / `contains` / `pattern`, with optional `force` overrides.
|
|
553
|
+
- **Result filters**: `filter` combines JSONPath with `equals` / `contains` / `pattern` so widgets refresh only when keywords match—perfect for last-request panels.
|
|
554
|
+
- **Starter templates**: Copy `configs/components/usage.template.toml` or `rust/configs/components/usage.template.toml` to `~/.claude/statusline-pro/components/usage.toml` and customize.
|
|
555
|
+
|
|
556
|
+
#### Quick Enable
|
|
557
|
+
|
|
558
|
+
Enable multiline mode in `config.toml` and point to your widget file:
|
|
559
|
+
|
|
560
|
+
```toml
|
|
561
|
+
[multiline]
|
|
562
|
+
enabled = true
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
Run `npx @amadeus19/cc-statusline@latest config init -w` to generate the main config and copy all widget templates in one step.
|
|
566
|
+
|
|
567
|
+
### 🎨 Three Theme System
|
|
568
|
+
|
|
569
|
+
#### Classic Theme - Maximum Compatibility
|
|
570
|
+
|
|
571
|
+
Classic theme supports three icon modes, automatically selected based on terminal capabilities by default:
|
|
572
|
+
|
|
573
|
+
##### 🎯 Nerd Font Mode (Recommended)
|
|
574
|
+
|
|
575
|
+

|
|
576
|
+
|
|
577
|
+
**Requires Nerd Font installation and selecting the font in the corresponding terminal**, recommend [Hack Nerd Font](https://github.com/ryanoasis/nerd-fonts/releases/download/v3.2.3/Hack.zip)
|
|
578
|
+
|
|
579
|
+
##### 😊 Emoji Mode
|
|
580
|
+
|
|
581
|
+

|
|
582
|
+
|
|
583
|
+
Suitable for terminals that support Emoji but don't have Nerd Font
|
|
584
|
+
|
|
585
|
+
##### 📝 Text Mode
|
|
586
|
+
|
|
587
|
+

|
|
588
|
+
|
|
589
|
+
Maximum compatibility, suitable for all terminal environments
|
|
590
|
+
|
|
591
|
+
#### Powerline Theme - Modern Design (Requires Nerd Font)
|
|
592
|
+
|
|
593
|
+

|
|
594
|
+
|
|
595
|
+
Seamless arrow connection design, requires Nerd Font support, provides the best visual experience.
|
|
596
|
+
|
|
597
|
+
#### Capsule Theme - Capsule Style (Requires Nerd Font)
|
|
598
|
+
|
|
599
|
+

|
|
600
|
+
|
|
601
|
+
Capsule-shaped wrapper, modern UI design, suitable for users pursuing simplicity and beauty.
|
|
602
|
+
|
|
603
|
+
#### Force Enable Specific Mode
|
|
604
|
+
|
|
605
|
+
If your terminal already supports certain icons (e.g., Nerd Font) but doesn't auto-enable, you can force enable that icon capability
|
|
606
|
+
|
|
607
|
+
```bash
|
|
608
|
+
# Force enable Nerd Font icons (requires font installation, otherwise will show garbled text)
|
|
609
|
+
npx @amadeus19/cc-statusline@latest --force-nerd-font
|
|
610
|
+
|
|
611
|
+
# Force enable Emoji icons (terminal must actually support Emoji like macOS, otherwise will show garbled text)
|
|
612
|
+
npx @amadeus19/cc-statusline@latest --force-emoji
|
|
613
|
+
|
|
614
|
+
# Force enable plain text mode
|
|
615
|
+
npx @amadeus19/cc-statusline@latest --force-text
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
### 📊 Token Calculation Accuracy
|
|
619
|
+
|
|
620
|
+
#### Fully Consistent with Claude Official API
|
|
621
|
+
|
|
622
|
+
The status bar's token calculation remains fully consistent with Claude's official API, ensuring accurate data display:
|
|
623
|
+
|
|
624
|
+

|
|
625
|
+
|
|
626
|
+
**As shown in the image**:
|
|
627
|
+
|
|
628
|
+
- Status bar display: `183.3k/200k (91.7%)`
|
|
629
|
+
- Claude API error: `183559 + 21333 > 200000`
|
|
630
|
+
- Calculation result: `183559 ≈ 183.3k` ✅ Completely consistent
|
|
631
|
+
|
|
632
|
+
#### Token Calculation Formula
|
|
633
|
+
|
|
634
|
+
```javascript
|
|
635
|
+
contextUsedTokens = usage.input_tokens +
|
|
636
|
+
usage.cache_creation_input_tokens +
|
|
637
|
+
usage.cache_read_input_tokens +
|
|
638
|
+
usage.output_tokens;
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
This ensures that the token usage displayed in the status bar is completely consistent with Claude's official statistics.
|
|
642
|
+
|
|
643
|
+
### 💰 Cost Calculation Explanation
|
|
644
|
+
|
|
645
|
+
#### Intelligent Cost Tracking System
|
|
646
|
+
|
|
647
|
+
The status bar provides two cost calculation modes, configurable in `config.toml`:
|
|
648
|
+
|
|
649
|
+
##### 🔄 Session Mode
|
|
650
|
+
|
|
651
|
+
- **Calculation scope**: From when you open Claude Code until using `/clear` command or closing the application
|
|
652
|
+
- **Calculation logic**: Based on all token consumption in the current session
|
|
653
|
+
- **Use case**: Cost control for single work sessions
|
|
654
|
+
- **Reset method**: Use `/clear` command or restart Claude Code
|
|
655
|
+
|
|
656
|
+
##### 🔗 Conversation Mode
|
|
657
|
+
|
|
658
|
+
- **Scope**: Tracks cumulative usage across the entire conversation chain
|
|
659
|
+
- **Smart Tracking**: Continues following the same project’s history even after closing and reopening Claude Code
|
|
660
|
+
- **Session-Agnostic**: Persists local snapshots of token changes for every pause/resume/compression to maintain continuity
|
|
661
|
+
- **Best For**: Long-running conversations (often with multiple compressions) that need full cost analysis
|
|
662
|
+
|
|
663
|
+
##### ⚙️ Configuration Method
|
|
664
|
+
|
|
665
|
+
Set in `config.toml`:
|
|
666
|
+
|
|
667
|
+
```toml
|
|
668
|
+
[components.usage]
|
|
669
|
+
mode = "conversation" # or "session"
|
|
670
|
+
```
|
|
671
|
+
|
|
672
|
+
##### 📊 Cost Calculation Formula
|
|
673
|
+
|
|
674
|
+
```javascript
|
|
675
|
+
cost = (inputTokens * inputPrice + outputTokens * outputPrice +
|
|
676
|
+
cacheTokens * cachePrice) / 200_000
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
**Note**: The status bar's cost calculation uses different logic and time ranges from the `/cost` command, ensuring accuracy for their respective scenarios.
|
|
680
|
+
|
|
681
|
+
### 🛠️ Advanced Configuration
|
|
682
|
+
|
|
683
|
+
#### Intelligent Configuration Management System
|
|
684
|
+
|
|
685
|
+
##### 📂 Configuration File Hierarchy
|
|
686
|
+
|
|
687
|
+
The status bar uses a two-level configuration system for flexible configuration management:
|
|
688
|
+
|
|
689
|
+
**Project-level Configuration** (Priority: High)
|
|
690
|
+
|
|
691
|
+
- Path: `~/.claude/projects/{project-hash}/statusline-pro/config.toml`
|
|
692
|
+
- Application: Personalized configuration for specific projects
|
|
693
|
+
- Initialization: `npx @amadeus19/cc-statusline@latest config init`
|
|
694
|
+
- Initialization with component templates: `npx @amadeus19/cc-statusline@latest config init -w`
|
|
695
|
+
|
|
696
|
+
**User-level Configuration** (Priority: Low)
|
|
697
|
+
|
|
698
|
+
- Path: `~/.claude/statusline-pro/config.toml`
|
|
699
|
+
- Application: Global default configuration for all projects
|
|
700
|
+
- Initialization: `npx @amadeus19/cc-statusline@latest config init -g`
|
|
701
|
+
- Initialization with component templates: `npx @amadeus19/cc-statusline@latest config init -w -g`
|
|
702
|
+
|
|
703
|
+
#### ⚡ Smart Terminal Detection and Configuration Initialization
|
|
704
|
+
|
|
705
|
+
When running initialization commands, the system automatically detects your terminal capabilities:
|
|
706
|
+
|
|
707
|
+
```bash
|
|
708
|
+
# Initialize project-level configuration (recommended)
|
|
709
|
+
npx @amadeus19/cc-statusline@latest config init
|
|
710
|
+
|
|
711
|
+
# Initialize project-level configuration and copy component templates
|
|
712
|
+
npx @amadeus19/cc-statusline@latest config init -w
|
|
713
|
+
|
|
714
|
+
# Initialize global configuration
|
|
715
|
+
npx @amadeus19/cc-statusline@latest config init -g
|
|
716
|
+
|
|
717
|
+
# Force re-initialization (overwrite existing configuration)
|
|
718
|
+
npx @amadeus19/cc-statusline@latest config init --force
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
> Tip: `-w` is the short form of `--with-components`; it copies the bundled multiline widget templates into your config folder so you can customize them locally.
|
|
722
|
+
|
|
723
|
+
**Smart Detection Features:**
|
|
724
|
+
|
|
725
|
+
- 🎨 **Nerd Font Detection**: Automatically identifies if terminal supports Nerd Font icons
|
|
726
|
+
- 😊 **Emoji Support Detection**: Detects terminal's emoji rendering capability
|
|
727
|
+
- 🌈 **Color Support Detection**: Identifies terminal's color display capability
|
|
728
|
+
- 🎯 **Automatic Theme Selection**: Automatically selects the best theme based on terminal capabilities
|
|
729
|
+
|
|
730
|
+
#### 📝 Configuration File Details
|
|
731
|
+
|
|
732
|
+
After system initialization, a complete `config.toml` configuration file will be generated:
|
|
733
|
+
|
|
734
|
+
```toml
|
|
735
|
+
# Default preset and theme
|
|
736
|
+
preset = "PMBTUS"
|
|
737
|
+
theme = "powerline"
|
|
738
|
+
|
|
739
|
+
# Theme feature configuration
|
|
740
|
+
[themes.powerline]
|
|
741
|
+
enable_gradient = true
|
|
742
|
+
ignore_separator = true
|
|
743
|
+
fine_progress = true
|
|
744
|
+
|
|
745
|
+
# Component order configuration
|
|
746
|
+
[components]
|
|
747
|
+
order = ["project", "model", "branch", "tokens", "usage", "status"]
|
|
748
|
+
|
|
749
|
+
# Token component detailed configuration
|
|
750
|
+
[components.tokens]
|
|
751
|
+
show_gradient = true # Enable colored gradient progress bar
|
|
752
|
+
show_progress_bar = true # Show progress bar
|
|
753
|
+
show_percentage = true # Show percentage
|
|
754
|
+
progress_width = 15 # Progress bar width
|
|
755
|
+
|
|
756
|
+
# Token threshold configuration
|
|
757
|
+
[components.tokens.thresholds]
|
|
758
|
+
warning = 60 # 60% shows yellow warning
|
|
759
|
+
danger = 85 # 85% shows red danger
|
|
760
|
+
backup = 85 # Backup area starts
|
|
761
|
+
critical = 95 # 95% shows 🔥 critical
|
|
762
|
+
|
|
763
|
+
# Terminal compatibility configuration
|
|
764
|
+
[terminal]
|
|
765
|
+
force_nerd_font = false # Force enable Nerd Font
|
|
766
|
+
force_emoji = false # Force enable Emoji
|
|
767
|
+
force_text = false # Force text mode
|
|
768
|
+
```
|
|
769
|
+
|
|
770
|
+
### 🖥️ Terminal Compatibility
|
|
771
|
+
|
|
772
|
+
Smart detection and automatic adaptation for different terminal environments:
|
|
773
|
+
|
|
774
|
+
- **Windows Terminal** ✅ Full support for all features
|
|
775
|
+
- **VS Code Terminal** ✅ Full support for all features
|
|
776
|
+
- **iTerm2 (macOS)** ✅ Full support for all features
|
|
777
|
+
- **Git Bash** ✅ Full support for all features
|
|
778
|
+
- **PowerShell** ✅ Full support for all features
|
|
779
|
+
- **CMD** ⚠️ Automatic fallback to safe text mode
|
|
780
|
+
|
|
781
|
+
### 🔧 Troubleshooting
|
|
782
|
+
|
|
783
|
+
### Version Compatibility Issues
|
|
784
|
+
|
|
785
|
+
#### **Q: Status bar not displaying or showing errors**
|
|
786
|
+
|
|
787
|
+
```bash
|
|
788
|
+
# Error example: status line command failed: npx @amadeus19/cc-statusline@latest
|
|
789
|
+
# Solution: Upgrade Claude Code to the latest version
|
|
790
|
+
npm install -g @anthropic-ai/claude-code@latest
|
|
791
|
+
```
|
|
792
|
+
|
|
793
|
+
#### **Q: "command not found: npx" or Node.js related errors**
|
|
794
|
+
|
|
795
|
+
```bash
|
|
796
|
+
# Error example: /bin/sh: npx: command not found
|
|
797
|
+
# Solution: Install or update Node.js environment
|
|
798
|
+
# Visit official website for latest version: https://nodejs.org/
|
|
799
|
+
# Or use package managers:
|
|
800
|
+
|
|
801
|
+
# macOS (using Homebrew)
|
|
802
|
+
brew install node
|
|
803
|
+
|
|
804
|
+
# Ubuntu/Debian
|
|
805
|
+
sudo apt update && sudo apt install nodejs npm
|
|
806
|
+
|
|
807
|
+
# Windows
|
|
808
|
+
# Please visit https://nodejs.org/ to download installer
|
|
809
|
+
```
|
|
810
|
+
|
|
811
|
+
#### **Q: Compatibility issues due to outdated Claude Code version**
|
|
812
|
+
|
|
813
|
+
```bash
|
|
814
|
+
# Check Claude Code version
|
|
815
|
+
claude --version
|
|
816
|
+
|
|
817
|
+
# If version is below 1.0.71, please update
|
|
818
|
+
npm install -g @anthropic-ai/claude-code@latest
|
|
819
|
+
|
|
820
|
+
# Restart terminal and reopen Claude Code after update
|
|
821
|
+
```
|
|
822
|
+
|
|
823
|
+
### Display Issues
|
|
824
|
+
|
|
825
|
+
#### **Q: Icons display as squares or garbled text**
|
|
826
|
+
|
|
827
|
+
```bash
|
|
828
|
+
# Check if terminal supports Nerd Font, force use Emoji mode
|
|
829
|
+
npx @amadeus19/cc-statusline@latest --force-emoji
|
|
830
|
+
```
|
|
831
|
+
|
|
832
|
+
#### **Q: Color display issues**
|
|
833
|
+
|
|
834
|
+
```bash
|
|
835
|
+
# Check terminal color support, can disable colors
|
|
836
|
+
npx @amadeus19/cc-statusline@latest --no-color
|
|
837
|
+
```
|
|
838
|
+
|
|
839
|
+
#### **Q: Status bar not updating**
|
|
840
|
+
|
|
841
|
+
```bash
|
|
842
|
+
# Check if Claude Code configuration file is correct
|
|
843
|
+
cat ~/.claude/settings.json
|
|
844
|
+
```
|
|
845
|
+
|
|
846
|
+
### Test Commands
|
|
847
|
+
|
|
848
|
+
```bash
|
|
849
|
+
# Test basic functionality
|
|
850
|
+
echo '{"model":{"id":"claude-sonnet-4"}}' | npx @amadeus19/cc-statusline@latest
|
|
851
|
+
|
|
852
|
+
# Test specific preset and theme
|
|
853
|
+
echo '{"model":{"id":"claude-sonnet-4"}}' | npx @amadeus19/cc-statusline@latest --preset MT --theme classic
|
|
854
|
+
```
|
package/bin/.gitkeep
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
|