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

cost-info

一個 Claude Code 外掛,會即時顯示目前工作階段截至目前的費用與消耗的 token。

已翻譯

關於這個 mod

Cost Info

一個 Claude Code 外掛,會即時顯示目前工作階段截至目前的費用與消耗的 token。

Cost Info 位於 Claude Code 提示列下方那一行的右側:◉ 5h ━─── 15%  wk ━─── 7%  Resets in 3h 55m | Token Usage 104k / 70k

  • 提示列下方。 提示列下方那一行的右側會即時顯示 ◉ $0.16 | Token Usage 142k / 30k | now $0.02,數字以綠色顯示,回合進行中也會更新;回合結束後,now 會變成 last。終端機窄於 120 欄時只顯示工作階段本身。這個費用數字與 /cost 顯示的相同,也包含子代理。
  • Token。 加總每次模型請求的輸入、快取寫入、快取讀取與輸出,也包含子代理。
  • 預算。 工作階段跨過預算時只警告一次。
  • /spend。 顯示 token、回合數、每回合平均值、費用最高的回合,以及預算已使用多少。
  • VS Code。 擴充功能不會繪製那一行,因此會在其中開啟 Cost 窗格。關閉後執行 /spend 即可叫回來。

在 Pro 或 Max 方案中,美元數不是你實際被收取的金額;所以 Claude Code 回報速率限制時,計量器會改為顯示各項已使用多少:◉ 5h ━─── 15% wk ━─── 7% Resets in 3h 55m | Token Usage 104k / 70k。它用細刻度顯示 5 小時與每週視窗,以及較早重設的那個視窗還剩多久。它讀取 Claude Code 已經收到的資料,因此不會增加額外費用。沒有速率限制(API 計費)時,會像之前一樣顯示費用。Token 從外掛載入工作階段時開始計算,因此恢復工作階段先前的 token 不會算進總數。

安裝

需要 Claude Code 2.1.288 或更新版本。請在 shell 中執行,不要在 Claude Code 工作階段內執行:

claude plugin marketplace add falconsw/cost-info
claude plugin install cost-info@falconsw-mods

接著將它載入已開啟的 Claude Code 工作階段:

/reload-plugins

也可以在終端機或 VS Code 中啟動新的工作階段。

要取得新版本,執行 claude plugin update cost-info@falconsw-mods,再執行 /reload-plugins。如果顯示已是最新版本,先執行 claude plugin marketplace update falconsw-mods。要移除它,執行 claude plugin uninstall cost-info@falconsw-mods。

設定

除非另行設定,預算是 $5;設為 0 可關閉。請從 shell 設定,寫入的值要是字串,然後重新啟動 Claude Code:

echo '{"budget": "10"}' | claude plugin configure cost-info@falconsw-mods --values-stdin

也可以在安裝時設定:

claude plugin install cost-info@falconsw-mods --config budget=10

claude plugin configure cost-info@falconsw-mods 會顯示是否已設定。

開發

claude plugin validate ./cost-info
claude plugin test ./cost-info
claude --plugin-dir ./cost-info   # reloads as you save

外掛在 Claude Code 內執行,擁有與 Claude Code 相同的存取權限。安裝前請先閱讀原始碼:它只有一個檔案,也就是 cost-info/hooks/register.tsx。

安裝

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

claude plugin marketplace add falconsw/cost-info
claude plugin install cost-info
原文 / README

Cost Info

A Claude Code mod that shows what your session has cost so far, and the tokens it took, live.

Cost Info at the right of the line under the Claude Code prompt: ◉ 5h ━─── 15%  wk ━─── 7%  Resets in 3h 55m | Token Usage 104k / 70k

  • Under the prompt. ◉ $0.16 | Token Usage 142k / 30k | now $0.02 at the right of the line under the prompt, the figures in green, live, mid-turn too; once the turn ends now becomes last. A narrow terminal (under 120 columns) shows the session alone. The cost is the same figure /cost shows, subagents included.
  • Tokens. Every model request's input, cache writes, cache reads and output, summed, subagents included.
  • Budget. A one-time warning when the session crosses it.
  • /spend. Tokens, turns, average per turn, your priciest turn, and how much of the budget is used.
  • VS Code. The extension doesn't draw that line, so there the meter opens as a Cost pane. Run /spend to bring it back if you close it.

On a Pro or Max plan the dollars aren't what you're billed, so when Claude Code reports rate limits the meter shows how much of each is used instead: ◉ 5h ━─── 15% wk ━─── 7% Resets in 3h 55m | Token Usage 104k / 70k: a thin gauge for the 5-hour and weekly windows, and the time until the sooner one resets. It reads what Claude Code already receives, so it costs nothing extra. Without rate limits (API billing) it shows cost as before. Tokens count from when the mod loaded into the session, so a resumed session's earlier tokens aren't in the total.

Install

Requires Claude Code 2.1.288 or later. Run these in a shell, not inside a Claude Code session:

claude plugin marketplace add falconsw/cost-info
claude plugin install cost-info@falconsw-mods

Then load it into your open Claude Code session:

/reload-plugins

Or start a new session, in the terminal or in VS Code.

To get a new version, run claude plugin update cost-info@falconsw-mods, then /reload-plugins. If it says it's already at the latest version, run claude plugin marketplace update falconsw-mods first. To remove it, run claude plugin uninstall cost-info@falconsw-mods.

Configure

The budget is $5 unless you set it; 0 turns it off. Set it from a shell, the value written as a string, then restart Claude Code:

echo '{"budget": "10"}' | claude plugin configure cost-info@falconsw-mods --values-stdin

Or set it while installing:

claude plugin install cost-info@falconsw-mods --config budget=10

claude plugin configure cost-info@falconsw-mods shows whether it's set.

Develop

claude plugin validate ./cost-info
claude plugin test ./cost-info
claude --plugin-dir ./cost-info   # reloads as you save

A mod runs inside Claude Code with the same access Claude Code has. Read the source before you install it: it's one file, cost-info/hooks/register.tsx.

更多類似作品