Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Turn the blank status bar into a real-time dashboard: model, context usage with
| **3-tier rendering** | True color → ANSI → ASCII. Works in any terminal. |
| **Nerd Font support** | Optional: ``, `󰔟`, `` icons. Set `CLAUDE_STATUSLINE_NERDFONT=1`. |
| **Powerline separators** | Optional: `` arrows. Set `CLAUDE_STATUSLINE_POWERLINE=1`. |
| **Boot cost indicator** | Shows how much context your startup config (CLAUDE.md, rules, memory, skills) consumes — before you even ask a question. Progress bar splits into dark (boot) vs gradient (chat). |
| **< 50ms** | Single `jq` call + cached git. No perceptible lag. |

## Installation
Expand Down Expand Up @@ -102,6 +103,23 @@ Example:
export CLAUDE_STATUSLINE_NERDFONT=1 # Enable Nerd Font icons + Powerline arrows
```

## Boot cost indicator

Most users don't realize how much context their startup configuration consumes. A large `CLAUDE.md`, many rules, memory files, and skills can eat 10–30% of your context window before you even start working.

This fork adds a **boot cost snapshot**: the first time the status line runs in a session, it records the current context usage as your "boot cost." From then on:

- The **progress bar** splits into three zones: dark gray (boot) → gradient (chat) → empty
- A **`(boot N%)`** label appears next to the percentage, in gray

```
◆ Opus 4 │ ██████░░░░ 45% (boot 27%) 1M │ $1.20 │ 10m0s
^^ ^^^^
boot(dark) chat(gradient)
```

The boot snapshot is stored in `/tmp/claude-statusline-boot` and resets with each new session.

## How it works

Claude Code's `statusLine` hook sends a JSON payload to your script via stdin after every assistant response. The JSON contains the full session state — model, tokens, cost, git info, rate limits, etc.
Expand Down
18 changes: 18 additions & 0 deletions README.zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
| **三層渲染退回** | 真彩色 → ANSI → ASCII。任何終端機都能用。 |
| **Nerd Font 支援** | 選配:``, `󰔟`, `` 圖示。設定 `CLAUDE_STATUSLINE_NERDFONT=1`。 |
| **Powerline 分隔符** | 選配:`` 箭頭。設定 `CLAUDE_STATUSLINE_POWERLINE=1`。 |
| **啟動成本指示器** | 顯示你的啟動配置(CLAUDE.md、rules、memory、skills)吃掉多少上下文——在你開口問之前就已經消耗的量。進度條分色:暗灰(啟動)vs 漸層(對話)。 |
| **< 50ms** | 單次 `jq` 呼叫 + Git 快取。無感延遲。 |

## 安裝
Expand Down Expand Up @@ -98,6 +99,23 @@ chmod +x ~/.claude/statusline.sh
export CLAUDE_STATUSLINE_NERDFONT=1 # 啟用 Nerd Font 圖示 + Powerline 箭頭
```

## 啟動成本指示器

大多數使用者不知道自己的啟動配置吃掉了多少上下文。一個大的 `CLAUDE.md`、很多 rules、memory 檔案和 skills,可以在你還沒開始工作之前就燒掉 10–30% 的上下文視窗。

這個 fork 加入了**啟動成本快照**:狀態列在 session 中第一次執行時,會記錄當下的上下文用量作為「啟動成本」。之後:

- **進度條**分為三個區域:暗灰(啟動)→ 漸層(對話)→ 空白
- 百分比旁邊會出現灰色的 **`(boot N%)`** 標籤

```
◆ Opus 4 │ ██████░░░░ 45% (boot 27%) 1M │ $1.20 │ 10m0s
^^ ^^^^
啟動(暗灰) 對話(漸層)
```

啟動快照存在 `/tmp/claude-statusline-boot`,每次新 session 自動重置。

## 運作原理

