anthonybaldwin/cc-plugins/tree/main/plugins/context-bar
context-bar
一個 [外掛](https://code.claude.com/docs/en/plugins/mods/overview),會把工作階段的上下文視窗畫成提示列上方帶狀區域中的堆疊列——每個類別一種顏色,就像 `/context` 的拆解結果——下方附有圖例。
關於這個 mod
一個 外掛,會把工作階段的上下文視窗畫成提示列上方帶狀區域中的堆疊列——每個類別一種顏色,就像 /context 的拆解結果——下方附有圖例:
████████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
40% System prompt 3% System tools 7% Messages 30% Autocompact buffer 10% Free space 50%
(每一段都使用所屬類別的主題色繪製——與 /context 使用的顏色相同——實心的 █ 代表已使用空間,▒ 代表壓縮緩衝區,░ 代表可用空間。)
它是即時的:Claude Code 在每個回合後推送一次測量結果,列會據此重繪。不需要輪詢、計時器,也不會請求 token 計數(這裡的拆解來自本機的 summary 估算,也就是 /context 的起始資料)。
安裝
/plugin marketplace add anthonybaldwin/cc-plugins
/plugin install context-bar@cc-plugins
需要 Claude Code v2.1.287+(mods)。它會在終端與 Desktop 應用程式的 Code 分頁中繪製;在 VS Code 聊天面板與 claude -p 中,掛鉤會執行,但不會繪製任何內容。
使用方式
| | |
|---|---|
| /context-bar | 切換堆疊列。選擇會跨工作階段保留,中途也能使用。 |
| ctrl+x ctrl+a | Claude Code 自己提供的摺疊功能,用於提示列上方的帶狀區域。 |
這個帶狀區域與其他外掛及 Claude Code 的問卷共用;問卷顯示時優先顯示問卷。
為什麼做成外掛,而不是放在 statusline-dashboard 的一列
狀態列只能收到視窗的總量。每個類別的拆解是 mods API 呼叫($.session.usage({ breakdown })),而提示列上方的帶狀區域是外掛唯一能繪製多列、套用主題色,並在推送時更新的元件位置。因此,狀態列保留上下文儀表,這個外掛則是旁邊的詳細檢視。兩者互相獨立——可以只安裝其中一個,也可以兩個都安裝。
運作方式
hooks/register.ts:
session.start註冊/context-bar,從$.store還原已儲存的切換狀態,並進行第一次測量。session.measure(每次主執行緒回合後觸發)會在上下文單位變動時重新讀取$.session.usage({ breakdown: 'summary' }),並把快照寫入$.state。寫入狀態會重繪帶狀區域——繪製掛鉤會訂閱它。classic.SessionStart會在clear/resume/fork/compact時再次測量並還原切換狀態(這些操作會重設$.state)。ui.render在AbovePrompt上使用最大餘數捨入,將類別排在bodyColumns個儲存格中(讓堆疊列永遠正好填滿帶狀區域寬度,也讓每個非空類別都能顯示),跳過類似/context網格中的延後工具列,並在寬度允許時盡量放入圖例項目。
測試(claude plugin test plugins/context-bar)涵蓋版面配置算術、在兩種介面上的繪製、透過 $.store 往返保存切換狀態、/clear 路徑,以及問卷優先順序。
安裝
請先查看作者 README,確認 marketplace 與外掛名稱;指令可能隨儲存庫結構而變動。
claude plugin marketplace add anthonybaldwin/cc-plugins claude plugin install context-bar
原文 / README
Context Bar
A mod that draws your context window as a stacked bar in the band above the prompt — one color per category, as /context breaks it down — with a legend underneath:
████████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
40% System prompt 3% System tools 7% Messages 30% Autocompact buffer 10% Free space 50%
(Each run is drawn in its category's theme color — the same colors /context uses — solid █ for what's in use, ▒ for the compaction buffer, ░ for free space.)
It's live: Claude Code pushes a measurement after every turn, and the bar redraws from it. No polling, no timer, no token-count requests (the breakdown is the local summary estimate, the one /context starts from).
Install
/plugin marketplace add anthonybaldwin/cc-plugins
/plugin install context-bar@cc-plugins
Requires Claude Code v2.1.287+ (mods). It draws in the terminal and in the Desktop app's Code tab; in the VS Code chat panel and claude -p the hooks run but nothing is drawn.
Use
| | |
|---|---|
| /context-bar | Toggle the bar. The choice is remembered across sessions. Works mid-turn. |
| ctrl+x ctrl+a | Claude Code's own collapse for the band above the prompt. |
The band is shared with other mods and with Claude Code's surveys; a survey takes precedence while it's up.
Why a mod, and why not a row in statusline-dashboard
The status line receives only the window's total. The per-category breakdown is a mods-API call ($.session.usage({ breakdown })), and the band above the prompt is the one place a plugin can draw a multi-row, theme-colored widget that updates on push. So the status line keeps its context gauge, and this is the detail view beside it. The two are independent — install either or both.
How it works
hooks/register.ts:
session.startregisters/context-bar, restores the saved toggle from$.store, and takes a first measurement.session.measure(fired after each main-thread turn) re-reads$.session.usage({ breakdown: 'summary' })whenever the context unit moved, and writes the snapshot into$.state. Writing the state redraws the band — the render hook subscribes to it.classic.SessionStartforclear/resume/fork/compactmeasures again and restores the toggle (those reset$.state).ui.renderonAbovePromptlays the categories out acrossbodyColumnscells with largest-remainder rounding (so the bar is always exactly the band's width and every non-empty category stays visible), skips deferred tool rows like/context's grid does, and fits as many legend entries as the width allows.
Tests (claude plugin test plugins/context-bar) cover the layout arithmetic, drawing on both surfaces, the toggle round-trip through $.store, the /clear path, and the survey precedence.
其他同名作品
- context-barrodbegbie · ★ 0
- context-barziedgithub · ★ 0
- context-barvrnrn · ★ 0
- context-barAkash001uts · ★ 0
- context-barBoom-Vitt · ★ 0
- context-barmyUdav4iik · ★ 0
