
Status line 是 Claude Code 的本地可编程状态栏:Claude Code 把 session JSON 送进你的脚本,你把模型、目录、上下文、成本、git、worktree 等信息渲染到底部。本篇拆解配置字段、刷新机制、可用 JSON 字段、脚本模板、subagentStatusLine 边界和排障清单。

/statusline,用自然语言描述你想显示的内容。官方文档给的例子是:/statusline show model name and context percentage with a progress bar。Claude Code 会生成脚本,并更新 ~/.claude/ 下的配置。1statusLine 字段。它的 type 设为 command,command 指向脚本路径或 inline shell 命令。官方手写配置的骨架是这样:1{
"statusLine": {
"type": "command",
"command": "~/.claude/statusline.sh",
"padding": 2
}
}padding 给内容增加水平缩进;refreshInterval 让命令按固定秒数重跑,适合展示时钟或外部状态;hideVimModeIndicator 可以隐藏内置的 -- INSERT --,前提是你的脚本已经自己渲染 vim.mode。1
/compact 完成之后、permission mode 改变时、vim mode 切换时。刷新有 300ms debounce;如果新的刷新事件发生时旧脚本还在跑,旧执行会被取消。1git status、git diff、调用外部 API、扫大仓库文件,都可能让底部信息滞后。官方示例建议给昂贵操作加缓存,并用 session_id 生成稳定但互不冲突的缓存文件名,而不是用每次进程都会变化的 $$ 或 process.pid。1statusLine 设置 refreshInterval。1| 想解决的问题 | 推荐字段 | 使用建议 |
|---|---|---|
| 分清当前模型 | model.id、model.display_name | 多模型切换时显示 display_name,排障时再看 id。1 |
| 分清当前目录 | cwd、workspace.current_dir、workspace.project_dir | 文档建议优先用 workspace.current_dir,因为它与 project dir 语义更一致。1 |
| 盯住上下文 | context_window.used_percentage、remaining_percentage、current_usage | used_percentage 是最省事的指标;自己计算时只按 input/cache 相关 token 算,不把 output token 加进去。1 |
| 盯住成本 | cost.total_cost_usd、cost.total_duration_ms、cost.total_api_duration_ms | 这些是当前 session 的估算成本和耗时,可用于长任务成本感知。1 |
| 分清并行环境 | workspace.git_worktree、worktree.name、worktree.branch | 多 worktree session 同时跑时,把分支名放在状态栏比靠窗口标题靠谱。1 |
| 做订阅额度提醒 | rate_limits.five_hour.used_percentage、rate_limits.seven_day.used_percentage | rate limit 字段只在 Claude.ai Pro/Max 订阅用户且首次 API response 后出现,脚本要处理字段缺失。1 |
null。比如 session_name 只有设置过 --name 或 /rename 才出现,vim 只在启用 vim mode 时出现,context_window.current_usage 在首个 API 调用前和 /compact 后可能是 null。脚本里要用 fallback,别直接假定字段永远存在。1#!/bin/bash
input=$(cat)
MODEL=$(echo "$input" | jq -r '.model.display_name // "Claude"')
DIR=$(echo "$input" | jq -r '.workspace.current_dir // .cwd // ""')
PCT=$(echo "$input" | jq -r '.context_window.used_percentage // 0' | cut -d. -f1)
BRANCH=""
if git rev-parse --git-dir >/dev/null 2>&1; then
BRANCH=$(git branch --show-current 2>/dev/null)
fi
if [ -n "$BRANCH" ]; then
echo "[$MODEL] ${DIR##*/} | git:$BRANCH | ctx:${PCT}%"
else
echo "[$MODEL] ${DIR##*/} | ctx:${PCT}%"
fi{
"statusLine": {
"type": "command",
"command": "~/.claude/statusline.sh"
}
}chmod +x ~/.claude/statusline.sh。设置写入后,Claude Code 会在下一次交互时显示状态栏。1
| 机制 | 适合做什么 | 不适合做什么 |
|---|---|---|
statusLine | 在底部显示你脚本输出的会话状态,例如模型、上下文、费用、git、worktree。1 | 不适合把普通 ID 自动变成 footer badge。 |
footerLinksRegexes | 当对话输出里出现某类 ID 时,在 footer 里生成可点击 badge;官方说明它不需要写脚本。2 | 不适合展示连续变化的 session 仪表盘。 |
subagentStatusLine | 改写 agent panel 中每个可见 subagent 行的内容,输入是包含 tasks 数组的 JSON,并要求每行输出 { "id": "", "content": "" }。1 | 不替代主 session 底部 status line。 |
chmod +x ~/.claude/statusline.sh。command 里用正斜杠路径,例如 C:/Users/username/.claude/statusline.ps1。1disableAllHooks 开着:这个设置会同时禁用 hooks 和自定义 status line。2null,用 // 0、// empty 兜底。1/statusline show model name, current directory and context percentage,让 Claude Code 生成第一版。worktree.branch 或 workspace.git_worktree 加进去。cost.total_cost_usd 和 cost.total_duration_ms 加进去。docs.anthropic.com
docs.anthropic.com
docs.anthropic.com
This story was produced automatically by a channel. One sentence is all it takes for Neodrop to keep producing for you.