statusline-config
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseStatusLine Config
状态栏配置
Customize — segments, themes, and colors.
~/.claude/statusline-command.sh自定义 — 包括分段、主题和颜色。
~/.claude/statusline-command.shWhen NOT to Use
不适用场景
| Scenario | Use Instead |
|---|---|
| Setting statusline for the first time (no customization needed) | Built-in |
Editing | Manual edit — this skill manages |
| Debugging Claude Code startup issues | |
| 场景 | 替代方案 |
|---|---|
| 首次设置状态栏(无需自定义) | 内置 |
直接编辑 | 手动编辑 —— 本技能管理的是 |
| 调试Claude Code启动问题 | |
Segments
分段
| Segment | JSON Field | Default | Notes |
|---|---|---|---|
| Directory | | ON | Truncate deep paths: |
| Git branch | shell | ON | |
| Model | | ON | - |
| Context % | | ON | Green >40%, Yellow 20-40%, Red <=20% |
| Cost | | ON | Show when >= $0.005, |
| >200k alert | | ON | Show only when |
For full JSON schema, see json-schema.md.
| 分段名 | JSON 字段 | 默认状态 | 说明 |
|---|---|---|---|
| 目录 | | 开启 | 长路径自动截断: |
| Git 分支 | shell | 开启 | |
| 模型 | | 开启 | - |
| 上下文占比 | | 开启 | >40%显示绿色,20-40%显示黄色,<=20%显示红色 |
| 成本 | | 开启 | 金额>= $0.005时显示,格式为 |
| 超200k令牌提醒 | | 开启 | 仅为 |
完整JSON schema请查看json-schema.md。
Themes
主题
| Theme | Type | Default | Notes |
|---|---|---|---|
| ANSI 16 | ✅ | Safe fallback, works everywhere |
| TrueColor | — | Recommended — pastel, WCAG AA >=4.5:1 |
| TrueColor | — | Vibrant purple/pink accents |
| TrueColor | — | Arctic blue, muted tones |
| — | — | No colors ( |
Switch via:
export CLAUDE_STATUSLINE_THEME=catppuccin-mochaFor complete token→hex mappings, see themes.md.
| 主题名 | 类型 | 默认 | 说明 |
|---|---|---|---|
| ANSI 16 | ✅ | 兼容所有环境的安全兜底方案 |
| TrueColor | — | 推荐使用 —— 柔和配色,WCAG AA对比度>=4.5:1 |
| TrueColor | — | 高饱和度紫/粉强调色 |
| TrueColor | — | 北极蓝调,低饱和度配色 |
| — | — | 无颜色( |
切换命令:
export CLAUDE_STATUSLINE_THEME=catppuccin-mocha完整令牌到十六进制颜色的映射请查看themes.md。
Semantic Tokens
语义令牌
Scripts use semantic tokens instead of hardcoded colors:
| Token | Role | Example |
|---|---|---|
| Directory path | blue / sapphire |
| Git branch name | magenta / mauve |
| Model display name | cyan / teal |
| Context >= 41% | green |
| Context 21-40% | yellow |
| Context <= 20% | red |
| Cost display | muted text |
| >200k token warning | orange/peach + bold |
| Pipe separator | dim/overlay |
| Secondary info | subtext |
| General text | foreground |
| Reset all formatting | |
脚本使用语义令牌而非硬编码颜色:
| 令牌名 | 作用 | 示例配色 |
|---|---|---|
| 目录路径 | 蓝色 / 蓝宝石色 |
| Git分支名 | 品红色 / 淡紫色 |
| 模型显示名 | 青色 / 蓝绿色 |
| 上下文占比>=41% | 绿色 |
| 上下文占比21-40% | 黄色 |
| 上下文占比<=20% | 红色 |
| 成本显示 | 低对比度文字 |
| 超200k令牌警告 | 橙色/桃色 + 粗体 |
| 管道分隔符 | 低亮度/覆盖色 |
| 次要信息 | 辅助文字 |
| 通用文本 | 前景色 |
| 重置所有格式 | |
Workflow
工作流
No args → Apply best-practice defaults (all ON segments + theme). Go to step 4.
ansi-defaultTheme change (e.g. "use catppuccin-mocha", "switch to dracula") → Read themes.md, apply requested theme. Go to step 4. Aliases: → .
catppuccincatppuccin-mochaCustom requests (e.g. "add cost", "remove git", "no colors") → Interactive flow:
- Read current script:
cat ~/.claude/statusline-command.sh - Ask segments to enable/disable (AskUserQuestion multiSelect)
- Ask theme preference (AskUserQuestion with theme options)
- Generate script following Script Rules + selected theme from themes.md
- Write to
~/.claude/statusline-command.sh - Verify:
echo '{"model":{"display_name":"Opus 4.6"},"workspace":{"current_dir":"/tmp/test"},"context_window":{"remaining_percentage":55},"cost":{"total_cost_usd":0.42},"exceeds_200k_tokens":false}' | ~/.claude/statusline-command.sh
无参数 → 应用最佳实践默认配置(所有分段开启 + 主题),跳转至步骤4。
ansi-default主题切换(例如「使用catppuccin-mocha」、「切换到dracula」)→ 读取themes.md,应用请求的主题,跳转至步骤4。别名: → 。
catppuccincatppuccin-mocha自定义请求(例如「添加成本分段」、「移除git分段」、「关闭颜色」)→ 交互流程:
- 读取当前脚本:
cat ~/.claude/statusline-command.sh - 询问需要开启/关闭的分段(使用AskUserQuestion多选功能)
- 询问主题偏好(使用AskUserQuestion提供主题选项)
- 按照脚本规则 + themes.md中选中的主题生成脚本
- 写入到
~/.claude/statusline-command.sh - 验证:
echo '{"model":{"display_name":"Opus 4.6"},"workspace":{"current_dir":"/tmp/test"},"context_window":{"remaining_percentage":55},"cost":{"total_cost_usd":0.42},"exceeds_200k_tokens":false}' | ~/.claude/statusline-command.sh
Script Rules
脚本规则
- Shebang: (POSIX)
#!/bin/sh - Read stdin:
input=$(cat) - Parse JSON:
jq -r '.field // fallback' - Theme from env:
theme="${CLAUDE_STATUSLINE_THEME:-ansi-default}" - NO_COLOR:
[ -n "${NO_COLOR:-}" ] && theme="none" - Theme aliases: →
catppuccincatppuccin-mocha - Invalid theme: fallback to
ansi-default - Color output: for ANSI/TrueColor,
printf "%b"for noneprintf "%s" - TrueColor format: (24-bit foreground)
\033[38;2;R;G;Bm - Git:
git --no-optional-locks -C "$dir" - Git cache: , 5s TTL,
/tmp/claude-statusline-git-cache-$(id -u)(macOS) /stat -f %m(Linux)stat -c %Y - CWD truncation: depth >2 →
~/.../basename - Cost: only when , format
>= 0.005est $X.XX - Alert style: + bold (
C_ALERT) to distinguish from\033[1mC_CTX_BAD
- Shebang:(POSIX标准)
#!/bin/sh - 读取标准输入:
input=$(cat) - 解析JSON:
jq -r '.field // fallback' - 从环境变量读取主题:
theme="${CLAUDE_STATUSLINE_THEME:-ansi-default}" - NO_COLOR处理:
[ -n "${NO_COLOR:-}" ] && theme="none" - 主题别名:→
catppuccincatppuccin-mocha - 无效主题:兜底使用
ansi-default - 颜色输出:ANSI/TrueColor使用,无颜色主题使用
printf "%b"printf "%s" - TrueColor格式:(24位前景色)
\033[38;2;R;G;Bm - Git命令:
git --no-optional-locks -C "$dir" - Git缓存:,5秒有效期,macOS用
/tmp/claude-statusline-git-cache-$(id -u)/ Linux用stat -f %mstat -c %Y - 工作目录截断:路径深度>2时显示为
~/.../basename - 成本:仅当金额时显示,格式为
>= 0.005est $X.XX - 提醒样式:+ 粗体(
C_ALERT),和\033[1m区分C_CTX_BAD
Script Structure
脚本结构
sh
#!/bin/sh
input=$(cat)sh
#!/bin/sh
input=$(cat)... extract JSON fields ...
... 提取JSON字段 ...
theme="${CLAUDE_STATUSLINE_THEME:-ansi-default}"
[ -n "${NO_COLOR:-}" ] && theme="none"
case "$theme" in
catppuccin|catppuccin-mocha) # set C_* tokens with TrueColor values ;;
dracula) # ... ;;
nord) # ... ;;
none) # all C_* = "" ;;
*) # ansi-default: ANSI 16 colors ;;
esac
theme="${CLAUDE_STATUSLINE_THEME:-ansi-default}"
[ -n "${NO_COLOR:-}" ] && theme="none"
case "$theme" in
catppuccin|catppuccin-mocha) # 为C_令牌设置TrueColor值 ;;
dracula) # ... ;;
nord) # ... ;;
none) # 所有C_变量设为"" ;;
*) # ansi-default:使用ANSI 16色 ;;
esac
... build output using C_* tokens ...
... 使用C_*令牌构建输出 ...
if [ "$theme" = "none" ]; then
printf "%s" "$out"
else
printf "%b" "$out"
fi
undefinedif [ "$theme" = "none" ]; then
printf "%s" "$out"
else
printf "%b" "$out"
fi
undefinedExample Output
输出示例
~/.../my-project | feat/auth | Opus 4.6 | ctx 48% left · est $0.12
~/.../my-project | main | Opus 4.6 | ctx 18% left · est $1.23 · >200k~/.../my-project | feat/auth | Opus 4.6 | ctx 48% left · est $0.12
~/.../my-project | main | Opus 4.6 | ctx 18% left · est $1.23 · >200kOutput
产出物
| Artifact | Path | Description |
|---|---|---|
| StatusLine script | | POSIX shell script consuming JSON stdin |
| 产物 | 路径 | 说明 |
|---|---|---|
| 状态栏脚本 | | 接收JSON标准输入的POSIX shell脚本 |
Verification
验证
After generating the script, verify:
- exists and is executable (
~/.claude/statusline-command.sh)chmod +x - Test echo passes:
echo '{"model":{"display_name":"Opus 4.6"},"workspace":{"current_dir":"/tmp/test"},"context_window":{"remaining_percentage":55},"cost":{"total_cost_usd":0.42},"exceeds_200k_tokens":false}' | ~/.claude/statusline-command.sh - Output contains expected segments (directory, model, context %)
- Theme matches user selection (check color codes in script)
- produces uncolored output
NO_COLOR=1
生成脚本后,请验证:
- 存在且有可执行权限(执行
~/.claude/statusline-command.sh)chmod +x - 测试命令执行成功:
echo '{"model":{"display_name":"Opus 4.6"},"workspace":{"current_dir":"/tmp/test"},"context_window":{"remaining_percentage":55},"cost":{"total_cost_usd":0.42},"exceeds_200k_tokens":false}' | ~/.claude/statusline-command.sh - 输出包含预期分段(目录、模型、上下文占比等)
- 主题匹配用户选择(检查脚本中的颜色代码)
- 时输出无颜色
NO_COLOR=1