Claude Code 的 `statusLine` 機制會在每次助理回覆後,把完整的 session 狀態打包成 JSON,透過 stdin 送給你指定的腳本。
Expand Down
49 changes: 40 additions & 9 deletions statusline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,48 +142,79 @@ parsed=$(echo "$input" | jq -r '
model="${model_name:-─}"

# ═══════════════════════════════════════════════════════════════
# 上下文進度條
# 啟動成本快照(Boot Cost Snapshot)
# ═══════════════════════════════════════════════════════════════

BOOT_CACHE="/tmp/claude-statusline-boot"

pct_int=${ctx_pct%.*}
pct_int=${pct_int:-0}
if (( pct_int < 0 )); then pct_int=0; fi
if (( pct_int > 100 )); then pct_int=100; fi

# 第一次執行時鎖定啟動成本
boot_pct=0
if [[ ! -f "$BOOT_CACHE" ]]; then
echo "$pct_int" > "$BOOT_CACHE"
boot_pct=$pct_int
else
boot_pct=$(cat "$BOOT_CACHE" 2>/dev/null)
boot_pct=${boot_pct:-0}
fi

# ═══════════════════════════════════════════════════════════════
# 上下文進度條(含啟動成本分色)
# ═══════════════════════════════════════════════════════════════

bar_filled=$(( pct_int / 10 ))
if (( bar_filled > 10 )); then bar_filled=10; fi

boot_filled=$(( boot_pct / 10 ))
if (( boot_filled > 10 )); then boot_filled=10; fi

# 漸層色(真彩色):綠 → 黃 → 橘 → 紅
GRAD_R=(46 116 186 241 239 236 233 231 211 192)
GRAD_G=(204 195 186 196 161 126 101 76 66 57)
GRAD_B=(113 89 64 15 24 34 44 60 50 43)

# 進度條三態:boot(暗灰█) → chat(漸層█) → 空(暗灰░)
bar=""
if [[ "$USE_ASCII" == "1" ]]; then
# ASCII 模式
for (( i=0; i<10; i++ )); do
if (( i < bar_filled )); then bar+="#"; else bar+="-"; fi
if (( i < boot_filled )); then bar+="="
elif (( i < bar_filled )); then bar+="#"
else bar+="-"; fi
done
elif (( USE_TRUECOLOR )); then
# 真彩色漸層:每格獨立上色
for (( i=0; i<10; i++ )); do
if (( i < bar_filled )); then
if (( i < boot_filled )); then
# boot 區:暗灰實心,表示「已被吃掉,回不來」
bar+="\\033[38;2;80;80;80m█"
elif (( i < bar_filled )); then
# chat 區:原版漸層色
bar+="\\033[38;2;${GRAD_R[$i]};${GRAD_G[$i]};${GRAD_B[$i]}m█"
else
# 空區:暗灰空心
bar+="\\033[38;2;60;60;60m░"
fi
done
bar+="${RST}"
else
# ANSI 退回:依整體百分比選色
if (( pct_int >= 90 )); then bar_color="$RED"
elif (( pct_int >= 70 )); then bar_color="$YELLOW"
else bar_color="$GREEN"; fi

for (( i=0; i<10; i++ )); do
if (( i < bar_filled )); then bar+="█"; else bar+="░"; fi
if (( i < boot_filled )); then bar+="${GRAY}█${RST}"
elif (( i < bar_filled )); then bar+="${bar_color}█${RST}"
else bar+="░"; fi
done
bar="${bar_color}${bar}${RST}"
fi

# boot 標籤(灰色小字,持續提醒)
boot_label=""
if (( boot_pct > 0 )); then
boot_label=" ${GRAY}(boot ${boot_pct}%)${RST}"
fi

# 百分比文字顏色(跟進度條整體色一致)
Expand Down Expand Up @@ -324,7 +355,7 @@ else prompt_color="$GREEN"; fi
# ═══════════════════════════════════════════════════════════════

line1="${PURPLE}${S_BRAND}${RST} ${CYAN}${model}${RST}"
line1+="${SEP}${bar} ${pct_color}${pct_int}%${RST}${ctx_warn}${ctx_label}"
line1+="${SEP}${bar} ${pct_color}${pct_int}%${RST}${boot_label}${ctx_warn}${ctx_label}"
line1+="${SEP}${cost_color}${S_COST}\$${cost_fmt}${RST}"
line1+="${dur_section}"
line1+="${rate_section}"
Expand Down