{"id":50669017,"url":"https://github.com/xautjzd/ai-stats","last_synced_at":"2026-06-08T09:02:45.780Z","repository":{"id":359974875,"uuid":"1248175100","full_name":"xautjzd/ai-stats","owner":"xautjzd","description":"A terminal dashboard for tracking usage statistics across AI coding tools(including Claude Code/Codex/OpenCode)","archived":false,"fork":false,"pushed_at":"2026-05-24T11:48:57.000Z","size":241,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-24T13:07:58.323Z","etag":null,"topics":["ai-usage","usage-statistics"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xautjzd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-24T09:35:40.000Z","updated_at":"2026-05-24T11:49:01.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/xautjzd/ai-stats","commit_stats":null,"previous_names":["xautjzd/ai-stats"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/xautjzd/ai-stats","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xautjzd%2Fai-stats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xautjzd%2Fai-stats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xautjzd%2Fai-stats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xautjzd%2Fai-stats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xautjzd","download_url":"https://codeload.github.com/xautjzd/ai-stats/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xautjzd%2Fai-stats/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34055249,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-08T02:00:07.615Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-usage","usage-statistics"],"created_at":"2026-06-08T09:02:43.905Z","updated_at":"2026-06-08T09:02:45.764Z","avatar_url":"https://github.com/xautjzd.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ai-stats\n\n\u003e A terminal dashboard for tracking usage statistics across AI coding tools.\n\n[中文文档](README.zh.md)\n\nAggregates session counts, token usage, cache efficiency, cost estimates, and extension inventory from **Claude Code**, **OpenCode**, and **Codex CLI** — all in one place. No accounts, no telemetry, reads only local data files.\n\n```\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n             AI CODING TOOLS STATISTICS\n                  Generated 2025-05-24 14:32\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n📊 OVERVIEW\n\n  Total Sessions:      1,284\n  Total Tokens:    9,471,032\n\n🔧 TOOL BREAKDOWN\n\n  Tool            Sessions               Tokens                 Share\n  ──────────────────────────────────────────────────────────────────\n  ◆ Claude Code        842          7,821,004  ████████████████░░░░  82%\n  ◈ OpenCode           312          1,241,887  ████░░░░░░░░░░░░░░░░  13%\n  ◇ Codex CLI          130            408,141  █░░░░░░░░░░░░░░░░░░░   4%\n```\n\n\n![](./screenshot.png)\n\n---\n\n## Supported Tools\n\n| Tool | Data Source | Format |\n|------|-------------|--------|\n| [Claude Code](https://claude.ai/code) | `~/.claude/stats-cache.json` | JSON |\n| [OpenCode](https://github.com/sst/opencode) | `~/.local/share/opencode/opencode.db` | SQLite |\n| [Codex CLI](https://github.com/openai/codex) | `~/.codex/state_5.sqlite` | SQLite |\n\nOnly tools with existing data files are shown. Missing tools are silently skipped.\n\n---\n\n## Requirements\n\n| Dependency | Required | Purpose |\n|------------|----------|---------|\n| Bash 3.x+ | Yes | Script runtime |\n| `sqlite3` | Yes | Read OpenCode and Codex databases |\n| `jq` | No | Per-model breakdown, daily activity, and MCP server listing for Claude Code |\n\nInstall dependencies:\n\n```bash\n# macOS\nbrew install sqlite jq\n\n# Arch Linux\nsudo pacman -S sqlite jq\n\n# Debian / Ubuntu\nsudo apt install sqlite3 jq\n\n# Fedora / RHEL\nsudo dnf install sqlite jq\n```\n\n---\n\n## Installation\n\n```bash\n# Download\ncurl -O https://raw.githubusercontent.com/yourname/ai-stats/main/ai-stats\n\n# Make executable\nchmod +x ai-stats\n\n# Run\n./ai-stats\n```\n\nOr place it somewhere on your `$PATH` for global access:\n\n```bash\nmv ai-stats /usr/local/bin/ai-stats\nai-stats\n```\n\n---\n\n## Usage\n\n```\nai-stats [COMMAND] [OPTIONS]\n```\n\n### Commands\n\n| Command | Alias | Description |\n|---------|-------|-------------|\n| `dashboard` | `d` | Full overview + all tool details (default) |\n| `claude` | `c` | Claude Code statistics only |\n| `opencode` | `o` | OpenCode statistics only |\n| `codex` | `x` | Codex CLI statistics only |\n| `compare` | `cmp` | Side-by-side cross-tool comparison |\n| `export` | `e` | Export all data to JSON |\n| `help` | `h` | Show usage information |\n\n### Options\n\n| Option | Description |\n|--------|-------------|\n| `-o, --output FILE` | Output path for the `export` command |\n| `--no-color` | Disable ANSI color output (for piping or logging) |\n| `--width NUM` | Override terminal width for formatting |\n\n### Examples\n\n```bash\n# Default dashboard (all tools)\nai-stats\n\n# Claude Code only\nai-stats claude\n\n# Compare all tools side by side\nai-stats compare\n\n# Export to a timestamped file\nai-stats export\n\n# Export to a specific path\nai-stats export -o ~/reports/ai-usage.json\n\n# Pipe-friendly output\nai-stats --no-color claude | tee claude-stats.txt\n```\n\n---\n\n## What Each View Shows\n\n### Dashboard\n\nA summary overview of all detected tools: total sessions, total tokens, and a proportional bar chart showing each tool's share of token consumption.\n\n### Claude Code (`claude`)\n\n- Sessions and message counts\n- Input / output token totals\n- Cache read and write tokens\n- Token breakdown by model (requires `jq`)\n- Recent 7-day activity: sessions, messages, tool calls per day (requires `jq`)\n- MCP servers configured in `claude_desktop_config.json` (requires `jq`)\n- Installed plugins and skill counts per plugin\n\n### OpenCode (`opencode`)\n\n- Sessions and message counts\n- Input / output / reasoning token totals\n- Cache read and write tokens\n- Estimated cost\n- Token and session breakdown by model\n- Recent 7-day activity: sessions, tokens, cost per day\n- MCP servers and skill paths from `opencode.json`\n\n### Codex CLI (`codex`)\n\n- Total, active, and archived thread counts\n- Total tokens used\n- Source breakdown (CLI vs VS Code)\n- Token breakdown by model\n- Recent 7-day activity: threads, tokens per day\n- Enabled plugins and MCP servers per plugin\n\n### Comparison (`compare`)\n\nA unified table across all tools showing sessions, input tokens, output tokens, and cache hits on one screen.\n\n### Export (`export`)\n\nOutputs a single JSON file combining raw data from all available tools:\n\n```json\n{\n  \"generated_at\": \"2025-05-24T06:32:00Z\",\n  \"tools\": {\n    \"claude_code\": { ... },\n    \"opencode\": { ... },\n    \"codex\": { ... }\n  }\n}\n```\n\n---\n\n## Data Sources\n\nThe script reads **only local files** — no network requests are made.\n\n| Tool | File | Notes |\n|------|------|-------|\n| Claude Code stats | `~/.claude/stats-cache.json` | Written by Claude Code automatically |\n| Claude MCP config | `~/Library/Application Support/Claude/claude_desktop_config.json` | macOS |\n| Claude MCP config | `~/.config/Claude/claude_desktop_config.json` | Linux (XDG) |\n| Claude plugins | `~/.claude/plugins/installed_plugins.json` | Plugin registry |\n| OpenCode database | `~/.local/share/opencode/opencode.db` | SQLite, written by OpenCode |\n| OpenCode config | `~/.config/opencode/opencode.json` | MCP and skills config |\n| Codex database | `~/.codex/state_5.sqlite` | SQLite, written by Codex CLI |\n| Codex config | `~/.codex/config.toml` | Plugin configuration |\n\n---\n\n## Adding a New Tool\n\nThe script uses a simple registry pattern. To add support for a new tool:\n\n1. **Register the tool** — append to the four arrays at the top of the script:\n\n   ```bash\n   TOOL_NAMES=(\"claude\" \"opencode\" \"codex\" \"mytool\")\n   TOOL_DISPLAYS=(\"Claude Code\" \"OpenCode\" \"Codex CLI\" \"My Tool\")\n   TOOL_PATHS=(\"~/.claude/stats-cache.json\" \"...\" \"...\" \"~/.mytool/data.db\")\n   TOOL_TYPES=(\"json\" \"sqlite\" \"sqlite\" \"sqlite\")\n   ```\n\n2. **Implement the stats function** — follow the naming convention `{tool_name}_stats`:\n\n   ```bash\n   mytool_stats() {\n       local db_path\n       db_path=$(expand_path \"~/.mytool/data.db\")\n       # query and print stats\n   }\n   ```\n\n3. **Implement the daily function** — `{tool_name}_daily` for the 7-day activity view.\n\n4. **Implement the extensions function** — `{tool_name}_extensions` for MCP servers and plugins.\n\n5. **Add a show function** — `show_mytool` that calls `tool_banner`, then the three functions above.\n\n6. **Wire it into `show_dashboard`** and the `main` case statement.\n\n---\n\n## Compatibility\n\n- macOS 13+ (primary target, tested)\n- Linux (fully supported — Arch, Debian, Ubuntu, Fedora, and compatible distros)\n- Bash 3.2+ compatible — no associative arrays, no `mapfile`\n- Number formatting works without `numfmt` via a pure-bash fallback\n- Claude Code JSON is parsed with `grep`/`awk` when `jq` is not installed (session and token totals only; per-model breakdown requires `jq`)\n\n---\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxautjzd%2Fai-stats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxautjzd%2Fai-stats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxautjzd%2Fai-stats/lists"}