ClaudeMods
☰
ZH-TW
● 0 人在線上 · 瀏覽 0 次
贊助提交作品
GitHub 儲存庫 · 發布者 myUdav4iik

context-bar

Claude Code 外掛,在提示框上方的區域繪製即時工作階段視窗拆解列,顯示分類用量、壓縮閾值指示器與速率限制視窗,可用 /context-bar 切換。

myUdav4iik@myUdav4iik

myUdav4iik/claude-mods/tree/main/context-bar

原貼文圖片1
已翻譯

關於這個 mod

context-bar 是一個 Claude Code mod,在提示框上方的區域即時繪製工作階段視窗拆解。標頭會顯示目前使用中的視窗占比彩色徽章(低於 50% 為綠色、低於 80% 為黃色、超過則為紅色)、已使用的 token、視窗大小,以及自動壓縮執行的位置。長條會依每個分類所占的比例顯示一個區段,後面接著可用空間軌道;圖例會列出每個分類及其 token 數,顏色與 /context 使用的顏色一致。可選的用量列會顯示方案的速率限制視窗(5h、7d 或閘道消費上限)、已使用占比與重設倒數,只會在訂閱方案中出現。它可用 /context-bar、/context-bar on 與 /context-bar off 切換,選擇會跨工作階段保留。使用的掛鉤包括:session.start(註冊、還原狀態、首次讀取、倒數計時器)、turn.complete(每次主要對話回合後讀取,跳過子代理)、session.compact(壓縮後讀取)、session.measure(在回合之間更新用量),以及 AbovePrompt 上的 ui.render(繪製區域,為問卷讓出位置)。資料來自 $.session.usage({ breakdown: 'summary' }),在本機估算,不會傳送請求。長條使用 flex box,因此會按精確比例切分且永不換行;終端機中用暗淡的線條繪製可用空間,桌面應用程式中用深色填滿。已知限制包括分類數值是估算值、每回合只更新一次、下次 API 回應前用量百分比可能過時、首次讀取前顯示佔位符,以及與其他 mod 共用這個區域。測試位於 tests/bar.test.tsx,可執行 claude plugin test 。

安裝

請先查看作者 README,確認 marketplace 與外掛名稱;指令可能隨儲存庫結構而變動。

claude plugin marketplace add myUdav4iik/claude-mods
claude plugin install context-bar
原文 / README

context-bar

A live breakdown of the context window, drawn in the band above Claude Code's prompt.

In the terminal:

context-bar in the terminal: a context header at 18%, the category bar, its legend, and a usage row with 5h and 7d limits

In the desktop app:

context-bar in the Claude desktop app: a context header at 35%, the category bar on a dark free-space fill, and its legend

  • Header: the share of the window in use, as a badge that is green under 50%, yellow under 80% and red above. Then the tokens in use, the window size, and the point where auto-compaction runs.
  • Bar: one segment per category, in proportion to its share of the window, followed by a track for the free space.
  • Legend: each category with its token count, in the colours /context uses.
  • Usage: your plan's rate-limit windows (5h, 7d, or a gateway's spend limit), each with the share used, coloured like the context badge, and a countdown to when it resets. The row only appears on a subscription, where Claude Code receives these figures.

Usage

| Command | Does | | --- | --- | | /context-bar | Shows or hides the bar | | /context-bar on | Shows the bar | | /context-bar off | Hides the bar |

The command runs at once, even while Claude is working. The choice is remembered across sessions. Claude Code's own [-] control on the band collapses it as well.

How it works

| Hook | What it does | | --- | --- | | session.start | Registers /context-bar, restores the saved on/off choice, takes a first reading, and starts a once-a-minute timer for the reset countdowns. | | turn.complete | Takes a reading after each turn of the main conversation. Subagent turns are skipped. | | session.compact | Takes a reading after the conversation is compacted. | | session.measure | Updates the usage row when a rate-limit window moves, between turns too. | | ui.render on AbovePrompt | Draws the band. It steps aside while Claude Code shows a survey there. |

Readings come from $.session.usage({ breakdown: 'summary' }), the same per-category breakdown /context shows. The summary mode estimates locally, so a reading sends no requests and costs nothing. The same call returns the rate-limit windows from the last API response; the usage row shows those, so it sends no requests either.

The bar is built from flex boxes, each growing by its share of the window, so it splits in exact proportion at any width and never wraps. Small categories still get at least one cell. Free space is drawn differently per surface:

  • Terminal: a dim line, because Claude Code's colour for free space there is bright enough to read as used.
  • Desktop app: a dark fill. The desktop wraps long runs of text rather than clipping them, so a line of characters doesn't work there.

The compaction reserve is drawn as part of the free track; the header shows where compaction runs.

Limitations

  • Estimates: the category figures are estimates, as in /context, so the total can differ slightly from the status line.
  • Once per turn: the bar updates after each turn, not while Claude is working.
  • Usage after a reset: the percentages come from the last API response. Once a window's reset time passes, the row shows "resetting" until the next response brings a new figure.
  • Before the first reply: the bar shows "waiting for the first reading…".
  • Shared band: the band above the prompt holds one mod at a time. If another installed mod draws there, only one of them shows.

Tests

tests/bar.test.tsx feeds the mod a sample breakdown, draws the band on the terminal and desktop surfaces, and fails if either surface refuses the drawing. Claude Code drops a drawing it can't validate without an error you'd see, so run the tests after changing how the bar is drawn:

claude plugin test .

其他同名作品

更多類似作品