|
1 | 1 | # agenttop |
2 | 2 |
|
3 | | -`htop` for AI coding agents. See where your tokens and money actually go. |
| 3 | +`htop` for AI coding agents. |
4 | 4 |
|
5 | | - |
| 5 | +```bash |
| 6 | +git clone https://github.com/vicarious11/agenttop && cd agenttop && ./setup.sh |
| 7 | +./run.sh # localhost:8420 |
| 8 | +``` |
| 9 | + |
| 10 | + |
6 | 11 |
|
7 | | -## The problem |
| 12 | +Monitors **Claude Code**, **Cursor**, **Kiro**, **Codex**, **Copilot**. Reads the local files they already write (`~/.claude/`, `~/.cursor/`, etc). Read-only. Nothing leaves your machine. |
8 | 13 |
|
9 | | -You use Claude Code, Cursor, Copilot — maybe all three. You're spending $500+/month and have zero visibility. Each tool buries usage data in local files nobody reads. You don't know which sessions waste money, which model is overkill, or if you're even getting better at prompting. |
| 14 | +## what it does |
10 | 15 |
|
11 | | -## The fix |
| 16 | +- unified dashboard across all your AI coding tools |
| 17 | +- every session, every prompt, every token, every dollar — one place |
| 18 | +- search sessions by project, sort by cost, view full prompt history |
| 19 | +- AI analysis: scores you 0-100 on session hygiene, prompt quality, cost efficiency, cache usage, tool utilization |
| 20 | +- cost forensics: spend by project, by model, estimated waste from marathon sessions |
| 21 | +- detects anti-patterns: correction spirals, context blowup, repeated prompts, model overkill |
| 22 | + |
| 23 | +## install |
12 | 24 |
|
13 | 25 | ```bash |
14 | 26 | git clone https://github.com/vicarious11/agenttop && cd agenttop && ./setup.sh |
15 | | -./run.sh |
16 | | -# open localhost:8420 |
17 | 27 | ``` |
18 | 28 |
|
19 | | -That's it. Reads your local AI tool data. Shows everything in one dashboard. Nothing leaves your machine. |
| 29 | +or `pip install agenttop` |
20 | 30 |
|
21 | | -## What you get |
| 31 | +## run |
22 | 32 |
|
23 | | -**One dashboard for all your AI tools** — Claude Code, Cursor, Kiro, Codex, Copilot. Total tokens, total cost, session history, model usage, hourly patterns. All in one place. |
| 33 | +```bash |
| 34 | +./run.sh # web dashboard |
| 35 | +.venv/bin/agenttop # terminal dashboard |
| 36 | +agenttop init # set up LLM for analysis (ollama/anthropic/openai) |
| 37 | +``` |
24 | 38 |
|
25 | | -**Session-level analysis** — Browse every session. Search by project. Sort by cost. Click any session to see the full prompt history. Select sessions and run AI analysis to find correction spirals, wasted tokens, and bad prompting patterns. |
| 39 | +## data sources |
26 | 40 |
|
27 | | -**A score (0-100)** — Deterministic. Computed from 5 dimensions: session hygiene, prompt quality, cost efficiency, cache hit rate, tool utilization. Not vibes — actual data ratios. |
| 41 | +``` |
| 42 | +~/.claude/projects/**/*.jsonl exact token counts per message |
| 43 | +~/.cursor/ai-tracking/*.db conversations, models, AI vs human ratio |
| 44 | +~/.codex/.codex-global-state.json prompts, automations |
| 45 | +~/.config/github-copilot/ session state |
| 46 | +~/Library/.../Kiro/state.vscdb workspace data |
| 47 | +``` |
28 | 48 |
|
29 | | -**Cost forensics** — Which project burned the most money. Which model is overkill. How much you wasted in marathon sessions where context degraded. Dollar amounts, not percentages. |
| 49 | +## architecture |
30 | 50 |
|
31 | | -**Recommendations that reference your data** — "Session X cost $31 and had 3 correction spirals. Use /compact after 50 messages." Not generic tips. |
| 51 | +``` |
| 52 | + ┌──────────────────────────────────────────────┐ |
| 53 | + │ YOUR MACHINE (read-only) │ |
| 54 | + │ │ |
| 55 | + │ ~/.claude/ ~/.cursor/ ~/.codex/ ... │ |
| 56 | + └──────┬───────────┬────────────┬──────────────┘ |
| 57 | + │ │ │ |
| 58 | + ▼ ▼ ▼ |
| 59 | + ┌──────────────────────────────────────────────┐ |
| 60 | + │ COLLECTORS │ |
| 61 | + │ │ |
| 62 | + │ ClaudeCodeCollector → JSONL parser │ |
| 63 | + │ CursorCollector → SQLite + workspace │ |
| 64 | + │ KiroCollector → VS Code state DB │ |
| 65 | + │ CodexCollector → JSON + SQLite │ |
| 66 | + │ CopilotCollector → session JSON │ |
| 67 | + │ │ |
| 68 | + │ Each: collect_sessions() → list[Session] │ |
| 69 | + │ get_stats(days) → ToolStats │ |
| 70 | + └──────────────────┬───────────────────────────┘ |
| 71 | + │ |
| 72 | + ┌────────────┴────────────┐ |
| 73 | + ▼ ▼ |
| 74 | + ┌─────────────┐ ┌─────────────┐ |
| 75 | + │ WEB (D3) │ │ TUI (term) │ |
| 76 | + │ port 8420 │ │ textual │ |
| 77 | + │ │ │ │ |
| 78 | + │ FastAPI │ │ 5 tabs: │ |
| 79 | + │ WebSocket │ │ dashboard │ |
| 80 | + │ 3 tabs: │ │ sessions │ |
| 81 | + │ overview │ │ explorer │ |
| 82 | + │ sessions │ │ analysis │ |
| 83 | + │ analyze │ │ graph │ |
| 84 | + └──────┬──────┘ └──────────────┘ |
| 85 | + │ |
| 86 | + ▼ |
| 87 | + ┌──────────────────────────────────────┐ |
| 88 | + │ OPTIMIZER (map-reduce-generate) │ |
| 89 | + │ │ |
| 90 | + │ MAP: per-session LLM calls │ |
| 91 | + │ (cached, concurrent) │ |
| 92 | + │ intent, spirals, quality │ |
| 93 | + │ │ |
| 94 | + │ REDUCE: pure python, deterministic │ |
| 95 | + │ score 0-100, 5 dimensions │ |
| 96 | + │ cost forensics, anti-pats │ |
| 97 | + │ │ |
| 98 | + │ GENERATE: single LLM call │ |
| 99 | + │ profile, recs, insights │ |
| 100 | + │ │ |
| 101 | + │ LLM: ollama / anthropic / openai │ |
| 102 | + └──────────────────────────────────────┘ |
| 103 | +``` |
32 | 104 |
|
33 | | -## Install |
| 105 | +**collectors** parse tool-specific local files into a unified `Session` model (id, tool, project, messages, tokens, cost, prompts, timestamps). each collector handles one tool's quirks — JSONL for Claude, SQLite for Cursor, JSON blobs for Codex. |
34 | 106 |
|
35 | | -```bash |
36 | | -# from source (recommended) |
37 | | -git clone https://github.com/vicarious11/agenttop && cd agenttop && ./setup.sh |
| 107 | +**web dashboard** is vanilla JS + D3, no frameworks. FastAPI serves the API and static files. WebSocket for live updates. three tabs: overview (knowledge graph + panels), sessions (paginated browser with detail pane), analyze (select sessions → LLM analysis → score + cost forensics + recommendations). |
38 | 108 |
|
39 | | -# or pip |
40 | | -pip install agenttop |
41 | | -``` |
| 109 | +**TUI** is built on textual. plotext for charts. five tabs: dashboard (stats + charts), sessions (project aggregates + history), explorer (interactive search/select/analyze), analysis (model usage + intent distribution), graph (tree view). |
42 | 110 |
|
43 | | -## Run |
| 111 | +**optimizer** is the interesting part. three phases: |
44 | 112 |
|
45 | | -```bash |
46 | | -./run.sh # web dashboard at localhost:8420 |
47 | | -.venv/bin/agenttop # terminal dashboard |
48 | | -agenttop init # configure LLM for AI analysis |
49 | | -``` |
| 113 | +1. **MAP** — takes your top 30 sessions (by cost), sends each to an LLM with full prompt history. classifies: intent (debugging/greenfield/exploration/...), had correction spirals?, prompt quality, wasted effort. results cached per session ID at `~/.agenttop/session_cache.json` — sessions are immutable so they're never re-analyzed. max 10 new sessions per run. concurrent: 1 worker for ollama, 4 for cloud. |
50 | 114 |
|
51 | | -## How it works |
| 115 | +2. **REDUCE** — pure python. no LLM. computes a deterministic score from 5 dimensions (0-20 points each): |
| 116 | + - session hygiene: `sessions_without_spirals / total × 20` |
| 117 | + - prompt quality: `sessions_without_waste / total × 20` |
| 118 | + - cost efficiency: `(1 - waste_pct/100) × 20` |
| 119 | + - cache efficiency: `cache_hit_rate/100 × 20` |
| 120 | + - tool utilization: `features_used/features_available × 20` |
52 | 121 |
|
53 | | -Reads local files your tools already create. Read-only. No API keys needed. No Docker. No cloud. |
| 122 | + also computes cost forensics (spend by project, by model, waste estimation from marathon sessions) and anti-pattern counts. |
54 | 123 |
|
55 | | -``` |
56 | | -~/.claude/projects/**/*.jsonl → Claude Code sessions, tokens, costs |
57 | | -~/.cursor/ai-tracking/*.db → Cursor conversations, models, code stats |
58 | | -~/.codex/.codex-global-state.json → Codex prompts, automations |
59 | | -~/.config/github-copilot/ → Copilot session state |
60 | | -~/Library/.../Kiro/state.vscdb → Kiro workspace data |
61 | | - | |
62 | | - v |
63 | | - agenttop (localhost:8420) |
64 | | - | |
65 | | - v |
66 | | - dashboard + AI analysis (optional, local Ollama or cloud LLM) |
| 124 | +3. **GENERATE** — single LLM call with ~2K tokens of pre-computed metrics. LLM writes prose (developer profile, recommendations, project insights). it does NOT compute any numbers — those come from REDUCE. |
| 125 | + |
| 126 | +the score is fully traceable. "session hygiene: 14/20 — 23/30 sessions had no correction spirals." not a vibe check. |
| 127 | + |
| 128 | +## API |
| 129 | + |
| 130 | +| endpoint | what | |
| 131 | +|----------|------| |
| 132 | +| `GET /api/stats?days=N` | aggregated stats from all collectors | |
| 133 | +| `GET /api/sessions?days=N` | all sessions (paginated client-side) | |
| 134 | +| `GET /api/sessions/{id}` | full session detail with prompts | |
| 135 | +| `GET /api/models` | claude model usage (input/output/cache) | |
| 136 | +| `GET /api/hours` | hourly token distribution | |
| 137 | +| `GET /api/graph` | D3-compatible knowledge graph | |
| 138 | +| `POST /api/analyze-sessions` | LLM analysis on selected sessions | |
| 139 | +| `POST /api/optimize` | full optimizer pipeline | |
| 140 | +| `GET /api/optimize-stream` | SSE streaming progress + result | |
| 141 | +| `WS /ws` | real-time stat updates | |
| 142 | + |
| 143 | +## config |
| 144 | + |
| 145 | +zero config by default. `agenttop init` for interactive setup, or: |
| 146 | + |
| 147 | +```toml |
| 148 | +# ~/.agenttop/config.toml |
| 149 | +[llm] |
| 150 | +provider = "ollama" # ollama | anthropic | openai | openrouter |
| 151 | +model = "ollama/gemma3:4b" |
| 152 | +map_concurrency = 0 # 0 = auto |
67 | 153 | ``` |
68 | 154 |
|
69 | | -## No telemetry |
| 155 | +## no telemetry |
70 | 156 |
|
71 | | -Zero. Your data stays on your machine. If you use Ollama for analysis, nothing leaves your laptop at all. |
| 157 | +zero. local only. ollama = nothing leaves your machine. |
72 | 158 |
|
73 | | -## License |
| 159 | +## license |
74 | 160 |
|
75 | 161 | Apache 2.0 |
0 commit comments