0
1,287
近 7 天 81
39.0
生态多维模型
8 天前
2026-09-26
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-total-session-cost@1.4.0"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-total-session-cost@1.4.0"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D opencode-total-session-costOpenCode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
A real-time, lightweight plugin for Opencode that tracks and displays the actual cumulative cost of your active session, including all background tasks, sub-agents, and child sessions.
Why this plugin?
By default, Opencode only displays the cost of your active main session. However, any background tasks or specialized sub-agents (like explore, coder, or custom test executors) invoked during your conversation run in their own child sub-sessions, keeping their costs hidden.
Without tracking these sub-sessions, you might see a main session cost of a few cents, while the background agents have spent significantly more.
This plugin solves that. It automatically aggregates the costs of your main session and all its nested child tasks, displaying your real, total spending in real-time directly inside the main session.
Features
- Sidebar-Independent: The cost indicator stays visible even when the Opencode sidebar is closed.
- Recursive Sub-Agent Tracking: Automatically detects and sums up the costs of all child tasks spawned during your session.
- Detailed Cost Breakdown: Offers a
/total_costslash command to show a detailed popup separating your active session cost from child task and sub-agent costs. - Session List Cost View: Offers a
/sessions_costcommand that opens a dialog with the sessions of the last 7 days grouped by day, showing the total cost (including sub-agents) of each session and of each day. - Provider & Model Breakdown: Displays the exact costs accumulated per model across all session hierarchy levels.
- Mouse Click Interaction: Left-clicking on the cost bar in the prompt header right panel triggers the same detailed breakdown popup, while right-clicking opens the session costs list.
Installation
Install it globally with:
opencode plugin opencode-total-session-cost -g
Cost categories
The breakdown separates costs into three buckets:
- Session: the cost of the active/root session.
- Task: child sessions spawned through the Task tool by the
exploreandgeneralagents. - Sub-agent: any other child session.
Example /total_cost output:
By session
Session: $0.12
Task: $0.34
Sub-agent: $0.08
---------------
Total: $0.54
By provider/model
anthropic/claude-sonnet-4: $0.40
openai/gpt-5: $0.14
------------------------------
Total: $0.54
Cost that cannot be tied to a model (for example spend recorded in the session
total without a matching step or message) is reported as unknown/unknown
instead of being guessed onto the currently selected model.
Session list costs
Run /sessions_cost (or /session_costs) to open a centered, read-only dialog with
the sessions of the last 7 days grouped by day. Each day header shows the total of its
sessions and each session row shows its recursive total (session plus every child
sub-session). Use the up/down arrows or mouse click to select a session and
enter (or click) to display its detailed cost breakdown popup; esc closes the dialog.
Session Costs last 7 days
Today $0.54
Refactor the parser $0.41
Add integration tests $0.13
Wed Sep 16 2026 $0.22
Fix flaky test $0.22
How it works
The plugin runs inside Opencode's TUI framework, recursively fetching session data:
- It reads the core cost of your active session.
- It recursively queries all child sub-sessions spawned by sub-agents.
- It displays the combined sum dynamically in the TUI.
Development
npm install
npm run typecheck
npm test
License
MIT
同类生态推荐
Cache Hit
opencode-cache-hit
OpenCode TUI sidebar: prompt cache hit rate, tokens & cost with sub-agent rollup. Works with opencode-visual-cache; optional per-call JSONL timeline.
Subagent Usage
opencode-subagent-usage
opencode TUI sidebar widget showing the rolled-up cost and token usage of subagent (child) sessions.
Usage Panel
opencode-usage-panel
Sidebar token-usage and cost panel for the opencode TUI. Breaks a session down by model with per-model cost, context usage, and configurable peak/off-peak pricing.