@monopi/analytics-extension
v0.6.1
Published
Pi extension for analytics tracking with SQLite persistence
Readme
@monopi/analytics-extension
Pi extension for analytics tracking with SQLite persistence.
Tracks your AI usage: which models you call, how many tokens you burn, what you spend, and stores it all in a local SQLite database so you can query trends over time.
Why use this?
The built-in usage tracker shows session-level costs. This extension goes further: it records every turn across every session for every project, giving you long-term visibility into your AI spend and usage patterns.
- Answer questions like: "Did my token spend increase after switching to Sonnet 4?"
- Spot trends: Are you using more tokens per turn over time?
- Correlate with codebases: Which projects cost the most?
What it tracks
Each time you interact with pi, this extension silently records:
| Data point | Description | | ---------------- | -------------------------------------------- | | Session | Start time, end time, duration, project path | | Turn | Model, provider, input/output tokens, cost | | Codebase | Working directory (hashed for privacy) | | Model / Provider | Auto-inferred from model ID |
All data lives in a SQLite database at ~/.pi/agent/analytics.db.
Installation
pi install npm:@monopi/analytics-extensionNote: This package is opt-in. It is not installed by
npx @monopi/monopi.
Usage
Terminal stats
# Quick terminal summary
/analyticsShows session counts, total tokens, total cost, and recent activity.
Browser dashboard
# Open the full React dashboard
/analytics-dashboardThe dashboard provides charts and tables for:
- Overview: total spend, sessions, tokens by period
- Models: cost and token breakdown by model
- Codebases: which projects drive the most usage
- Insights: usage patterns across time
How it works
- Hooks into
session_start,turn_end, andsession_endevents - Auto-infers provider from model ID (e.g.,
claude-sonnet-4→anthropic) - Uses
@monopi/analytics-dbfor schema, migrations, and query helpers - Database at
~/.pi/agent/analytics.dbusing better-sqlite3 + Drizzle ORM
Dashboard
The companion browser dashboard (@monopi/analytics-dashboard) visualizes all data:
cd packages/monopi__analytics-dashboard
pnpm devIt reads directly from the same SQLite database.
Related packages
@monopi/analytics-db: SQLite schema, migrations, typed queries@monopi/analytics-dashboard: React visualization SPA
