statusline-config

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

StatusLine Config

状态栏配置

Customize
~/.claude/statusline-command.sh
— segments, themes, and colors.
自定义
~/.claude/statusline-command.sh
— 包括分段、主题和颜色。

When NOT to Use

不适用场景

ScenarioUse Instead
Setting statusline for the first time (no customization needed)Built-in
statusline-setup
agent (Claude Code agent type) — applies defaults automatically
Editing
settings.json
directly
Manual edit — this skill manages
statusline-command.sh
, not
settings.json
Debugging Claude Code startup issues
/claude-health
— config health check
场景替代方案
首次设置状态栏(无需自定义)内置
statusline-setup
Agent(Claude Code Agent类型)—— 自动应用默认配置
直接编辑
settings.json
手动编辑 —— 本技能管理的是
statusline-command.sh
,而非
settings.json
调试Claude Code启动问题
/claude-health
—— 配置健康检查

Segments

分段

SegmentJSON FieldDefaultNotes
Directory
workspace.current_dir
ONTruncate deep paths:
~/.../last-dir
Git branchshell
git
ON
--no-optional-locks
, cache 5s
Model
model.display_name
ON-
Context %
context_window.remaining_percentage
ONGreen >40%, Yellow 20-40%, Red <=20%
Cost
cost.total_cost_usd
ONShow when >= $0.005,
est $X.XX
>200k alert
exceeds_200k_tokens
ONShow only when
true
For full JSON schema, see json-schema.md.
分段名JSON 字段默认状态说明
目录
workspace.current_dir
开启长路径自动截断:
~/.../last-dir
Git 分支shell
git
开启
--no-optional-locks
,缓存5秒
模型
model.display_name
开启-
上下文占比
context_window.remaining_percentage
开启>40%显示绿色,20-40%显示黄色,<=20%显示红色
成本
cost.total_cost_usd
开启金额>= $0.005时显示,格式为
est $X.XX
超200k令牌提醒
exceeds_200k_tokens
开启仅为
true
时显示
完整JSON schema请查看json-schema.md

Themes

主题

ThemeTypeDefaultNotes
ansi-default
ANSI 16Safe fallback, works everywhere
catppuccin-mocha
TrueColorRecommended — pastel, WCAG AA >=4.5:1
dracula
TrueColorVibrant purple/pink accents
nord
TrueColorArctic blue, muted tones
none
No colors (
NO_COLOR
auto-triggers)
Switch via:
export CLAUDE_STATUSLINE_THEME=catppuccin-mocha
For complete token→hex mappings, see themes.md.
主题名类型默认说明
ansi-default
ANSI 16兼容所有环境的安全兜底方案
catppuccin-mocha
TrueColor推荐使用 —— 柔和配色,WCAG AA对比度>=4.5:1
dracula
TrueColor高饱和度紫/粉强调色
nord
TrueColor北极蓝调,低饱和度配色
none
无颜色(
NO_COLOR
环境变量会自动触发该主题)
切换命令:
export CLAUDE_STATUSLINE_THEME=catppuccin-mocha
完整令牌到十六进制颜色的映射请查看themes.md

Semantic Tokens

语义令牌

