statusline-generator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseStatusline Generator
状态栏生成工具
Overview
概述
This skill provides tools and guidance for creating and customizing Claude Code statuslines. It generates multi-line statuslines optimized for portrait screens, integrates with for session/daily cost tracking, displays git branch status, and supports color customization.
ccusage本Skill提供创建和自定义Claude Code状态栏的工具与指南。它生成适配竖屏的多行状态栏,集成实现会话/每日成本追踪,显示Git分支状态,并支持颜色自定义。
ccusageWhen to Use This Skill
使用场景
This skill activates for:
- Statusline configuration requests for Claude Code
- Cost information display (session/daily costs)
- Multi-line layouts for portrait or narrow screens
- Statusline color or format customization
- Statusline display or cost tracking issues
- Git status or path shortening features
本Skill适用于以下场景:
- Claude Code状态栏配置请求
- 成本信息显示(会话/每日成本)
- 竖屏或窄屏适配的多行布局
- 状态栏颜色或格式自定义
- 状态栏显示或成本追踪问题排查
- Git状态或路径缩短功能需求
Quick Start
快速开始
Basic Installation
基础安装
Install the default multi-line statusline:
-
Run the installation script:bash
bash scripts/install_statusline.sh -
Restart Claude Code to see the statusline
The default statusline displays:
- Line 1:
username (model) [session_cost/daily_cost] - Line 2:
current_path - Line 3:
[git:branch*+]
安装默认的多行状态栏:
-
运行安装脚本:bash
bash scripts/install_statusline.sh -
重启Claude Code即可看到状态栏
默认状态栏显示内容:
- 第一行:
username (model) [session_cost/daily_cost] - 第二行:
current_path - 第三行:
[git:branch*+]
Manual Installation
手动安装
Alternatively, manually install by:
- Copy to
scripts/generate_statusline.sh~/.claude/statusline.sh - Make it executable:
chmod +x ~/.claude/statusline.sh - Update :
~/.claude/settings.jsonjson{ "statusLine": { "type": "command", "command": "bash /home/username/.claude/statusline.sh", "padding": 0 } }
也可选择手动安装:
- 将复制到
scripts/generate_statusline.sh~/.claude/statusline.sh - 设置可执行权限:
chmod +x ~/.claude/statusline.sh - 更新:
~/.claude/settings.jsonjson{ "statusLine": { "type": "command", "command": "bash /home/username/.claude/statusline.sh", "padding": 0 } }
Statusline Features
状态栏功能
Multi-Line Layout
多行布局
The statusline uses a 3-line layout optimized for portrait screens:
username (Sonnet 4.5 [1M]) [$0.26/$25.93]
~/workspace/java/ready-together-svc
[git:feature/branch-name*+]Benefits:
- Shorter lines fit narrow screens
- Clear visual separation of information types
- No horizontal scrolling needed
状态栏采用适配竖屏的3行布局:
username (Sonnet 4.5 [1M]) [$0.26/$25.93]
~/workspace/java/ready-together-svc
[git:feature/branch-name*+]优势:
- 较短的行宽适配窄屏
- 不同类型信息视觉区分清晰
- 无需横向滚动
Cost Tracking Integration
成本追踪集成
Cost tracking via :
ccusage- Session Cost: Current conversation cost
- Daily Cost: Total cost for today
- Format: in magenta
[$session/$daily] - Caching: 2-minute cache to avoid performance impact
- Background Fetch: First run loads costs asynchronously
Requirements: must be installed and in PATH. See for installation and troubleshooting.
ccusagereferences/ccusage_integration.md通过实现成本追踪:
ccusage- 会话成本:当前对话的成本
- 每日成本:当日累计成本
- 格式:洋红色的
[$session/$daily] - 缓存:2分钟缓存避免影响性能
- 后台获取:首次加载时异步获取成本数据
要求:必须已安装并加入PATH。安装与排查详情请参考。
ccusagereferences/ccusage_integration.mdModel Name Shortening
模型名称简化
Model names are automatically shortened:
- →
"Sonnet 4.5 (with 1M token context)""Sonnet 4.5 [1M]" - →
"Opus 4.1 (with 500K token context)""Opus 4.1 [500K]"
This saves horizontal space while preserving key information.
模型名称会自动简化:
- →
"Sonnet 4.5 (with 1M token context)""Sonnet 4.5 [1M]" - →
"Opus 4.1 (with 500K token context)""Opus 4.1 [500K]"
在保留关键信息的同时节省横向空间。
Git Status Indicators
Git状态标识
Git branch status shows:
- Yellow: Clean branch (no changes)
- Red: Dirty branch (uncommitted changes)
- Indicators:
- - Modified or staged files
* - - Untracked files
+ - Example: - Modified files and untracked files
[git:main*+]
Git分支状态显示规则:
- 黄色:分支干净(无修改)
- 红色:分支有未提交修改
- 标识说明:
- - 文件已修改或暂存
* - - 存在未追踪文件
+ - 示例:- 存在已修改文件和未追踪文件
[git:main*+]
Path Shortening
路径缩短
Paths are shortened:
- Home directory replaced with
~ - Example: →
/home/username/workspace/project~/workspace/project
路径会自动缩短:
- 主目录替换为
~ - 示例:→
/home/username/workspace/project~/workspace/project
Color Scheme
配色方案
Default colors optimized for visibility:
- Username: Bright Green ()
\033[01;32m - Model: Bright Cyan ()
\033[01;36m - Costs: Bright Magenta ()
\033[01;35m - Path: Bright White ()
\033[01;37m - Git (clean): Bright Yellow ()
\033[01;33m - Git (dirty): Bright Red ()
\033[01;31m
默认配色优化了可见性:
- 用户名:亮绿色 ()
\033[01;32m - 模型:亮青色 ()
\033[01;36m - 成本:亮洋红色 ()
\033[01;35m - 路径:亮白色 ()
\033[01;37m - Git(干净分支):亮黄色 ()
\033[01;33m - Git(脏分支):亮红色 ()
\033[01;31m
Customization
自定义配置
Changing Colors
修改颜色
Customize colors by editing and modifying the ANSI color codes in the final statement. See for available colors.
~/.claude/statusline.shprintfreferences/color_codes.mdExample: Change username to blue
bash
undefined通过编辑中最终语句的ANSI颜色代码来自定义颜色。可用颜色参考。
~/.claude/statusline.shprintfreferences/color_codes.md示例:将用户名改为蓝色
bash
undefinedFind this line:
找到该行:
printf '\033[01;32m%s\033[00m \033[01;36m(%s)\033[00m%s\n\033[01;37m%s\033[00m\n%s' \
printf '\033[01;32m%s\033[00m \033[01;36m(%s)\033[00m%s\n\033[01;37m%s\033[00m\n%s' \
Change \033[01;32m (green) to \033[01;34m (blue):
将\033[01;32m(绿色)改为\033[01;34m(蓝色):
printf '\033[01;34m%s\033[00m \033[01;36m(%s)\033[00m%s\n\033[01;37m%s\033[00m\n%s' \
undefinedprintf '\033[01;34m%s\033[00m \033[01;36m(%s)\033[00m%s\n\033[01;37m%s\033[00m\n%s' \
undefinedSingle-Line Layout
单行布局
Convert to single-line layout by modifying the final :
printfbash
undefined修改最终语句可切换为单行布局:
printfbash
undefinedReplace:
替换:
printf '\033[01;32m%s\033[00m \033[01;36m(%s)\033[00m%s\n\033[01;37m%s\033[00m\n%s'
"$username" "$model" "$cost_info" "$short_path" "$git_info"
"$username" "$model" "$cost_info" "$short_path" "$git_info"
printf '\033[01;32m%s\033[00m \033[01;36m(%s)\033[00m%s\n\033[01;37m%s\033[00m\n%s'
"$username" "$model" "$cost_info" "$short_path" "$git_info"
"$username" "$model" "$cost_info" "$short_path" "$git_info"
With:
替换为:
printf '\033[01;32m%s\033[00m \033[01;36m(%s)\033[00m:\033[01;37m%s\033[00m%s%s'
"$username" "$model" "$short_path" "$git_info" "$cost_info"
"$username" "$model" "$short_path" "$git_info" "$cost_info"
undefinedprintf '\033[01;32m%s\033[00m \033[01;36m(%s)\033[00m:\033[01;37m%s\033[00m%s%s'
"$username" "$model" "$short_path" "$git_info" "$cost_info"
"$username" "$model" "$short_path" "$git_info" "$cost_info"
undefinedDisabling Cost Tracking
禁用成本追踪
If is unavailable or not desired:
ccusage- Comment out the cost section in the script (lines ~47-73)
- Remove for
%sfrom the final$cost_infoprintf
See for details.
references/ccusage_integration.md若不可用或不需要成本追踪:
ccusage- 注释脚本中的成本相关部分(约47-73行)
- 从最终语句中移除
printf对应的$cost_info%s
详情请参考。
references/ccusage_integration.mdAdding Custom Elements
添加自定义元素
Add custom information (e.g., hostname, time):
bash
undefined可添加自定义信息(如主机名、时间):
bash
undefinedAdd variable before final printf:
在最终printf前添加变量:
hostname=$(hostname -s)
current_time=$(date +%H:%M)
hostname=$(hostname -s)
current_time=$(date +%H:%M)
Update printf to include new elements:
更新printf以包含新元素:
printf '\033[01;32m%s@%s\033[00m \033[01;36m(%s)\033[00m%s [%s]\n...'
"$username" "$hostname" "$model" "$cost_info" "$current_time" ...
"$username" "$hostname" "$model" "$cost_info" "$current_time" ...
undefinedprintf '\033[01;32m%s@%s\033[00m \033[01;36m(%s)\033[00m%s [%s]\n...'
"$username" "$hostname" "$model" "$cost_info" "$current_time" ...
"$username" "$hostname" "$model" "$cost_info" "$current_time" ...
undefinedTroubleshooting
问题排查
Costs Not Showing
成本信息不显示
Check:
- Is installed? Run
ccusagewhich ccusage - Test manually:
ccusageccusage session --json --offline -o desc - Wait 5-10 seconds after first display (background fetch)
- Check cache:
ls -lh /tmp/claude_cost_cache_*.txt
Solution: See for detailed troubleshooting.
references/ccusage_integration.md检查项:
- 是否已安装?运行
ccusage验证which ccusage - 手动测试:
ccusageccusage session --json --offline -o desc - 首次显示后等待5-10秒(后台获取数据)
- 检查缓存:
ls -lh /tmp/claude_cost_cache_*.txt
解决方案: 详细排查步骤请参考。
references/ccusage_integration.mdColors Hard to Read
颜色难以辨认
Solution: Adjust colors for your terminal background using . Bright colors () are generally more visible than regular ().
references/color_codes.md01;3X00;3X解决方案: 参考根据终端背景调整颜色。亮色()通常比常规颜色()更清晰。
references/color_codes.md01;3X00;3XStatusline Not Updating
状态栏不更新
Check:
- Verify settings.json points to correct script path
- Ensure script is executable:
chmod +x ~/.claude/statusline.sh - Restart Claude Code
检查项:
- 验证settings.json指向正确的脚本路径
- 确保脚本具有可执行权限:
chmod +x ~/.claude/statusline.sh - 重启Claude Code
Git Status Not Showing
Git状态不显示
Check:
- Are you in a git repository?
- Test git commands:
git branch --show-current - Check git permissions in the directory
检查项:
- 当前目录是否为Git仓库?
- 测试Git命令:
git branch --show-current - 检查目录下的Git权限
Resources
资源
scripts/generate_statusline.sh
scripts/generate_statusline.sh
Main statusline script with all features (multi-line, ccusage, git, colors). Copy this to for use.
~/.claude/statusline.sh包含所有功能的主状态栏脚本(多行布局、ccusage集成、Git状态、颜色)。复制到即可使用。
~/.claude/statusline.shscripts/install_statusline.sh
scripts/install_statusline.sh
Automated installation script that copies the statusline script and updates settings.json.
自动化安装脚本,负责复制状态栏脚本并更新settings.json。
references/color_codes.md
references/color_codes.md
Complete ANSI color code reference for customizing statusline colors. Load when users request color customization.
完整的ANSI颜色代码参考,用于自定义状态栏颜色。用户请求颜色自定义时可加载此文档。
references/ccusage_integration.md
references/ccusage_integration.md
Detailed explanation of ccusage integration, caching strategy, JSON structure, and troubleshooting. Load when users experience cost tracking issues or want to understand how it works.
ccusage集成的详细说明,包括缓存策略、JSON结构和排查步骤。用户遇到成本追踪问题或想了解工作原理时可加载此文档。