No description
  • TypeScript 60.2%
  • JavaScript 39.8%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-06-26 08:01:07 +02:00
src Initial commit 2026-06-24 09:41:46 +02:00
test Initial commit 2026-06-24 09:41:46 +02:00
.gitignore Initial commit 2026-06-24 09:41:46 +02:00
LICENSE Initial commit 2026-06-24 09:41:46 +02:00
package-lock.json Initial commit 2026-06-24 09:41:46 +02:00
package.json Initial commit 2026-06-24 09:41:46 +02:00
README.md Initial commit 2026-06-24 09:41:46 +02:00
renovate.json renovate.json hinzugefügt 2026-06-26 08:01:07 +02:00
tsconfig.json Initial commit 2026-06-24 09:41:46 +02:00

opencode-costs

Cost reporter for OpenCode — detailed cost breakdown per agent and sub-agent.

OpenCode's TUI only shows the main agent's cost. This tool reveals the full picture: main agent + all sub-agents with their individual costs, tokens, and models.

Why?

When you use OpenCode with SDD orchestrators or delegated tasks, the real cost is hidden. A session might show $0.50 but the sub-agents actually spent $5.00. opencode-costs shows you the truth.

Installation

Requires Node.js 18+.

# Install
npm install
npm run build

# Optional: expose the `costs` command globally
npm link

npm install compiles better-sqlite3 (a native module), so a C/C++ toolchain must be available.

Usage inside OpenCode

This is the primary use case. Inside OpenCode, press ! to run terminal commands:

!costs

That's it. You'll see the full cost breakdown of the current session including all sub-agents.

Auto-detection: When running inside OpenCode, the tool automatically detects your current session by matching the working directory. No need to pass session IDs manually.

Quick reference

Command What it does
!costs Cost breakdown of the current session
!costs --all Global statistics across all sessions
!costs --last 5 Last 5 sessions summary
!costs --days 7 Sessions from the last 7 days
!costs --session ID Specific session by ID
!costs --agent sdd-apply Filter by agent name
!costs --json JSON output for piping

Usage outside OpenCode

If you ran npm link, the costs command is available from a regular terminal:

# Most recent session
costs

# Last 10 sessions
costs --last 10

# Sessions from the last 7 days
costs --days 7

# Sessions from the last 7 days, capped to 3
costs --days 7 --last 3

# Global stats
costs --all

# JSON for further processing
costs --json | jq '.summary.total_cost'

Without npm link, run it directly:

node dist/cli.js --all

Example output

Single session breakdown (main agent + sub-agents):

─────────────────────────────────────────────────
  Agent                       Model         Cost      %
─────────────────────────────────────────────────
  sdd-orchestrator-copilot    claude...    $0.98    39%
    sdd-explore-copilot       claude...    $1.00    40%
    sdd-apply-copilot         claude...    $0.54    22%
─────────────────────────────────────────────────
  TOTAL                                     $2.52   100%
─────────────────────────────────────────────────
In:574.9K  Out:16.2K  Rsn:6.1K  31m 38s

Session listing (--last / --days) — the Project column shows the folder each session ran in:

┌──────────────────────┬────────────────────┬───────────────────────┬───────┬─────────────────┬──────────────────┐
│ ID                   │ Project            │ Title                 │  Cost │ Model           │ Date             │
├──────────────────────┼────────────────────┼───────────────────────┼───────┼─────────────────┼──────────────────┤
│ ses_1078f10ccffep7f6 │ opencode-costs     │ Add lookback days par… │ $2.79 │ claude-opus-4.8 │ 2026-06-24 07:19 │
│ ses_10bc5a350ffeT1U2 │ api-service        │ Add rate limiting      │ $5.16 │ claude-opus-4.8 │ 2026-06-24 06:40 │
│                      │                    │ TOTAL                 │ $7.95 │                 │                  │
└──────────────────────┴────────────────────┴───────────────────────┴───────┴─────────────────┴──────────────────┘

How it works

Reads directly from OpenCode's SQLite database at ~/.local/share/opencode/opencode.db. No API keys, no external services, no tracking.

Requirements

  • Node.js 18+
  • A C/C++ toolchain (for building better-sqlite3)

License

MIT