Scripts use semantic tokens instead of hardcoded colors:
TokenRoleExample
C_CWD
Directory pathblue / sapphire
C_BRANCH
Git branch namemagenta / mauve
C_MODEL
Model display namecyan / teal
C_CTX_OK
Context >= 41%green
C_CTX_WARN
Context 21-40%yellow
C_CTX_BAD
Context <= 20%red
C_COST
Cost displaymuted text
C_ALERT
>200k token warningorange/peach + bold
C_SEP
Pipe separator
|
dim/overlay
C_MUTED
Secondary infosubtext
C_TEXT
General textforeground
C_RESET
Reset all formatting
\033[0m
脚本使用语义令牌而非硬编码颜色:
令牌名作用示例配色
C_CWD
目录路径蓝色 / 蓝宝石色
C_BRANCH
Git分支名品红色 / 淡紫色
C_MODEL
模型显示名青色 / 蓝绿色
C_CTX_OK
上下文占比>=41%绿色
C_CTX_WARN
上下文占比21-40%黄色
C_CTX_BAD
上下文占比<=20%红色
C_COST
成本显示低对比度文字
C_ALERT
超200k令牌警告橙色/桃色 + 粗体
C_SEP
管道分隔符
|
低亮度/覆盖色
C_MUTED
次要信息辅助文字
C_TEXT
通用文本前景色
C_RESET
重置所有格式
\033[0m

Workflow

工作流

No args → Apply best-practice defaults (all ON segments +
ansi-default
theme). Go to step 4.
Theme change (e.g. "use catppuccin-mocha", "switch to dracula") → Read themes.md, apply requested theme. Go to step 4. Aliases:
catppuccin
catppuccin-mocha
.
Custom requests (e.g. "add cost", "remove git", "no colors") → Interactive flow:
  1. Read current script:
    cat ~/.claude/statusline-command.sh
  2. Ask segments to enable/disable (AskUserQuestion multiSelect)
  3. Ask theme preference (AskUserQuestion with theme options)
  4. Generate script following Script Rules + selected theme from themes.md
  5. Write to
    ~/.claude/statusline-command.sh
  6. 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
无参数 → 应用最佳实践默认配置(所有分段开启 +
ansi-default
主题),跳转至步骤4。
主题切换(例如「使用catppuccin-mocha」、「切换到dracula」)→ 读取themes.md,应用请求的主题,跳转至步骤4。别名:
catppuccin
catppuccin-mocha
自定义请求(例如「添加成本分段」、「移除git分段」、「关闭颜色」)→ 交互流程:
  1. 读取当前脚本:
    cat ~/.claude/statusline-command.sh
  2. 询问需要开启/关闭的分段(使用AskUserQuestion多选功能)
  3. 询问主题偏好(使用AskUserQuestion提供主题选项)
  4. 按照脚本规则 + themes.md中选中的主题生成脚本
  5. 写入到
    ~/.claude/statusline-command.sh
  6. 验证:
    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:
    #!/bin/sh
    (POSIX)
  • 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:
    catppuccin
    catppuccin-mocha
  • Invalid theme: fallback to
    ansi-default
  • Color output:
    printf "%b"
    for ANSI/TrueColor,
    printf "%s"
    for none
  • TrueColor format:
    \033[38;2;R;G;Bm
    (24-bit foreground)
  • Git:
    git --no-optional-locks -C "$dir"
  • Git cache:
    /tmp/claude-statusline-git-cache-$(id -u)
    , 5s TTL,
    stat -f %m
    (macOS) /
    stat -c %Y
    (Linux)
  • CWD truncation: depth >2 →
    ~/.../basename
  • Cost: only when
    >= 0.005
    , format
    est $X.XX
  • Alert style:
    C_ALERT
    + bold (
    \033[1m
    ) to distinguish from
    C_CTX_BAD
  • Shebang:
    #!/bin/sh
    (POSIX标准)
  • 读取标准输入:
    input=$(cat)
  • 解析JSON:
    jq -r '.field // fallback'
  • 从环境变量读取主题:
    theme="${CLAUDE_STATUSLINE_THEME:-ansi-default}"
  • NO_COLOR处理:
    [ -n "${NO_COLOR:-}" ] && theme="none"
  • 主题别名:
    catppuccin
    catppuccin-mocha
  • 无效主题:兜底使用
    ansi-default
  • 颜色输出:ANSI/TrueColor使用
    printf "%b"
    ,无颜色主题使用
    printf "%s"
  • TrueColor格式:
    \033[38;2;R;G;Bm
    (24位前景色)
  • Git命令:
    git --no-optional-locks -C "$dir"
  • Git缓存:
    /tmp/claude-statusline-git-cache-$(id -u)
    ,5秒有效期,macOS用
    stat -f %m
    / Linux用
    stat -c %Y
  • 工作目录截断:路径深度>2时显示为
    ~/.../basename
  • 成本:仅当金额
    >= 0.005
    时显示,格式为
    est $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
undefined
if [ "$theme" = "none" ]; then printf "%s" "$out" else printf "%b" "$out" fi
undefined

Example 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 · >200k

Output

产出物

ArtifactPathDescription
StatusLine script
~/.claude/statusline-command.sh
POSIX shell script consuming JSON stdin
产物路径说明
状态栏脚本
~/.claude/statusline-command.sh
接收JSON标准输入的POSIX shell脚本

Verification

验证

After generating the script, verify:
  • ~/.claude/statusline-command.sh
    exists and is executable (
    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)
  • NO_COLOR=1
    produces uncolored output
生成脚本后,请验证:
  • ~/.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
    时输出无颜色