anthonybaldwin/cc-plugins/tree/main/plugins/context-bar
context-bar
一个 [mod](https://code.claude.com/docs/en/plugins/mods/overview),会把上下文窗口绘制成提示列上方带状区域中的堆叠条——每个类别使用一种颜色,就像 `/context` 的分解结果一样——下方还会显示图例。
关于这个 mod
一个 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 自带的折叠操作,用于提示列上方的带状区域。 |
这个带状区域与其他 mod 以及 Claude Code 的调查共用;调查显示时优先显示调查。
为什么做成 mod,而不是放进 statusline-dashboard 的一行
状态行只能收到窗口的总量。每个类别的分解是 mods API 调用($.session.usage({ breakdown })),而提示列上方的带状区域是插件唯一能绘制多行、带主题颜色并在推送时更新的组件位置。因此,状态行保留上下文仪表盘,这个 mod 则作为旁边的详情视图。两者相互独立——可以只安装其中一个,也可以同时安装。
工作原理
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
