Total Session Cost
Real-time cumulative cost tracker for Opencode sessions, aggregating costs from parent sessions, archived messages, and all child sub-agent tasks.
0
1,287
81 in 7 days
39.0
Multi-signal model
8 days ago
2026-09-26
Install and configure
opencode.jsonWrites to this project's opencode.json — applies to this repository only.
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-total-session-cost@1.4.0"]
}Writes to ~/.config/opencode/opencode.json — applies to every project.
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-total-session-cost@1.4.0"]
}If you want to modify the plugin locally, install it into the project and reference the local path.
shell
pnpm add -D opencode-total-session-costOpenCode loads npm dependencies through its embedded runtime on startup and caches them locally — no manual global install needed.
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
Similar plugins
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.