Skip to content

heyhuynhgiabuu/ocsight

Repository files navigation

OCsight - OpenCode Cost Tracking

Track your OpenCode AI spending. Real costs from real data.

Usage Summary

What It Does

ocsight reads your OpenCode sessions and shows you exactly what you're spending:

  • Cost tracking by provider and model
  • Budget limits with spending alerts
  • Token usage breakdowns
  • Live monitoring of active sessions

Installation

# macOS/Linux (Homebrew)
brew install heyhuynhgiabuu/tap/ocsight

# Node.js (npm)
npm install -g ocsight

# Direct download
curl -L https://github.com/heyhuynhgiabuu/ocsight/releases/latest/download/ocsight-$(uname -s)-$(uname -m).zip | tar -xz

Quick Start

# See your spending
ocsight summary

# Set budget limits
ocsight budget set --monthly 200

# Monitor live usage
ocsight live

Screenshots & Examples

πŸ“Š Usage Summary

See your OpenCode usage at a glance with provider breakdowns and daily activity:

Summary Command

πŸ’° Cost Tracking

Track your AI spending with daily breakdowns and spending alerts:

Costs Command

πŸ“‹ Session Management

Browse, analyze, and drill into individual sessions:

Sessions Command

πŸ”΄ Live Monitoring

Real-time dashboard showing active session costs and tokens:

Live Monitor

πŸ’° Budget Management

Set spending limits and get alerts when approaching budgets:

Budget Status

Add budget limits and configure spending alerts:

Budget Add

View detailed budget information and settings:

Budget Show

πŸ€– Model Database

Browse pricing across 500+ AI models:

Models Database

Export Formats

ocsight can export your data in multiple formats for reporting and analysis:

JSON Export

{
  "summary": {
    "totalSessions": 787,
    "totalCost": 8736.43,
    "totalTokens": 2949563969,
    "dateRange": "2024-12-12 to 2024-12-19"
  },
  "providers": [
    {
      "name": "anthropic",
      "sessions": 26,
      "cost": 8237.66,
      "tokens": 699650136
    }
  ]
}

CSV Export

Date,Provider,Model,Sessions,Tokens,Cost
2024-12-19,anthropic,claude-3.5-sonnet,15,12345678,234.56
2024-12-18,openai,gpt-4o,23,23456789,456.78
2024-12-17,anthropic,claude-3.5-haiku,19,18234567,345.67

Markdown Report

# OpenCode Usage Report

## Summary

- **Period**: 2024-12-12 to 2024-12-19
- **Total Sessions**: 787
- **Total Cost**: $8,736.43
- **Total Tokens**: 2,949,563,969

## Top Providers

| Provider  | Sessions | Cost      | Tokens      |
| --------- | -------- | --------- | ----------- |
| anthropic | 26       | $8,237.66 | 699,650,136 |
| openai    | 77       | $405.73   | 471,822,278 |

Commands Reference

summary - Usage Overview

ocsight summary                    # Last 7 days
ocsight summary --days 30          # Last month
ocsight summary --provider anthropic  # Filter by provider
ocsight summary --detailed          # Full breakdown

sessions - Session Management

ocsight sessions list              # List all sessions
ocsight sessions list --recent     # Recent only
ocsight sessions show ses_123      # View specific session
ocsight sessions top --cost        # Most expensive sessions
ocsight sessions top --tokens      # Most tokens used

costs - Cost Tracking

ocsight costs                      # Last 7 days
ocsight costs today                # Today only
ocsight costs --days 30            # Last month
ocsight costs --alert 100          # Alert if >$100/day
ocsight costs --provider anthropic # Filter by provider

live - Real-time Monitoring

ocsight live                       # Monitor current session
ocsight live --session ses_123     # Monitor specific session
ocsight live --refresh 5           # Update every 5 seconds

export - Export Data

ocsight export                     # JSON format
ocsight export --format csv        # CSV format
ocsight export --format markdown   # Markdown report
ocsight export --output report.csv # Custom filename

models - Model Pricing

ocsight models list                # List all models
ocsight models providers           # List providers
ocsight models show gpt-4o         # Model details

budget - Budget Management

ocsight budget set --monthly 200   # Set $200 monthly limit
ocsight budget add                 # Add provider budget
ocsight budget forecast            # Project month-end costs
ocsight budget status              # Current budget usage
ocsight budget show                # Show budget details

Example Terminal Output

πŸ“Š Usage Summary
════════════════

Overview
Sessions          β”‚ 787
Total Cost        β”‚ $8,736.43
Total Tokens      β”‚ 2,949,563,969
Avg Cost/Session  β”‚ $11.10

