$ show Maciek-roboblog/Claude-Code-Usage-Monitor
This repository provides `claude-monitor`, a privacy-first CLI application for real-time monitoring of Claude Code usage. It reads local JSONL session logs, computes token consumption, costs, and burn rates, and displays them via a Rich-based terminal UI. The tool supports multiple subscription plans (Pro, Max5, Max20, Custom), integrates with Claude Code's official rate limits via statusline capture, and offers an opt-in persistent usage warehouse for historical analysis. It is distributed as a PyPI package with command aliases `cmonitor` and `ccm`. The architecture is modular, with separate packages for CLI, core logic, data ingestion/analysis, monitoring, output formatting, terminal management, UI components, and utilities. Key entry points include the CLI main module (`cli/main.py`), snapshot builder (`output/snapshots.py`), and monitoring orchestrator (`monitoring/orchestrator.py`). The application is well-tested with over 700 tests covering snapshot, trust-layer, warehouse, UI, timezone, and CLI paths. While primarily an application, it incorporates data engineering patterns such as sessionization, percentile-based limit estimation, and a versioned JSON warehouse. The codebase demonstrates strong craftsmanship with reusable components like the P90Calculator, PricingCalculator, TimezoneHandler, and UsageWarehouse. However, it has some technical drift risks due to hardcoded pricing rates, dependency on Claude Code's internal log format, and experimental API features that may change.
The LLM identified 5 files worth highlighting for reuse:
Implements P90Calculator, a cached percentile-based limit detector that computes the 90th percentile of token usage from historical session blocks. It is self-contained, uses numpy for efficient calculation, and can be extracted for any project needing percentile-based thresholds or anomaly detection.
Provides PricingCalculator with per-model input/output/cache token rates, family-based fallback, and legacy rate support. It is isolated from the rest of the codebase and can be reused in any application that needs to compute API costs based on token counts and model names.
Implements UsageWarehouse, a generic versioned JSON store with atomic upsert, pruning, and daily dimension queries. It handles schema versioning, file locking, and retention policies. This pattern is reusable for any application needing a lightweight, file-based persistent store with historical queries.
Contains TimezoneHandler, a robust utility for parsing timestamps from various formats, converting between timezones, and detecting system timezone and time format. It is self-contained and can be extracted for any Python project requiring reliable timezone-aware datetime operations.
Provides TokenProgressBar, TimeProgressBar, and ModelUsageBar with semantic color thresholds (green/yellow/red) and ASCII fallback for terminals without Unicode support. These are built on Rich's Progress and can be reused in any CLI application needing visually informative progress indicators.