重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
statusline-setup by b-open-io/prompts
npx skills add https://github.com/b-open-io/prompts --skill statusline-setup创建并自定义 Claude Code 状态行,以显示上下文信息,如模型名称、Git 分支、令牌使用情况、项目颜色等。
Claude Code 支持在界面底部显示自定义状态行。状态行会在对话消息更改时更新,最多每 300 毫秒运行一次。
设置状态行时,首先检查现有配置,并使用 AskUserQuestion 收集偏好设置。
# 检查现有配置
if [[ -f ~/.claude/settings.json ]]; then
EXISTING=$(jq -r '.statusLine // empty' ~/.claude/settings.json)
if [[ -n "$EXISTING" ]]; then
# 用户已有状态行 - 询问是否备份
fi
fi
创建一个通过 stdin 接收 JSON 数据并输出带 ANSI 颜色的单行文本的 shell 脚本。
快速设置:
cat > ~/.claude/statusline.sh << 'EOF'
#!/bin/bash
input=$(cat)
MODEL=$(echo "$input" | jq -r '.model.display_name')
DIR=$(basename "$(echo "$input" | jq -r '.workspace.current_dir')")
echo "[$MODEL] $DIR"
EOF
chmod +x ~/.claude/statusline.sh
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
在设置中配置:
{
"statusLine": {
"type": "command",
"command": "~/.claude/statusline.sh",
"padding": 0
}
}
使用第三方工具 ccstatusline 实现基于小部件的方法,并提供 TUI 配置界面。
快速设置:
bunx ccstatusline@latest
在设置中配置:
{
"statusLine": "bunx ccstatusline@latest"
}
状态行命令通过 stdin 接收结构化的 JSON:
| 字段 | 描述 |
|---|---|
model.id | 模型标识符(例如 "claude-opus-4-1") |
model.display_name | 人类可读的名称(例如 "Opus") |
workspace.current_dir | 当前工作目录 |
workspace.project_dir | 原始项目目录 |
cost.total_cost_usd | 会话成本(美元) |
cost.total_duration_ms | 总会话持续时间 |
context_window.context_window_size | 最大上下文大小 |
context_window.current_usage | 当前令牌使用情况对象 |
transcript_path | 会话转录 JSON 文件的路径 |
session_id | 唯一的会话标识符 |
if git rev-parse --git-dir > /dev/null 2>&1; then
BRANCH=$(git branch --show-current 2>/dev/null)
DIRTY=""
git diff --quiet HEAD 2>/dev/null || DIRTY="*"
echo "[$MODEL] $BRANCH$DIRTY"
fi
USAGE=$(echo "$input" | jq '.context_window.current_usage')
if [ "$USAGE" != "null" ]; then
TOKENS=$(echo "$USAGE" | jq '.input_tokens + .cache_creation_input_tokens + .cache_read_input_tokens')
SIZE=$(echo "$input" | jq -r '.context_window.context_window_size')
PERCENT=$((TOKENS * 100 / SIZE))
echo "Context: ${PERCENT}%"
fi
SETTINGS=".vscode/settings.json"
if [[ -f "$SETTINGS" ]]; then
COLOR=$(jq -r '.["peacock.color"] // empty' "$SETTINGS")
fi
FILE_URL="vscode://file${LAST_FILE}"
echo -e "\033]8;;${FILE_URL}\a${FILENAME}\033]8;;\a"
使用模拟 JSON 测试脚本:
echo '{"model":{"display_name":"Opus"},"workspace":{"current_dir":"/test"}}' | ./statusline.sh
使用 scripts/install-statusline.sh 可以:
~/.claude/备份文件会带有时间戳,保存在 ~/.claude/ 目录中:
# 列出可用备份
ls -la ~/.claude/*.backup.*
# 使用恢复脚本进行恢复
~/.claude/plugins/cache/.../scripts/restore-statusline.sh
# 或手动恢复
LATEST=$(ls -t ~/.claude/settings.json.backup.* 2>/dev/null | head -1)
if [[ -n "$LATEST" ]]; then
cp "$LATEST" ~/.claude/settings.json
fi
有关详细的实施指南,请参阅参考资料目录:
references/json-input-schema.md - 完整的 JSON 输入文档,包含所有字段、Bash/Python/Node.js 中的提取示例以及处理 null 值的方法references/scripting-patterns.md - ANSI 颜色代码(256 色和真彩色)、Powerline 分隔符、Git 集成模式、项目检测、可点击链接(OSC 8)、终端集成和格式化辅助工具references/ccstatusline-guide.md - 完整的小部件文档、安装、配置选项、可用小部件、多行设置和故障排除每周安装数
49
代码仓库
GitHub 星标数
7
首次出现
2026 年 1 月 24 日
安全审计
已安装于
claude-code45
opencode43
gemini-cli42
cursor40
codex39
github-copilot36
Create and customize Claude Code status lines to display contextual information like model name, git branch, token usage, project colors, and more.
Claude Code supports custom status lines displayed at the bottom of the interface. Status lines update when conversation messages change, running at most every 300ms.
When setting up a status line, first check for existing configuration and use AskUserQuestion to gather preferences.
# Check for existing configuration
if [[ -f ~/.claude/settings.json ]]; then
EXISTING=$(jq -r '.statusLine // empty' ~/.claude/settings.json)
if [[ -n "$EXISTING" ]]; then
# User has existing status line - ask about backup
fi
fi
Create a shell script that receives JSON data via stdin and outputs a single line with ANSI colors.
Quick setup:
cat > ~/.claude/statusline.sh << 'EOF'
#!/bin/bash
input=$(cat)
MODEL=$(echo "$input" | jq -r '.model.display_name')
DIR=$(basename "$(echo "$input" | jq -r '.workspace.current_dir')")
echo "[$MODEL] $DIR"
EOF
chmod +x ~/.claude/statusline.sh
Configure in settings:
{
"statusLine": {
"type": "command",
"command": "~/.claude/statusline.sh",
"padding": 0
}
}
Use the third-party ccstatusline for a widget-based approach with TUI configuration.
Quick setup:
bunx ccstatusline@latest
Configure in settings:
{
"statusLine": "bunx ccstatusline@latest"
}
The status line command receives structured JSON via stdin:
| Field | Description |
|---|---|
model.id | Model identifier (e.g., "claude-opus-4-1") |
model.display_name | Human-readable name (e.g., "Opus") |
workspace.current_dir | Current working directory |
workspace.project_dir | Original project directory |
cost.total_cost_usd | Session cost in USD |
cost.total_duration_ms |
if git rev-parse --git-dir > /dev/null 2>&1; then
BRANCH=$(git branch --show-current 2>/dev/null)
DIRTY=""
git diff --quiet HEAD 2>/dev/null || DIRTY="*"
echo "[$MODEL] $BRANCH$DIRTY"
fi
USAGE=$(echo "$input" | jq '.context_window.current_usage')
if [ "$USAGE" != "null" ]; then
TOKENS=$(echo "$USAGE" | jq '.input_tokens + .cache_creation_input_tokens + .cache_read_input_tokens')
SIZE=$(echo "$input" | jq -r '.context_window.context_window_size')
PERCENT=$((TOKENS * 100 / SIZE))
echo "Context: ${PERCENT}%"
fi
SETTINGS=".vscode/settings.json"
if [[ -f "$SETTINGS" ]]; then
COLOR=$(jq -r '.["peacock.color"] // empty' "$SETTINGS")
fi
FILE_URL="vscode://file${LAST_FILE}"
echo -e "\033]8;;${FILE_URL}\a${FILENAME}\033]8;;\a"
Test scripts with mock JSON:
echo '{"model":{"display_name":"Opus"},"workspace":{"current_dir":"/test"}}' | ./statusline.sh
Use scripts/install-statusline.sh to:
~/.claude/Backups are created with timestamps in ~/.claude/:
# List available backups
ls -la ~/.claude/*.backup.*
# Restore using restore script
~/.claude/plugins/cache/.../scripts/restore-statusline.sh
# Or manually
LATEST=$(ls -t ~/.claude/settings.json.backup.* 2>/dev/null | head -1)
if [[ -n "$LATEST" ]]; then
cp "$LATEST" ~/.claude/settings.json
fi
For detailed implementation guidance, see the references directory:
references/json-input-schema.md - Complete JSON input documentation with all fields, extraction examples in Bash/Python/Node.js, and handling null valuesreferences/scripting-patterns.md - ANSI color codes (256-color and true color), Powerline separators, Git integration patterns, project detection, clickable links (OSC 8), terminal integration, and formatting helpersreferences/ccstatusline-guide.md - Complete widget documentation, installation, configuration options, available widgets, multi-line setup, and troubleshootingWeekly Installs
49
Repository
GitHub Stars
7
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubWarnSocketPassSnykWarn
Installed on
claude-code45
opencode43
gemini-cli42
cursor40
codex39
github-copilot36
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
123,700 周安装
| Total session duration |
context_window.context_window_size | Max context size |
context_window.current_usage | Current token usage object |
transcript_path | Path to session transcript JSON |
session_id | Unique session identifier |