statusline-generator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Statusline 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
ccusage
for session/daily cost tracking, displays git branch status, and supports color customization.
本Skill提供创建和自定义Claude Code状态栏的工具与指南。它生成适配竖屏的多行状态栏,集成
ccusage
实现会话/每日成本追踪,显示Git分支状态,并支持颜色自定义。

When 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:
  1. Run the installation script:
    bash
    bash scripts/install_statusline.sh
  2. 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*+]
安装默认的多行状态栏:
  1. 运行安装脚本:
    bash
    bash scripts/install_statusline.sh
  2. 重启Claude Code即可看到状态栏
默认状态栏显示内容:
  • 第一行
    username (model) [session_cost/daily_cost]
  • 第二行
    current_path
  • 第三行
    [git:branch*+]

Manual Installation

手动安装

Alternatively, manually install by:
  1. Copy
    scripts/generate_statusline.sh
    to
    ~/.claude/statusline.sh
  2. Make it executable:
    chmod +x ~/.claude/statusline.sh
  3. Update
    ~/.claude/settings.json
    :
    json
    {
      "statusLine": {
        "type": "command",
        "command": "bash /home/username/.claude/statusline.sh",
        "padding": 0
      }
    }
也可选择手动安装:
  1. scripts/generate_statusline.sh
    复制到
    ~/.claude/statusline.sh
  2. 设置可执行权限:
    chmod +x ~/.claude/statusline.sh
  3. 更新
    ~/.claude/settings.json
    json
    {
      "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:
    [$session/$daily]
    in magenta
  • Caching: 2-minute cache to avoid performance impact
  • Background Fetch: First run loads costs asynchronously
Requirements:
ccusage
must be installed and in PATH. See
references/ccusage_integration.md
for installation and troubleshooting.
通过
ccusage
实现成本追踪:
  • 会话成本:当前对话的成本
  • 每日成本:当日累计成本
  • 格式:洋红色的
    [$session/$daily]
  • 缓存:2分钟缓存避免影响性能
  • 后台获取:首次加载时异步获取成本数据
要求
ccusage
必须已安装并加入PATH。安装与排查详情请参考
references/ccusage_integration.md

Model 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:
      [git:main*+]
      - Modified files and untracked files
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
~/.claude/statusline.sh
and modifying the ANSI color codes in the final
printf
statement. See
references/color_codes.md
for available colors.
Example: Change username to blue
bash
undefined
通过编辑
~/.claude/statusline.sh
中最终
printf
语句的ANSI颜色代码来自定义颜色。可用颜色参考
references/color_codes.md
示例:将用户名改为蓝色
bash
undefined

Find 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' \
undefined
printf '\033[01;34m%s\033[00m \033[01;36m(%s)\033[00m%s\n\033[01;37m%s\033[00m\n%s' \
undefined

Single-Line Layout

单行布局

Convert to single-line layout by modifying the final
printf
:
bash
undefined
修改最终
printf
语句可切换为单行布局:
bash
undefined

Replace:

替换:

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"
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"

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"
undefined
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"
undefined

Disabling Cost Tracking

禁用成本追踪

If
ccusage
is unavailable or not desired:
  1. Comment out the cost section in the script (lines ~47-73)
  2. Remove
    %s
    for
    $cost_info
    from the final
    printf
See
references/ccusage_integration.md
for details.
ccusage
不可用或不需要成本追踪:
  1. 注释脚本中的成本相关部分(约47-73行)
  2. 从最终
    printf
    语句中移除
    $cost_info
    对应的
    %s
详情请参考
references/ccusage_integration.md

Adding Custom Elements

添加自定义元素

Add custom information (e.g., hostname, time):
bash
undefined
可添加自定义信息(如主机名、时间):
bash
undefined

Add 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" ...
undefined
printf '\033[01;32m%s@%s\033[00m \033[01;36m(%s)\033[00m%s [%s]\n...'
"$username" "$hostname" "$model" "$cost_info" "$current_time" ...
undefined

Troubleshooting

问题排查

Costs Not Showing

成本信息不显示

Check:
  1. Is
    ccusage
    installed? Run
    which ccusage
  2. Test
    ccusage
    manually:
    ccusage session --json --offline -o desc
  3. Wait 5-10 seconds after first display (background fetch)
  4. Check cache:
    ls -lh /tmp/claude_cost_cache_*.txt
Solution: See
references/ccusage_integration.md
for detailed troubleshooting.
检查项:
  1. 是否已安装
    ccusage
    ?运行
    which ccusage
    验证
  2. 手动测试
    ccusage
    ccusage session --json --offline -o desc
  3. 首次显示后等待5-10秒(后台获取数据)
  4. 检查缓存:
    ls -lh /tmp/claude_cost_cache_*.txt
解决方案: 详细排查步骤请参考
references/ccusage_integration.md

Colors Hard to Read

颜色难以辨认

Solution: Adjust colors for your terminal background using
references/color_codes.md
. Bright colors (
01;3X
) are generally more visible than regular (
00;3X
).
解决方案: 参考
references/color_codes.md
根据终端背景调整颜色。亮色(
01;3X
)通常比常规颜色(
00;3X
)更清晰。

Statusline Not Updating

状态栏不更新

Check:
  1. Verify settings.json points to correct script path
  2. Ensure script is executable:
    chmod +x ~/.claude/statusline.sh
  3. Restart Claude Code
检查项:
  1. 验证settings.json指向正确的脚本路径
  2. 确保脚本具有可执行权限:
    chmod +x ~/.claude/statusline.sh
  3. 重启Claude Code

Git Status Not Showing

Git状态不显示

Check:
  1. Are you in a git repository?
  2. Test git commands:
    git branch --show-current
  3. Check git permissions in the directory
检查项:
  1. 当前目录是否为Git仓库?
  2. 测试Git命令:
    git branch --show-current
  3. 检查目录下的Git权限

Resources

资源

scripts/generate_statusline.sh

scripts/generate_statusline.sh

Main statusline script with all features (multi-line, ccusage, git, colors). Copy this to
~/.claude/statusline.sh
for use.
包含所有功能的主状态栏脚本(多行布局、ccusage集成、Git状态、颜色)。复制到
~/.claude/statusline.sh
即可使用。

scripts/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结构和排查步骤。用户遇到成本追踪问题或想了解工作原理时可加载此文档。