Skip to main content

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

Project description

opencode-costs

PyPI version Downloads License Python

Leer en español

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

# From GitHub
pip install git+https://github.com/caertos/opencode-costs.git

# Or clone and install
git clone https://github.com/caertos/opencode-costs.git
cd opencode-costs
pip install .

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 --session ID Specific session by ID
!costs --agent sdd-apply Filter by agent name
!costs --json JSON output for piping

Separate terminal window

If the output gets truncated in OpenCode's terminal, open it in a separate window:

!costs --window

This opens a new terminal window with the full, untruncated report of the current session.

Usage outside OpenCode

From a regular terminal:

# Most recent session
costs

# Last 10 sessions
costs --last 10

# Global stats
costs --all

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

# Open in separate window
costs --window

Example output

╭──────────────────────────────────────────────────────────────────────╮
│ COST REPORT  ses_abc123  My session title                           │
╰──────────────────────────────────────────────────────────────────────╯
╭─────────────────────────────── RESUMEN TOTAL ────────────────────────╮
│   Cost Total         $2.52                                           │
│   Tokens Input      574.9K                                           │
│   Tokens Output      16.2K                                           │
│   Reasoning           6.1K                                           │
│   Duration         31m 38s                                           │
╰──────────────────────────────────────────────────────────────────────╯
                                        DESGLOSE POR AGENTE
╭───────────────────────────┬──────────┬──────────────┬────────╮
│ Agente                    │ Sesiones │        Costo │      % │
├───────────────────────────┼──────────┼──────────────┼────────┤
│ sdd-orchestrator-copilot  │    1     │        $0.98 │  38.8% │
│   sdd-explore-copilot     │    2     │        $1.00 │  39.6% │
│   sdd-apply-copilot       │    1     │        $0.54 │  21.6% │
├───────────────────────────┼──────────┼──────────────┼────────┤
│ TOTAL                     │    4     │        $2.52 │  100%  │
╰───────────────────────────┴──────────┴──────────────┴────────╯

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

  • Python 3.10+
  • rich (installed automatically)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opencode_costs-1.0.4.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opencode_costs-1.0.4-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file opencode_costs-1.0.4.tar.gz.

File metadata

  • Download URL: opencode_costs-1.0.4.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for opencode_costs-1.0.4.tar.gz
Algorithm Hash digest
SHA256 47c64d31aa7e3cdc627c83ba660c0e243e0e1dd105797fd5797e8f008fa64b3f
MD5 edda716f84c0faf47f26d9a5e2c3eeda
BLAKE2b-256 cdc166f5fcf0873b17614cae2a814abfe9df684261be361af59186a2814b2994

See more details on using hashes here.

Provenance

The following attestation bundles were made for opencode_costs-1.0.4.tar.gz:

Publisher: publish.yml on Caertos/opencode-costs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opencode_costs-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: opencode_costs-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for opencode_costs-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 6a20715f90f0ba44885db0375ce342f296c5d6266158f1ad72f67ac3d1be4fb6
MD5 cdcc663a0e5f5fe6163cea6be3032c71
BLAKE2b-256 4a7a79df51745a2d773737c68a100dd12bdb00901bd26fd99d7509a07dcd0e24

See more details on using hashes here.

Provenance

The following attestation bundles were made for opencode_costs-1.0.4-py3-none-any.whl:

Publisher: publish.yml on Caertos/opencode-costs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page