ClaudeMods
☰
ZH-CN
● 0 人在线 · 浏览 0 次
赞助提交作品
GitHub 仓库 · 发布者 oaustegard

usage-dollars

一个 Claude Code 插件,将每个工作阶段的费用记入每日账本,在状态栏中显示今天和本月至今的支出与月度预算对比,并在 80%/100% 时显示提示消息,另提供 /spend 命令。

oaustegard@oaustegard

oaustegard/claude-code-mods/tree/main/usage-dollars

已翻译

关于这个 mod

usage-dollars 是一个用美元追踪支出的 Claude Code 插件。每个工作阶段的费用($.session.usage().cost.usd,即 /cost 汇总的金额)都会记入插件存储中的每日账本,供这台机器上的所有工作阶段共用。状态栏会显示类似「$1.20 today · $34.10/$100.00 month (34%)」的内容,预算达到 80% 和 100% 时各显示一次提示消息,/spend 会打印相同的数字以及剩余金额。每段对话的支出仍由默认的甜甜圈图按钮处理。预算可在配置菜单中通过 monthlyBudgetUsd 设置(默认值为 100,设为 0 可隐藏)。账本从首次加载此 mod 时开始,因此不会计入更早的支出,也不会重新记入恢复工作阶段过去已经产生的费用。它以 mod 资料夹形式提供,其中包含 .claude-plugin/plugin.json、用于命名模块的 hooks/hooks.json,以及模块本身(hooks/register.ts、hooks/ledger.ts)。在 ~/.claude/settings.json 的 env 区块中通过 CLAUDE_CODE_PLUGIN_DIRS 列出该资料夹即可启用(只从使用者设定读取),并使用 claude plugin validate 验证变更。请注意,勾点 API 标记为早期访问 API,不同版本之间可能变更。

安装

请先查看作者 README 确认 marketplace 和插件名称;命令可能随仓库结构改变。

claude plugin marketplace add oaustegard/claude-code-mods
claude plugin install usage-dollars
原文 / README

claude-code-mods

Plugins for Claude Code that run code around the agent's tool calls: they can block a call before it runs, add a note to its result, or put a message in front of the person. They work in the terminal and in the desktop app's Code tab. Each folder is one plugin.

| Mod | What it does | |---|---| | tripwire | Blocks or annotates shell mistakes that recur in Claude Code sessions: whole-disk find, long foreground sleep loops, errors hidden by \| tail, forgotten background shells | | usage-dollars | Spend in dollars for today and the month so far against a monthly budget: status line, toast at 80% and 100%, /spend |

The hook API these mods use is marked early access in Claude Code's own type declarations and can change between releases. Those declarations were written by Claude Code 2.1.286, the version tripwire was developed against.

Layout

A mod folder holds .claude-plugin/plugin.json, hooks/hooks.json naming one module, the module itself, and types/index.d.ts when the mod keeps state. Claude Code generates .claude-plugin/types/ the first time it loads a mod, so that directory is not in the repo.

Enabling

List each mod folder, :-separated, in the env block of ~/.claude/settings.json. Claude Code reads this variable only from user settings, never from a project's:

"env": { "CLAUDE_CODE_PLUGIN_DIRS": "/path/to/claude-code-mods/tripwire" }

Interactive sessions watch the folder and reload on save. To check a change before committing it:

claude plugin validate tripwire

tripwire

Tripwire was built from 17 local session transcripts: 546 Bash calls. Each rule below answers a mistake that appears in them more than once. A rule can block a call before it runs, add a note the model reads after the result, or show the person a toast or a status line.

| Rule | Kind | Evidence (replayed on the transcripts) | |---|---|---| | find over /, ~, $HOME or /Users/<name> with no -maxdepth | block | 5 calls, each moved to the background automatically and left running past the end of the task | | foreground loop whose sleep totals more than 120s (an unbounded while/until with sleep ≥ 5 counts; timeout N caps the total) | block | 35 calls; the person's reaction to one: "what on earth is taking so long?" | | error text in output whose pipeline ends in tail/head and exits 0 | note | 20 of 233 such calls | | zsh glob abort, macOS has no timeout, gh pr create without --head, gh pr view --json merged | note | one fix line each | | background shells still open | status line, plus a toast at turn end | "what are the 5 shells that are open still doing?" | | foreground call running longer than 5 minutes | status line, then a toast | a 51-minute foreground Agent call |

The replay applies the same patterns the rules use to the Bash calls in those transcripts. The counts describe one person's sessions, so another machine will see different numbers.

# tripwire:allow in a command lets a block through when the person asked for exactly that. /tripwire lists the counts for the current session and for all sessions (kept in the plugin store) and the open background tasks. The counts show whether a rule still fires, and a rule that never trips is a candidate for deletion.

usage-dollars

Books each session's cost ($.session.usage().cost.usd, what /cost totals) into a per-day ledger in the plugin store, shared by every session on the machine. The status line shows $1.20 today · $34.10/$100.00 month (34%), a toast fires once at 80% and once at 100% of the budget, and /spend prints the same figures plus what remains. Per-conversation spend is not shown: the default donut chart button covers it.

Set the budget in the config menu (monthlyBudgetUsd, default 100, 0 hides it). The ledger starts when the mod is first loaded, so earlier spend is not counted, and a resumed session's past cost is not re-booked.

更多类似作品