Provider Breakdown
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Provider β”‚ Sessions β”‚ Cost     β”‚ Tokens        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ anthropicβ”‚      26  β”‚ $8,237.66β”‚ 699,650,136   β”‚
β”‚ openai   β”‚      77  β”‚   $405.73β”‚ 471,822,278   β”‚
β”‚ github   β”‚     517  β”‚     $0.00β”‚ 805,039,693   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Daily Activity (Last 7 Days)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Date       β”‚ Sessionsβ”‚ Cost     β”‚ Tokens      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 2024-12-19 β”‚      15 β”‚   $234.56β”‚  12,345,678 β”‚
β”‚ 2024-12-18 β”‚      23 β”‚   $456.78β”‚  23,456,789 β”‚
β”‚ 2024-12-17 β”‚      19 β”‚   $345.67β”‚  18,234,567 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Why ocsight?

βœ… Accurate

Real costs from actual model pricing, no estimates

πŸš€ Fast

Built with Bun for maximum performance:

  • Zstd compression (faster/smaller than gzip)
  • SIMD-accelerated ANSI processing
  • Native TypeScript execution
  • Concurrent test execution
  • Handles 10k+ sessions instantly with optimized caching

πŸ’° Smart Budgets

Set limits, get alerts, forecast spending with conservative projections

πŸ”΄ Live Monitoring

Watch costs accumulate in real-time

πŸ“Š Comprehensive Analytics

Detailed breakdowns by provider, model, and time period

πŸ”’ Private

Runs locally, never sends your data anywhere

Requirements

  • Bun runtime (recommended) or Node.js 18+
  • OpenCode installed
  • Session data in ~/.local/share/opencode/storage/

Performance with Bun

ocsight is optimized for Bun v1.3+:

  • 6-57x faster ANSI processing with native SIMD operations
  • Smaller cache files using zstd compression instead of gzip
  • Faster startup with native TypeScript execution
  • 166ms build time using Bun.build API
  • Concurrent testing for faster test execution

When running with Bun, you automatically get:

  • Native zstd compression for cache (faster + smaller than gzip)
  • SIMD-accelerated ANSI stripping in live monitoring
  • OS-native credential storage for secrets
  • Faster JSON parsing and file I/O

Node.js fallbacks ensure full compatibility without Bun-specific features.

Data Sources

ocsight reads from your local OpenCode storage:

~/.local/share/opencode/storage/
β”œβ”€β”€ session/<project-hash>/ses_*.json   # Session metadata
└── message/<session-id>/msg_*.json     # Individual messages

Development

git clone https://github.com/heyhuynhgiabuu/ocsight
cd ocsight
bun install
bun run build
bun test
bun run packages/cli/src/index.ts summary

Build Process

ocsight uses Bun's native build system:

# Bundle CLI with Bun.build API
bun run scripts/bundle-cli.ts

# Compile standalone executables
bun build packages/cli/src/index.ts --compile --outfile ocsight-linux-x64

# Run tests with concurrent execution
bun test --concurrent

# Watch mode for development
bun test --watch

Cross-Platform Builds

Native executables are built via CI:

  • Linux x64 - Ubuntu 22.04 build
  • macOS x64 - Intel Mac build with code signing
  • macOS ARM64 - Apple Silicon build with code signing
  • Windows x64 - Windows build with .exe output

Download from releases page.

Configuration

ocsight works out of the box. Optional config:

ocsight budget set --monthly 200    # Set budget
ocsight config show                  # View config
ocsight config doctor               # Validate setup

Troubleshooting

No data showing?

  • Check OpenCode is installed: which opencode
  • Verify data exists: ls ~/.local/share/opencode/storage/
  • Run doctor: ocsight config doctor

Wrong costs?

  • ocsight uses models.dev pricing
  • Some providers (github) show $0.00 for free tiers
  • Custom/enterprise pricing not supported

Performance issues?

  • First run caches data (may be slow)
  • Use --days flag to limit data range
  • Large histories (>10k sessions) may be slow
  • Tip: Run with Bun for 6-57x faster performance vs Node.js

Project Structure

ocsight/
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ cli/          # CLI implementation
β”‚   └── web/          # Documentation website
β”œβ”€β”€ assets/           # Screenshots and examples
β”œβ”€β”€ scripts/          # Build and release scripts
└── README.md         # You are here

Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new features
  4. Submit a pull request

License

MIT Β© heyhuynhgiabuu

Links


Track your AI costs with confidence Β· Built with Bun.js for speed