๐ OpenCode Monitor
June 10, 2026 ยท View on GitHub
OpenCode Monitor is a CLI tool for monitoring and analyzing OpenCode AI coding sessions.
Transform your OpenCode usage data into beautiful, actionable insights with comprehensive analytics, real-time monitoring, and professional reporting capabilities.
โ ๏ธ Disclaimer - This application is not affiliated with OpenCode AI. It is an independent community tool for monitoring OpenCode usage.
๐ Features
๐ผ Professional Analytics
- ๐ Comprehensive Reports - Daily, weekly, and monthly usage breakdowns
- ๐ฐ Cost Tracking - Accurate cost calculations for multiple AI models
- ๐ Multi-Currency Support - Display costs in USD, GBP, EUR, JPY, CNY, INR, or any currency with live exchange rates
- ๐ Model Analytics - Detailed breakdown of usage per AI model with
--breakdownflag - ๐ Single Model Deep Dive -
ocmonitor model <name>drills into one model with dates, costs, speed, and tool stats - ๐ Project Analytics - Track costs and token usage by coding project
- โฑ๏ธ Performance Metrics - Session duration and processing time tracking
- ๐ Flexible Week Boundaries - Customize weekly reports with 7 start day options (Monday-Sunday)
- ๐ Output Speed Tracking - Average output tokens per second for each model in reports
- ๐ Workflow Grouping - Automatically groups main sessions with their sub-agent sessions (explore, etc.)
๐๏ธ Storage Support
- SQLite Database - Native support for OpenCode v1.2.0+ SQLite format (
~/.local/share/opencode/opencode.db) - Legacy File Support - Backwards compatible with pre-v1.2.0 JSON file storage
- Auto Detection - Automatically detects and uses the appropriate storage backend
- Hierarchical Sessions - Parent/sub-agent relationships from SQLite displayed as tree view
๐จ Beautiful User Interface
- ๐ Rich Terminal UI - Professional design with clean styling and optimal space utilization
- ๐ Progress Bars - Visual indicators for cost quotas, context usage, and session time
- ๐ฅ Color Coding - Green/yellow/red status indicators based on usage thresholds
- ๐ฑ Live Dashboard - Real-time monitoring with project names and session titles
- โฐ Session Time Tracking - 5-hour session progress bar with color-coded time alerts
- ๐ง Tool Usage Panel - Track tool success rates (bash, read, edit, etc.) in live dashboard
๐ค Data Export & Integration
- ๐ CSV Export - Spreadsheet-compatible exports with metadata
- ๐ JSON Export - Machine-readable exports for custom integrations
- ๐ Multiple Report Types - Sessions, daily, weekly, monthly, model, and project reports
- ๐ Prometheus Metrics - Real-time metrics endpoint for Grafana/Prometheus integration
๐ Quick Start
Installation
Option 1: pip / PyPI (Recommended)
pip install opencode-monitor
With optional extras:
pip install "opencode-monitor[charts,export]"
Option 2: uvx (Run without installing)
uvx opencode-monitor live
Option 3: uv tool install
uv installs the tool in an isolated environment.
uv tool install opencode-monitor
# With optional extras
uv tool install "opencode-monitor[charts,export]"
# Easy to upgrade
uv tool upgrade opencode-monitor
Option 4: pipx Installation (Cross Platform)
pipx creates isolated environments and works on all platforms (including Arch Linux, Ubuntu, macOS, etc.).
pipx install opencode-monitor
With optional extras:
pipx install "opencode-monitor[charts,export]"
Option 5: Install from source
git clone https://github.com/Shlomob/ocmonitor-share.git
cd ocmonitor-share
python3 -m pip install -e .
Option 6: Dockerized Installation
docker compose build
Usage example:
docker compose run --rm ocmonitor sessions
If your host OpenCode data is not in ~/.local/share/opencode, set OPENCODE_DATA_DIR before running:
OPENCODE_DATA_DIR=/your/path/to/opencode/data/dir docker compose run --rm ocmonitor sessions
Basic Usage
# Real-time monitoring dashboard
ocmonitor live
# View sessions history
ocmonitor sessions
# Daily usage breakdown (add --breakdown for per-model detail)
ocmonitor daily
ocmonitor daily --breakdown
# Deep dive into a specific model
ocmonitor model claude-sonnet-4-5
Command Reference
| Command | Description |
|---|---|
ocmonitor live | Real-time monitoring dashboard |
ocmonitor sessions | All sessions summary with workflow grouping |
ocmonitor session <path> | Single session detail |
ocmonitor daily | Daily usage breakdown |
ocmonitor weekly | Weekly usage breakdown |
ocmonitor monthly | Monthly usage breakdown |
ocmonitor models | Model usage statistics |
ocmonitor model <name> | Single model deep dive |
ocmonitor projects | Project usage statistics |
ocmonitor agents | List detected agents and types |
ocmonitor export <type> | Export to CSV/JSON |
ocmonitor metrics | Prometheus metrics endpoint |
ocmonitor config show | Show current configuration |
Global Options
These options can be used with any command:
ocmonitor --theme light sessions # Override theme (dark/light)
ocmonitor --verbose daily # Show detailed error traces
ocmonitor --config /path/config.toml sessions # Use custom config file
ocmonitor --no-remote sessions # Disable remote pricing fallback
๐ Documentation
- Quick Start Guide - Get up and running in 5 minutes
- Manual Test Guide - Comprehensive testing instructions
- Contributing Guidelines - How to contribute to the project
๐ฏ Use Cases
Individual Developers
- Cost Management - Track your AI usage costs across different models and projects
- Usage Optimization - Identify patterns in your coding sessions with session time tracking
- Performance Monitoring - Monitor session efficiency and token usage with real-time dashboards
- Project Analytics - Understand which projects consume the most AI resources
Development Teams
- Team Analytics - Aggregate usage statistics across team members and projects
- Budget Planning - Forecast AI costs based on usage trends and project breakdowns
- Model Comparison - Compare performance and costs across different AI models
- Session Management - Track coding session durations and productivity patterns
Organizations
- Resource Planning - Plan AI resource allocation and budgets by project
- Usage Reporting - Generate professional reports for stakeholders with export capabilities
- Cost Attribution - Track AI costs by project, team, and time period
- Quality Monitoring - Monitor session lengths and usage patterns for optimization
๐ Example Output
๐ธ Screenshots: The following examples include both text output and clickable screenshots. To add your own screenshots, place PNG files in the
screenshots/directory with the corresponding filenames.
Sessions Summary
Click image to view full-size screenshot of sessions summary output
Workflow Grouping
By default, sessions are grouped into workflows - a main session combined with its sub-agent sessions (like explore). This gives you a complete picture of your coding session including all agent activity.
# Sessions with workflow grouping (default)
ocmonitor sessions
# Sessions without grouping (flat list)
ocmonitor sessions --no-group
# Force a specific data source
ocmonitor sessions --source sqlite # Force SQLite (v1.2.0+)
ocmonitor sessions --source files # Force legacy file storage
# List detected agents and their types
ocmonitor agents
Workflow Features:
- Main sessions and sub-agent sessions are visually grouped with tree-style formatting
- Aggregated tokens and costs are shown for the entire workflow
- Sub-agent count displayed in the Agent column (e.g.,
+2means 2 sub-agents) - Use
--no-groupto see individual sessions without grouping
Time-Based Reporting
ocmonitor daily|weekly|monthly <path> [--breakdown]
Time-based usage breakdown with optional per-model cost analysis.
# Daily breakdown
ocmonitor daily
# Weekly breakdown with per-model breakdown
ocmonitor weekly --breakdown
# Monthly breakdown
ocmonitor monthly
# Weekly with custom start day
ocmonitor weekly --start-day friday --breakdown
--breakdown Flag: Shows token consumption and cost per model within each time period (daily/weekly/monthly), making it easy to see which models are consuming resources.
Supported days: monday, tuesday, wednesday, thursday, friday, saturday, sunday
Live Monitoring Commands
ocmonitor live <path>
Real-time monitoring dashboard that updates automatically.
# Start live monitoring (updates every 3 seconds by default)
ocmonitor live
# Custom update interval (in seconds)
ocmonitor live --interval 10
# Pick a workflow by readable title before launching
# (also enables interactive switching controls by default)
ocmonitor live --pick
# Pin live monitor to a specific workflow/session ID
ocmonitor live --session-id ses_abc123
# Force a specific data source
ocmonitor live --source sqlite # Force SQLite (v1.2.0+)
ocmonitor live --source files # Force legacy file storage
# Enable interactive switching while live monitor runs (experimental)
ocmonitor live --interactive-switch
If --session-id is pinned and the selected workflow is no longer active, live monitoring stops with a clear message.
When both --session-id and --pick are supplied to ocmonitor live, --session-id takes precedence and --pick is ignored.
Features:
- ๐ Auto-refreshing display with professional UI design
- ๐ Real-time cost tracking with progress indicators
- โฑ๏ธ Live session duration with 5-hour progress bar
- ๐ Token usage updates and context window monitoring
- ๐ Output Rate - Rolling 5-minute window showing output tokens per second
- ๐ฆ Color-coded status indicators and time alerts
- ๐ Project name display for better context
- ๐ Human-readable session titles instead of cryptic IDs
- ๐ Workflow Tracking - Automatically tracks entire workflow including sub-agents (explore, etc.)
- ๐ง Tool Usage Stats - Shows success rates for tools (bash, read, edit, etc.) with color-coded progress bars
Click image to view full-size screenshot of the live monitoring dashboard
Model Usage Breakdown
Click image to view full-size screenshot of model usage analytics
# Filter by timeframe or date range
ocmonitor models --timeframe weekly
ocmonitor models --start-date 2026-01-01 --end-date 2026-02-01
ocmonitor projects --timeframe monthly
ocmonitor projects --start-date 2026-01-01 --end-date 2026-02-01
Model Analytics Features:
- Per-provider/model token usage and cost breakdown, with separate Provider and Model columns
- Cost percentage distribution across models
- Speed Column - Average output tokens per second for each model
- Session and interaction counts per model
Single Model Detail
# Drill into one model by exact or partial name
ocmonitor model claude-sonnet-4-5
ocmonitor model sonnet # lists all sonnet variants to pick from
ocmonitor model opus -f json # JSON output
Output:
โญโ Model Detail: claude-sonnet-4-5 โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ First Used 2025-09-15 โ
โ Last Used 2026-02-28 โ
โ Sessions 42 โ
โ Days Used 28 โ
โ Interactions 1,247 โ
โ โ
โ Input Tokens 2,451,320 โ
โ Output Tokens 489,210 โ
โ Cache Read 1,102,400 โ
โ Cache Write 312,500 โ
โ โ
โ Total Cost \$47.23 โ
โ Avg/Day \$1.69 โ
โ Avg/Session \$1.12 โ
โ โ
โ Output Speed 62.4 tok/s (p50) โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Tool Usage for claude-sonnet-4-5
โโโโโโโโโโณโโโโโโโโณโโโโโโโโโโณโโโโโโโโโณโโโโโโโโโโโโโโโ
โ Tool โ Calls โ Success โ Failed โ Success Rate โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ read โ 620 โ 598 โ 22 โ 96% โ
โ edit โ 412 โ 389 โ 23 โ 94% โ
โ bash โ 298 โ 285 โ 13 โ 96% โ
โโโโโโโโโโดโโโโโโโโดโโโโโโโโโโดโโโโโโโโโดโโโโโโโโโโโโโโโ
Features:
- ๐ Fuzzy Matching - Partial name matches; shows alternatives when multiple models match
- ๐ Key-Value Panel - First/last used, sessions, days active, interactions, full token breakdown
- ๐ฐ Cost Breakdown - Total cost, average per day, average per session
- ๐ Output Speed - Median output tokens/sec (p50) across all interactions
- ๐ง Tool Stats - Per-tool calls, success, failed, color-coded success rate
Prometheus Metrics
# Start metrics server (default port 9090)
ocmonitor metrics
# Custom port
ocmonitor metrics --port 8080
# Scrape metrics
curl http://localhost:9090/metrics
Metrics exposed:
ocmonitor_tokens_input_total{model}- Input tokens per modelocmonitor_tokens_output_total{model}- Output tokens per modelocmonitor_cost_dollars_total{model}- Total cost per modelocmonitor_sessions_total{model}- Session count per modelocmonitor_session_duration_hours_total- Total session durationocmonitor_sessions_by_project{project}- Sessions by project
Note: The model label value is in provider/model format (e.g., anthropic/claude-sonnet-4-20250514).
โ๏ธ Configuration
Configuration File Location
Create your configuration file at: ~/.config/ocmonitor/config.toml
# Create the configuration directory
mkdir -p ~/.config/ocmonitor
# Create your configuration file
touch ~/.config/ocmonitor/config.toml
Configuration Options
The tool is highly configurable through the config.toml file:
[paths]
# OpenCode v1.2.0+ SQLite database (preferred)
database_file = "~/.local/share/opencode/opencode.db"
# Legacy file storage (fallback)
messages_dir = "~/.local/share/opencode/storage/message"
export_dir = "./exports"
[ui]
table_style = "rich" # "rich", "simple", or "minimal"
theme = "dark" # "dark" or "light"
progress_bars = true
colors = true
live_refresh_interval = 3 # Live dashboard refresh in seconds
[export]
default_format = "csv"
include_metadata = true
[analytics]
default_timeframe = "daily" # "daily", "weekly", or "monthly"
recent_sessions_limit = 50 # Max sessions to analyze by default
[models]
# Path to local models pricing configuration
config_file = "models.json"
# Remote pricing fallback from models.dev (disabled by default)
remote_fallback = false
remote_url = "https://models.dev/api.json"
remote_timeout_seconds = 8
remote_cache_ttl_hours = 24
[metrics]
# Prometheus metrics server configuration
port = 9090
host = "0.0.0.0"
[currency]
# Display currency (ISO 4217 code): USD, GBP, EUR, CNY, JPY, INR, or custom
code = "USD"
symbol = "$"
# Conversion rate from USD (ignored when remote_rates = true)
rate = 1.0
# Display format: "symbol_prefix" (\$1.23) or "code_suffix" (1.23 USD)
display_format = "symbol_prefix"
# Decimal places (auto if not set: JPY=0, most others=2)
# decimals = 2
# Live rate fetching from frankfurter.dev (free, no API key)
remote_rates = false
remote_rates_url = "https://api.frankfurter.dev/v1/latest?base=USD"
remote_rates_timeout_seconds = 8
remote_rates_cache_ttl_hours = 24
remote_rates_cache_path = "~/.cache/ocmonitor/exchange_rates.json"
allow_stale_rates_on_error = true
Configuration File Search Order:
~/.config/ocmonitor/config.toml(user overrides - highest priority)config.toml(current directory)ocmonitor.toml(current directory)- Packaged fallback:
ocmonitor/config.toml(lowest priority, only used if no other config exists)
User settings in ~/.config/ocmonitor/config.toml take precedence over all other locations.
Remote Pricing Fallback
OpenCode Monitor supports automatic pricing updates from models.dev, a community-maintained pricing database.
Features:
- Automatically fetches pricing for new models not in your local
models.json - Fill-only mode - never overwrites your local or user-defined prices
- Shared cache across all your projects (
~/.cache/ocmonitor/models_dev_api.json) - 24-hour TTL with stale cache fallback on errors
- Works offline using cached data
Enable Remote Fallback:
[models]
remote_fallback = true
Use --no-remote to disable for a single run:
# Force local-only pricing for this command
ocmonitor --no-remote sessions
Pricing Precedence (highest to lowest):
- User override file (
~/.config/ocmonitor/models.json) - Project/local
models.json - models.dev remote fallback (fill-only)
Currency Conversion
OpenCode Monitor supports displaying costs in your local currency instead of USD.
Quick Setup:
[currency]
code = "GBP"
symbol = "ยฃ"
rate = 0.79
Supported Presets:
| Currency | Code | Symbol | Example Rate |
|---|---|---|---|
| US Dollar | USD | $ | 1.00 |
| British Pound | GBP | ยฃ | 0.79 |
| Euro | EUR | โฌ | 0.92 |
| Chinese Yuan | CNY | ยฅ | 7.24 |
| Japanese Yen | JPY | ยฅ | 149.50 |
| Indian Rupee | INR | INR | 83.12 |
Display Formats:
symbol_prefix(default):$1.23orยฃ1.23code_suffix:1.23 USDor1.23 GBP
Live Exchange Rates: Enable automatic rate fetching from frankfurter.dev:
[currency]
code = "EUR"
symbol = "โฌ"
remote_rates = true
JPY/Zero-Decimal Currencies: Currencies like JPY automatically use 0 decimal places unless explicitly configured.
๐ ๏ธ Development
Prerequisites
- Python 3.8+
- pip package manager
Setting Up Development Environment
The project uses pyproject.toml for modern Python packaging. You can install in development mode using either pip or pipx:
git clone https://github.com/Shlomob/ocmonitor-share.git
cd ocmonitor-share
# Using pip (editable install)
python3 -m pip install -e ".[dev]"
# Or using pipx (editable install)
pipx install -e ".[dev]"
Install all extras for development:
python3 -m pip install -e ".[dev,charts,export]"
Running Tests
# Run all tests
pytest
# Run only unit tests
pytest -m unit
# Run only integration tests
pytest -m integration
# Legacy test scripts
python3 test_basic.py
python3 test_simple.py
Project Architecture
ocmonitor/
โโโ cli.py # Command-line interface (all commands)
โโโ config.py # Configuration management, TOML parsing
โโโ models/ # Pydantic data models
โ โโโ analytics.py # DailyUsage, WeeklyUsage, MonthlyUsage, ModelUsageStats
โ โโโ session.py # TokenUsage, TimeData, InteractionFile, SessionData
โ โโโ tool_usage.py # Tool usage tracking models
โ โโโ workflow.py # Workflow grouping models
โโโ services/ # Business logic layer
โ โโโ agent_registry.py # Agent type detection
โ โโโ export_service.py # CSV/JSON export functionality
โ โโโ live_monitor.py # Real-time dashboard with auto-refresh
โ โโโ price_fetcher.py # Remote pricing from models.dev
โ โโโ report_generator.py # Rich UI report generation
โ โโโ session_analyzer.py # Core session analysis and summaries
โ โโโ session_grouper.py # Workflow grouping logic
โโโ ui/ # Rich UI components
โ โโโ dashboard.py # Live dashboard UI
โ โโโ tables.py # Table formatting with progress bars
โ โโโ theme.py # Dark/light theme support
โโโ utils/ # Utility functions
โโโ data_loader.py # Unified data loading (SQLite/files)
โโโ error_handling.py # User-friendly error messages
โโโ file_utils.py # File processing
โโโ formatting.py # Number/cost formatting utilities
โโโ sqlite_utils.py # SQLite database access
โโโ time_utils.py # Time formatting and calculations
๐ค Contributing
We welcome contributions! Please see our Contributing Guidelines for details on:
- ๐ Reporting bugs
- ๐ก Suggesting features
- ๐ง Setting up development environment
- ๐ Code style and standards
- ๐ Submitting pull requests
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- OpenCode - For creating an excellent AI coding agent that makes development more efficient
- ccusage - A similar monitoring tool for Claude Code that inspired features in this project
- Click - Excellent CLI framework
- Rich - Beautiful terminal formatting
- Pydantic - Data validation and settings
๐ Status
๐งช Beta Testing - This application is currently in beta testing phase. Please report any issues you encounter.
Built with โค๏ธ for the OpenCode community


