cjmellor/mella-marketplace/tree/main/plugins/session-stats
关于这个 mod
一个 Claude Code mod,让模型、上下文占用和速率限制用量一直可见,这样你可以把它们交给 statusline 脚本显示。
Mods 会在你的计算机上于 Claude Code 内运行代码。安装前先阅读源代码——这个 mod 只有一个文件
hooks/register.tsx,而且只读取当前工作阶层自己的数字。它不会运行 shell 命令,也不会发出网络请求。
状态栏
显示在提示列上方:
Sonnet 5.5 ◼◼◼◼◼ 12% 5h 8% (34m) W 13% (4d 2h) +
- 模型名称与
/model显示的相同,后面是推理 effort 图标:○低、◐中、●高、◉xhigh、◈max(如果 effort 是 token 预算,则显示数字)。/model切换会立即显示,并在新模型的第一回合前清除 effort 图标;在其他地方进行的切换(Alt+P 选择器、回退、IDE)会从下一回合开始显示。Effort 从每次请求读取,因此会在第一回合后出现;/effort <level>会立即显示,而从菜单选择的等级会在下一回合开始显示。没有 effort 设置的模型不会显示图标。 - 上下文窗口的五格状态栏和百分比。
- 每个速率限制窗口(
5h、W)的百分比,以及距离重置的时间。窗口在第一次响应报告这些数据后才出现,而且只对订阅用户显示。 - 状态栏和百分比为绿色,达到 60% 时变黄,达到 85% 时变红。
- 右侧按钮在面板关闭时显示
+,打开时显示−。按下即可打开或关闭面板。
调查显示时状态栏会隐藏。
面板
按 + 按钮或执行 /session-stats 打开。
- 模型、上下文占用以及每个速率限制窗口都会显示为 20 格状态栏,并带有重置倒计时。会话(
5h)和每周窗口显示为Session limit和Weekly · all models;引擎报告的按模型每周窗口(例如 Fable)显示为Weekly · <model>,状态栏中显示为W <model>。 - 本会话: 成本、回合时间、缓存命中率,以及每个模型占用的 token 比例。
- 拆解: 输入、输出、缓存读取和缓存写入 token。
- 上下文窗口: 按类别显示(系统提示、工具、消息、可用空间),按估算大小从大到小排列。
会话数据统计的是 mod 加载后完成的回合。重新加载会保留数据,/clear 不会重置数据;"Turns" 是已完成回合的墙钟时间,不是 API 自己的时间。
按 r 刷新。按 Esc 把键盘交还给提示列并关闭面板。
即时性
引擎会在每个回合后推送数据,并在速率限制窗口移动整个百分点时推送;/model 和 /effort 之后也会立即刷新。重置倒计时每分钟跳动一次。
安装
/plugin marketplace add cjmellor/mella-marketplace
/plugin install session-stats@mella-marketplace
/reload-plugins
不安装也可以从检出目录试用:
claude --plugin-dir plugins/session-stats
开发
claude plugin validate plugins/session-stats
claude plugin test plugins/session-stats
validate 不会检查状态栏绘制的内容:无效的渲染树会被引擎丢弃,状态栏就不会出现。如果编辑后它消失了,请用 --debug 运行 Claude Code,并查找 ui.render (AbovePrompt): a hook returned a tree that does not validate 这一行。
限制
- 它不能在 status line 中绘制,也不能隐藏 status line。保留你的
statusline来显示目录、分支和 PR,或把这些内容交给另一个 mod。 - 只能有一个钩子绘制状态栏。这个 mod 会向下询问钩子取得它们的树,再把自己的行叠加在上面,所以只有在它先加载时才能与
git-diff组合。一个不先询问就绘制的 mod 会取代它。 - Mods 不会收到模型或 effort 变更事件,只会收到
/model和/effort命令事件。对于当前模型拒绝或降低等级的/effort,在下一回合纠正前仍会按输入内容显示。 - 面板打开时取得的是快照(按
r刷新)。 - 热重载 mod 会关闭已打开的面板。
- 终端会把指针下的按钮绘制成反色区块。这来自引擎,无法设置样式。
安装
请先查看作者 README 确认 marketplace 和插件名称;命令可能随仓库结构改变。
claude plugin marketplace add cjmellor/mella-marketplace claude plugin install session-stats
原文 / README
session-stats
A Claude Code mod that keeps the model, context fill and rate-limit usage in
view, so you can drop a statusline script for them.
Mods run code inside Claude Code on your machine. Read the source before you install one — this one is a single file,
hooks/register.tsx, and only reads the session's own figures. It runs no shell commands and makes no network calls.
The band
Shown above the prompt:
Sonnet 5.5 ◼◼◼◼◼ 12% 5h 8% (34m) W 13% (4d 2h) +
- The model, as
/modelshows it, then an icon for the reasoning effort:○low,◐medium,●high,◉xhigh,◈max (a number if the effort is a token budget). A/modelswitch shows at once and clears the effort icon until the new model's first turn; one made elsewhere (the Alt+P picker, a fallback, the IDE) shows from the next turn. The effort is read from each request, so it appears after the first turn;/effort <level>shows at once, while a level picked from a menu shows from the next turn. Models without an effort setting show no icon. - A five-square bar and percentage for the context window.
- Each rate-limit window (
5h,W) with its percentage and the time until it resets. Windows appear once the first response has reported them, and only on a subscription. - Bars and percentages are green, turn yellow at 60% and red at 85%.
- The button on the right shows
+while the pane is closed and−while it is open. Press it to open or close the pane.
The band is hidden while a survey is up.
The pane
Open it with the + button or /session-stats.
- The model, context fill and each rate-limit window as a 20-square bar, with
reset countdowns. Session (
5h) and weekly windows show asSession limitandWeekly · all models; a per-model weekly window the engine reports, such as Fable, shows asWeekly · <model>, and asW <model>in the band. - This session: cost, turn time, cache hit and each model's share of tokens.
- Breakdown: input, output, cache read and cache write tokens.
- Context window: by category (system prompt, tools, messages, free space), largest first, estimated locally.
The session figures add up the turns finished since the mod loaded. A reload
keeps them, /clear does not reset them, and "Turns" is the wall-clock time
of finished turns, not the API's own time.
r refreshes. Esc hands the keyboard back and closes the pane.
Freshness
The figures are pushed by the engine after each turn and whenever a rate-limit
window moves a whole point, and refreshed straight after /model and /effort.
Reset countdowns tick once a minute.
Install
/plugin marketplace add cjmellor/mella-marketplace
/plugin install session-stats@mella-marketplace
/reload-plugins
To try it from a checkout without installing:
claude --plugin-dir plugins/session-stats
Develop
claude plugin validate plugins/session-stats
claude plugin test plugins/session-stats
validate does not check what the band draws: an invalid render tree is dropped
by the engine and the band simply does not appear. If it goes missing after an
edit, run Claude Code with --debug and look for a ui.render (AbovePrompt): a hook returned a tree that does not validate line.
Limits
- It cannot draw in the status line or hide it. Keep your
statuslinefor the directory, branch and PR, or move those into another mod. - Only one hook can draw the band. This mod asks the hooks beneath it for their
tree and stacks its own row on top, so it composes with
git-diffonly when it loads first. A mod that draws without asking replaces this one. - Mods get no event for a model or effort change, only for the
/modeland/effortcommands. A level/effortrefuses or lowers for the model still shows as typed until the next turn corrects it. - The pane is a snapshot taken when it opens (press
rto refresh). - A hot reload of the mod closes an open pane.
- The terminal draws a button under the pointer as an inverted block. That comes from the engine and cannot be styled.
