ClaudeMods
☰
ZH-CN
● 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 .

其他同名作品

更多类似作品