ocmonitor-share

ocmonitor-share

OpenCode Monitor is a CLI tool for monitoring and analyzing OpenCode AI coding usage

Stars: 138

Visit
 screenshot

OpenCode Monitor is a CLI tool designed for monitoring and analyzing OpenCode AI coding sessions. It provides comprehensive analytics, real-time monitoring, and professional reporting capabilities. The tool offers features such as professional analytics with detailed reports, cost tracking, model analytics, project analytics, performance metrics, and flexible week boundaries. It also supports storage in SQLite database format, legacy file support, and hierarchical sessions display. The tool features a beautiful user interface with rich terminal UI, progress bars, color coding, live dashboard, and session time tracking. Additionally, it allows data export in CSV and JSON formats, and offers various types of reports. OpenCode Monitor is highly configurable through a configuration file and supports remote pricing updates from models.dev for new models. The tool is suitable for individual developers, development teams, and organizations to manage costs, optimize usage, monitor performance, and track AI resources.

README:

๐Ÿ“Š OpenCode Monitor

Python 3.8+ License: MIT

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.

Sessions Summary Screenshot

๐ŸŒŸ Features

๐Ÿ’ผ Professional Analytics

  • ๐Ÿ“ˆ Comprehensive Reports - Daily, weekly, and monthly usage breakdowns
  • ๐Ÿ’ฐ Cost Tracking - Accurate cost calculations for multiple AI models
  • ๐Ÿ“Š Model Analytics - Detailed breakdown of usage per AI model with --breakdown flag
  • ๐Ÿ“‹ 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

๐Ÿš€ Quick Start

Installation

Option 1: uv Installation (Fastest - One-liner)

uv is a fast Python package manager. It installs the tool in an isolated environment without cloning the repository.

# Install directly from GitHub
uv tool install git+https://github.com/Shlomob/ocmonitor-share.git

# With optional extras
uv tool install "git+https://github.com/Shlomob/ocmonitor-share.git#egg=ocmonitor[charts,export]"

Why uv?

  • No need to clone the repository
  • Lightning-fast dependency resolution
  • Creates isolated environments automatically
  • Easy to upgrade: uv tool upgrade ocmonitor

Option 2: pipx Installation (Cross Platform)

pipx is the recommended way to install Python CLI applications. It creates isolated environments and works on all platforms (including Arch Linux, Ubuntu, macOS, etc.).

git clone https://github.com/Shlomob/ocmonitor-share.git
cd ocmonitor-share
pipx install .

Why pipx?

  • Creates isolated environments (no dependency conflicts)
  • Works on Arch Linux without breaking system packages
  • No sudo required
  • Easy to upgrade or uninstall

Optional extras:

# With visualization charts
pipx install ".[charts]"

# With export functionality  
pipx install ".[export]"

# With all extras
pipx install ".[charts,export]"

Option 3: Automated Installation (Linux/macOS)

git clone https://github.com/Shlomob/ocmonitor-share.git
cd ocmonitor-share
./install.sh

Option 4: Manual Installation

git clone https://github.com/Shlomob/ocmonitor-share.git
cd ocmonitor-share
python3 -m pip install -r requirements.txt
python3 -m pip install -e .

Basic Usage

# Quick configuration check
ocmonitor config show

# Analyze your sessions (auto-detects SQLite or files)
ocmonitor --theme light sessions

# Analyze by project
ocmonitor projects

# Real-time monitoring (dark theme)
ocmonitor --theme dark live

# Export your data
ocmonitor export sessions --format csv

# Force specific data source
ocmonitor sessions --source sqlite
ocmonitor sessions --source files

๐Ÿ“– Documentation

๐ŸŽฏ 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

Sessions Summary Screenshot

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 ~/.local/share/opencode/storage/message

# Sessions without grouping (flat list)
ocmonitor sessions ~/.local/share/opencode/storage/message --no-group

# 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., +2 means 2 sub-agents)
  • Use --no-group to 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 ~/.local/share/opencode/storage/message

# Weekly breakdown with per-model breakdown
ocmonitor weekly ~/.local/share/opencode/storage/message --breakdown

# Monthly breakdown
ocmonitor monthly ~/.local/share/opencode/storage/message

# Weekly with custom start day
ocmonitor weekly ~/.local/share/opencode/storage/message --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 5 seconds)
ocmonitor live ~/.local/share/opencode/storage/message

# Custom refresh interval (in seconds)
ocmonitor live ~/.local/share/opencode/storage/message --refresh 10

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

Live Dashboard Screenshot

Click image to view full-size screenshot of the live monitoring dashboard

Model Usage Breakdown

Model Usage Breakdown Screenshot

Click image to view full-size screenshot of model usage analytics

Model Analytics Features:

  • Per-model token usage and cost breakdown
  • Cost percentage distribution across models
  • Speed Column - Average output tokens per second for each model
  • Session and interaction counts per model

โš™๏ธ 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"
progress_bars = true
colors = true

[export]
default_format = "csv"
include_metadata = true

[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

Configuration File Search Order:

  1. ~/.config/ocmonitor/config.toml (recommended user location)
  2. config.toml (current directory)
  3. Project directory fallback

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):

  1. OpenCode's pre-computed cost (from session data, when available)
  2. User override file (~/.config/ocmonitor/models.json)
  3. Project/local models.json
  4. models.dev remote fallback (fill-only)

๐Ÿ› ๏ธ 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/
โ”œโ”€โ”€ ocmonitor/              # Core package
โ”‚   โ”œโ”€โ”€ cli.py             # Command-line interface
โ”‚   โ”œโ”€โ”€ config.py          # Configuration management
โ”‚   โ”œโ”€โ”€ models/            # Pydantic data models
โ”‚   โ”‚   โ”œโ”€โ”€ session.py     # Session and interaction models
โ”‚   โ”‚   โ””โ”€โ”€ workflow.py    # Workflow grouping models
โ”‚   โ”œโ”€โ”€ services/          # Business logic services
โ”‚   โ”‚   โ”œโ”€โ”€ agent_registry.py    # Agent type detection
โ”‚   โ”‚   โ”œโ”€โ”€ session_grouper.py   # Workflow grouping logic
โ”‚   โ”‚   โ”œโ”€โ”€ live_monitor.py      # Real-time monitoring
โ”‚   โ”‚   โ””โ”€โ”€ report_generator.py  # Report generation
โ”‚   โ”œโ”€โ”€ ui/                # Rich UI components
โ”‚   โ”‚   โ””โ”€โ”€ dashboard.py   # Live dashboard UI
โ”‚   โ””โ”€โ”€ utils/             # Utility functions
โ”‚       โ”œโ”€โ”€ data_loader.py # Unified data loading (SQLite/files)
โ”‚       โ”œโ”€โ”€ file_utils.py  # File processing
โ”‚       โ””โ”€โ”€ sqlite_utils.py # SQLite database access
โ”œโ”€โ”€ config.toml            # User configuration
โ”œโ”€โ”€ models.json            # AI model pricing data
โ””โ”€โ”€ test_sessions/         # Sample test data

๐Ÿค 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

For Tasks:

Click tags to check more tools for each tasks

For Jobs:

Alternative AI tools for ocmonitor-share

Similar Open Source Tools

For similar tasks

For similar jobs