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.
