agentic-metric 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. agentic_metric-0.1.0/.gitignore +7 -0
  2. agentic_metric-0.1.0/LICENSE +21 -0
  3. agentic_metric-0.1.0/PKG-INFO +151 -0
  4. agentic_metric-0.1.0/README-CN.md +123 -0
  5. agentic_metric-0.1.0/README.md +123 -0
  6. agentic_metric-0.1.0/pyproject.toml +44 -0
  7. agentic_metric-0.1.0/src/agentic_metric/__init__.py +3 -0
  8. agentic_metric-0.1.0/src/agentic_metric/__main__.py +6 -0
  9. agentic_metric-0.1.0/src/agentic_metric/cli.py +230 -0
  10. agentic_metric-0.1.0/src/agentic_metric/collectors/__init__.py +78 -0
  11. agentic_metric-0.1.0/src/agentic_metric/collectors/_process.py +67 -0
  12. agentic_metric-0.1.0/src/agentic_metric/collectors/claude_code.py +567 -0
  13. agentic_metric-0.1.0/src/agentic_metric/collectors/codex.py +375 -0
  14. agentic_metric-0.1.0/src/agentic_metric/collectors/cursor.py +369 -0
  15. agentic_metric-0.1.0/src/agentic_metric/collectors/opencode.py +387 -0
  16. agentic_metric-0.1.0/src/agentic_metric/collectors/vscode.py +476 -0
  17. agentic_metric-0.1.0/src/agentic_metric/config.py +31 -0
  18. agentic_metric-0.1.0/src/agentic_metric/models.py +97 -0
  19. agentic_metric-0.1.0/src/agentic_metric/pricing.py +108 -0
  20. agentic_metric-0.1.0/src/agentic_metric/store/__init__.py +5 -0
  21. agentic_metric-0.1.0/src/agentic_metric/store/aggregator.py +140 -0
  22. agentic_metric-0.1.0/src/agentic_metric/store/database.py +230 -0
  23. agentic_metric-0.1.0/src/agentic_metric/tui/__init__.py +1 -0
  24. agentic_metric-0.1.0/src/agentic_metric/tui/app.py +285 -0
  25. agentic_metric-0.1.0/src/agentic_metric/tui/styles.tcss +26 -0
  26. agentic_metric-0.1.0/src/agentic_metric/tui/widgets.py +87 -0
  27. agentic_metric-0.1.0/tests/__init__.py +0 -0
  28. agentic_metric-0.1.0/tests/test_collectors.py +63 -0
  29. agentic_metric-0.1.0/tests/test_pricing.py +47 -0
  30. agentic_metric-0.1.0/tests/test_store.py +95 -0
@@ -0,0 +1,7 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.egg-info/
4
+ dist/
5
+ build/
6
+ .pytest_cache/
7
+ *.db
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MrQianjinsi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,151 @@
1
+ Metadata-Version: 2.4
2
+ Name: agentic-metric
3
+ Version: 0.1.0
4
+ Summary: Agentic coding metric monitor — multi-agent, TUI, CLI
5
+ Project-URL: Homepage, https://github.com/MrQianjinsi/agentic_metric
6
+ Project-URL: Repository, https://github.com/MrQianjinsi/agentic_metric
7
+ Project-URL: Issues, https://github.com/MrQianjinsi/agentic_metric/issues
8
+ Author-email: MrQianjinsi <mrqianjinsi@gmail.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: ai,claude-code,codex,coding-agent,cursor,metrics,tui
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development :: Quality Assurance
22
+ Requires-Python: >=3.10
23
+ Requires-Dist: rich>=13.0.0
24
+ Requires-Dist: textual-plotext>=0.3.0
25
+ Requires-Dist: textual>=1.0.0
26
+ Requires-Dist: typer>=0.9.0
27
+ Description-Content-Type: text/markdown
28
+
29
+ # Agentic Metric
30
+
31
+ [中文文档](README-CN.md)
32
+
33
+ A local-only monitoring tool for AI coding agents. Track token usage and costs across Claude Code, Codex, Cursor, OpenCode, VS Code (Copilot Chat), and more — with a TUI dashboard and CLI.
34
+
35
+ **All data stays on your machine. No network requests, no telemetry, no data leaves your computer.** The tool only reads local agent data files (e.g. `~/.claude/`) and process info.
36
+
37
+ ## Features
38
+
39
+ - **Live monitoring** — Detect running agent processes, incremental JSONL session parsing
40
+ - **Cost estimation** — Estimated based on token usage and per-model pricing tables, not actual billing. Useful as a reference, but may differ from real costs due to caching discounts, plan-specific pricing, etc.
41
+ - **Today overview** — Sessions, token usage, and cost summary for the current day
42
+ - **Historical trends** — 30-day daily token/cost trends
43
+ - **TUI dashboard** — Terminal UI with 1-second live refresh, stacked token charts, and trend lines
44
+ - **Multi-agent** — Plugin architecture, supports Claude Code and Cursor, extensible
45
+
46
+ ## Data Sources
47
+
48
+ | Agent | Path | Data |
49
+ |-------|------|------|
50
+ | Claude Code | `~/.claude/projects/` | JSONL sessions, token usage, model, branch |
51
+ | Claude Code | `~/.claude/stats-cache.json` | Daily activity stats |
52
+ | Cursor | `~/.config/Cursor/User/globalStorage/state.vscdb` | Composer sessions, token usage, model |
53
+ | Cursor | Process detection | Running status, working directory |
54
+ | Codex | `~/.codex/sessions/` | JSONL sessions, token usage, model |
55
+ | VS Code | `~/.config/Code/User/workspaceStorage/*/chatSessions/` | Chat sessions (JSON + JSONL), token usage (JSONL only), model |
56
+ | VS Code | `~/.config/Code/User/globalStorage/emptyWindowChatSessions/` | Empty-window chat sessions |
57
+ | VS Code | Process detection | Running status, working directory |
58
+ | OpenCode | `~/.local/share/opencode/opencode.db` | SQLite sessions, messages, token usage, model |
59
+ | OpenCode | Process detection | Running status, active session matching |
60
+
61
+ All aggregated data is stored locally in `~/.local/share/agentic_metric/data.db` (SQLite).
62
+
63
+ ## Installation
64
+
65
+ ```bash
66
+ pip install agentic-metric
67
+ ```
68
+
69
+ ## Usage
70
+
71
+ ```bash
72
+ agentic-metric status # Show currently active agents
73
+ agentic-metric today # Today's usage overview
74
+ agentic-metric history # Historical trends (default 30 days)
75
+ agentic-metric history -d 7 # Last 7 days
76
+ agentic-metric sync # Force sync data to local database
77
+ agentic-metric tui # Launch TUI dashboard
78
+ agentic-metric bar # One-line summary for status bars
79
+ ```
80
+
81
+ ### Status Bar Integration
82
+
83
+ `agentic-metric bar` outputs a compact one-line summary (e.g. `AM: $1.23 | 4.5M`) for embedding into status bars like i3blocks, waybar, tmux, vim statusline, etc.
84
+
85
+ **i3blocks / waybar:**
86
+
87
+ ```ini
88
+ [agentic-metric]
89
+ command=agentic-metric bar
90
+ interval=60
91
+ ```
92
+
93
+ **tmux:**
94
+
95
+ ```tmux
96
+ set -g status-right '#(agentic-metric bar | head -1)'
97
+ set -g status-interval 60 # refresh every 60 seconds (default 15)
98
+ ```
99
+
100
+ **vim / neovim statusline:**
101
+
102
+ ```vim
103
+ set statusline+=%{system('agentic-metric\ bar\ \|\ head\ -1')}
104
+ " statusline refreshes on cursor move, mode change, etc.
105
+ " to force a periodic refresh, add a timer:
106
+ autocmd CursorHold * redrawstatus
107
+ set updatetime=60000 " trigger CursorHold after 60s idle
108
+ ```
109
+
110
+ ### TUI Keybindings
111
+
112
+ | Key | Action |
113
+ |-----|--------|
114
+ | `q` | Quit |
115
+ | `r` | Refresh data |
116
+ | `Tab` | Switch Dashboard / History tab |
117
+
118
+ ## Agent Data Coverage
119
+
120
+ Different agents expose different levels of local data. Here's what's available for each:
121
+
122
+ | Field | Claude Code | Codex | Cursor | VS Code (Copilot) | OpenCode |
123
+ |-------|:-----------:|:-----:|:------:|:-----------------:|:--------:|
124
+ | Session ID | ✓ JSONL | ✓ JSONL | ✓ composerId | ✓ sessionId | ✓ session table |
125
+ | Project path | ✓ JSONL | ✓ JSONL | ◐ partial (from bubble or conversationState) | ✓ workspace.json URI | ✓ session.directory (launch cwd) |
126
+ | Git branch | ✓ JSONL | ✓ JSONL | ✗ not stored | ✗ not stored | ✗ not stored |
127
+ | Model | ✓ JSONL | ✓ JSONL | ✓ modelConfig / bubble modelInfo | ✓ result.details (e.g. "Claude Haiku 4.5 • 1x") | ✓ message.modelID |
128
+ | Input tokens | ✓ per-message | ✓ cumulative | ◐ older versions only | ◐ JSONL format only | ✓ per-message |
129
+ | Output tokens | ✓ per-message | ✓ cumulative | ◐ older versions only | ◐ JSONL format only | ✓ per-message (includes reasoning) |
130
+ | Cache tokens | ✓ read + write | ✓ read only | ✗ not exposed | ✗ not exposed | ◐ read only (write always 0) |
131
+ | User turns | ✓ | ✓ | ✓ | ✓ | ✓ |
132
+ | Message count | ✓ all messages | ✓ AI replies only | ✓ all messages | ✓ turns × 2 | ✓ all messages |
133
+ | First/last prompt | ✓ | ✓ | ✓ from bubble text | ✓ message.text | ✓ from part table |
134
+ | Cost estimation | ✓ | ✓ | ◐ only when tokens available | ◐ only when tokens available | ◐ estimated only (reported cost always 0) |
135
+ | Live active status | ✓ PID + session file match | ✓ PID + session file match | ◐ process-level only (latest session marked active) | ◐ process-level only | ✓ PID + DB session match |
136
+
137
+ **Key differences:**
138
+
139
+ - **Claude Code & Codex** — Each running process maps to a JSONL session file with a unique session ID. This allows precise matching between live processes and DB sessions for accurate active status.
140
+ - **Cursor** — Live detection only sees the process PID, while historical sessions use composer UUIDs from `state.vscdb`. There is no way to link a running Cursor process to a specific composer session, so the most recent session is marked active when the process is running.
141
+ - **Token coverage** — Cursor stored per-bubble `tokenCount` (input/output) in `state.vscdb` in earlier versions (~2025-05 to ~2025-12), but newer versions no longer populate this field — all values are zero. Cursor appears to have moved usage tracking to a server-side system, so local token data is unavailable for recent sessions. Cache token breakdown (read/write) has never been available.
142
+ - **Model name** — Cursor's "default" model setting doesn't record which model was actually used on the backend. These sessions show `default` in the model column.
143
+ - **VS Code (Copilot Chat)** — Has two storage formats: legacy JSON (older sessions, no token data) and newer incremental JSONL (with `result.usage` containing `promptTokens`/`completionTokens`). Token usage is only available for sessions stored in JSONL format. Model names are extracted from Copilot's display strings (e.g. "GPT-4o • 1x") and normalized to pricing keys. Workspace paths support local (`file://`), SSH remote (`vscode-remote://ssh-remote+host`), and container (`attached-container+...`) URIs.
144
+ - **OpenCode** — Stores all data in a local SQLite database (`opencode.db`). Token data is per-message with `input`, `output`, `reasoning`, and `cache.read`/`cache.write` fields. Reasoning tokens are counted as output tokens (billed at output rate). The `cost` field in messages is always 0, so all costs are estimated using the pricing table. `cache.write` is also always 0.
145
+
146
+ ## Privacy
147
+
148
+ - **Fully offline** — no network requests, no data sent anywhere
149
+ - **Read-only** — never modifies agent config or data files
150
+ - All stats stored in a local SQLite database
151
+ - Delete `~/.local/share/agentic_metric/` at any time to remove all data
@@ -0,0 +1,123 @@
1
+ # Agentic Metric
2
+
3
+ [English](README.md)
4
+
5
+ 本地化的 AI coding agent 指标监控工具。追踪 Claude Code、Codex、Cursor、OpenCode、VS Code (Copilot Chat) 等 agent 的 token 用量和成本,提供 TUI 仪表盘和 CLI 命令。
6
+
7
+ **所有数据完全存储在本地,使用过程不会联网。** 工具仅读取本机的 agent 数据文件(如 `~/.claude/`)和进程信息,不发送任何数据到外部服务器。
8
+
9
+ ## 功能
10
+
11
+ - **实时监控** — 检测运行中的 agent 进程,增量解析 JSONL 会话数据
12
+ - **成本估算** — 基于 token 用量和各模型定价表估算,非实际账单费用。可作为参考,但可能因缓存折扣、套餐定价等因素与真实费用有差异
13
+ - **今日概览** — 当天的 session 数、token 用量、花费汇总
14
+ - **历史趋势** — 每日 token/成本的 30 天趋势
15
+ - **TUI 仪表盘** — 终端图形界面,实时刷新(1 秒),含 token 堆叠图和趋势折线图
16
+ - **多 Agent 支持** — 插件架构,已支持 Claude Code 和 Cursor,可扩展
17
+
18
+ ## 数据来源
19
+
20
+ | Agent | 数据路径 | 采集内容 |
21
+ |-------|---------|---------|
22
+ | Claude Code | `~/.claude/projects/` | JSONL 会话、token 用量、模型、分支 |
23
+ | Claude Code | `~/.claude/stats-cache.json` | 每日活动统计 |
24
+ | Cursor | `~/.config/Cursor/User/globalStorage/state.vscdb` | Composer 会话、token 用量、模型 |
25
+ | Cursor | 进程检测 | 运行状态、工作目录 |
26
+ | Codex | `~/.codex/sessions/` | JSONL 会话、token 用量、模型 |
27
+ | VS Code | `~/.config/Code/User/workspaceStorage/*/chatSessions/` | 聊天会话(JSON + JSONL)、token 用量(仅 JSONL)、模型 |
28
+ | VS Code | `~/.config/Code/User/globalStorage/emptyWindowChatSessions/` | 空窗口聊天会话 |
29
+ | VS Code | 进程检测 | 运行状态、工作目录 |
30
+ | OpenCode | `~/.local/share/opencode/opencode.db` | SQLite 会话、消息、token 用量、模型 |
31
+ | OpenCode | 进程检测 | 运行状态、活跃会话匹配 |
32
+
33
+ 所有数据汇总存储在 `~/.local/share/agentic_metric/data.db`(SQLite)。
34
+
35
+ ## 安装
36
+
37
+ ```bash
38
+ pip install agentic-metric
39
+ ```
40
+
41
+ ## 使用
42
+
43
+ ```bash
44
+ agentic-metric status # 查看当前活跃的 agent
45
+ agentic-metric today # 今日用量概览
46
+ agentic-metric history # 历史趋势(默认 30 天)
47
+ agentic-metric history -d 7 # 最近 7 天
48
+ agentic-metric sync # 强制同步数据到本地数据库
49
+ agentic-metric tui # 启动 TUI 仪表盘
50
+ agentic-metric bar # 单行摘要,用于状态栏集成
51
+ ```
52
+
53
+ ### 状态栏集成
54
+
55
+ `agentic-metric bar` 输出紧凑的单行摘要(如 `AM: $1.23 | 4.5M`),可嵌入 i3blocks、waybar、tmux、vim statusline 等状态栏。
56
+
57
+ **i3blocks / waybar:**
58
+
59
+ ```ini
60
+ [agentic-metric]
61
+ command=agentic-metric bar
62
+ interval=60
63
+ ```
64
+
65
+ **tmux:**
66
+
67
+ ```tmux
68
+ set -g status-right '#(agentic-metric bar | head -1)'
69
+ set -g status-interval 60 # 每 60 秒刷新一次(默认 15 秒)
70
+ ```
71
+
72
+ **vim / neovim statusline:**
73
+
74
+ ```vim
75
+ set statusline+=%{system('agentic-metric\ bar\ \|\ head\ -1')}
76
+ " statusline 在光标移动、模式切换等事件时自动刷新
77
+ " 如需定时刷新,可添加 timer:
78
+ autocmd CursorHold * redrawstatus
79
+ set updatetime=60000 " 空闲 60 秒后触发 CursorHold
80
+ ```
81
+
82
+ ### TUI 快捷键
83
+
84
+ | 键 | 功能 |
85
+ |----|------|
86
+ | `q` | 退出 |
87
+ | `r` | 刷新数据 |
88
+ | `Tab` | 切换 Dashboard / History 标签页 |
89
+
90
+ ## 各 Agent 统计口径差异
91
+
92
+ 不同 agent 在本地暴露的数据详细程度不同:
93
+
94
+ | 字段 | Claude Code | Codex | Cursor | VS Code (Copilot) | OpenCode |
95
+ |------|:-----------:|:-----:|:------:|:-----------------:|:--------:|
96
+ | 会话 ID | ✓ JSONL 文件 | ✓ JSONL 文件 | ✓ composerId | ✓ sessionId | ✓ session 表 |
97
+ | 项目路径 | ✓ | ✓ | ◐ 部分(从 bubble 或 conversationState 提取) | ✓ workspace.json URI | ✓ session.directory(启动目录) |
98
+ | Git 分支 | ✓ | ✓ | ✗ 不存储 | ✗ 不存储 | ✗ 不存储 |
99
+ | 模型名称 | ✓ | ✓ | ✓ 但 "default" 模式不记录实际模型 | ✓ result.details(如 "Claude Haiku 4.5 • 1x") | ✓ message.modelID |
100
+ | Input tokens | ✓ 逐条累加 | ✓ 累计值 | ◐ 仅旧版本 | ◐ 仅 JSONL 格式 | ✓ 逐条累加 |
101
+ | Output tokens | ✓ 逐条累加 | ✓ 累计值 | ◐ 仅旧版本 | ◐ 仅 JSONL 格式 | ✓ 逐条累加(含 reasoning) |
102
+ | Cache tokens | ✓ 读+写 | ✓ 仅读 | ✗ 不暴露 | ✗ 不暴露 | ◐ 仅读(write 始终为 0) |
103
+ | 用户轮次 | ✓ | ✓ | ✓ | ✓ | ✓ |
104
+ | 消息总数 | ✓ 所有消息 | ✓ 仅 AI 回复 | ✓ 所有消息 | ✓ 轮次 × 2 | ✓ 所有消息 |
105
+ | 首条/末条 prompt | ✓ | ✓ | ✓ 从 bubble text 提取 | ✓ message.text | ✓ 从 part 表提取 |
106
+ | 成本估算 | ✓ | ✓ | ◐ 仅在有 token 数据时可估算 | ◐ 仅在有 token 数据时可估算 | ◐ 全部为估算(上报 cost 始终为 0) |
107
+ | 实时活跃状态 | ✓ PID + 会话文件精确匹配 | ✓ PID + 会话文件精确匹配 | ◐ 仅进程级检测(标记最新会话为活跃) | ◐ 仅进程级检测 | ✓ PID + DB 会话匹配 |
108
+
109
+ **主要差异说明:**
110
+
111
+ - **Claude Code 和 Codex** — 每个运行中的进程对应一个 JSONL 会话文件,文件内含唯一 session ID,因此可以精确匹配 live 进程和数据库会话。
112
+ - **Cursor** — 实时检测只能获取进程 PID,而历史会话使用 `state.vscdb` 中的 composer UUID。两者无法关联,因此仅在 Cursor 进程运行时将最新会话标记为活跃。
113
+ - **Token 覆盖率** — Cursor 在早期版本(约 2025-05 至 2025-12)会在 `state.vscdb` 的 bubble 数据中记录 `tokenCount`(input/output),但新版本不再填充该字段(值始终为 0)。Cursor 已将用量追踪迁移至服务端,近期会话的本地 token 数据不可用。Cache token 细分(读/写)从未可用。
114
+ - **模型名称** — Cursor 的 "default" 模型设置不记录后端实际使用的模型,这类会话在模型列显示为 `default`。
115
+ - **VS Code (Copilot Chat)** — 存在两种存储格式:旧版 JSON(无 token 数据)和新版增量 JSONL(含 `result.usage`,包括 `promptTokens`/`completionTokens`)。Token 用量仅在 JSONL 格式的会话中可用。模型名称从 Copilot 的显示字符串(如 "GPT-4o • 1x")提取并归一化为定价键。工作区路径支持本地(`file://`)、SSH 远程(`vscode-remote://ssh-remote+host`)和容器(`attached-container+...`)URI。
116
+ - **OpenCode** — 数据存储在本地 SQLite 数据库(`opencode.db`)。Token 数据按消息粒度记录,包含 `input`、`output`、`reasoning` 和 `cache.read`/`cache.write` 字段。Reasoning tokens 计入 output tokens(按 output 费率计费)。消息中的 `cost` 字段始终为 0,因此所有成本均通过定价表估算。`cache.write` 也始终为 0。
117
+
118
+ ## 隐私
119
+
120
+ - 不联网,不发送任何数据
121
+ - 不修改 agent 的配置或数据文件(只读)
122
+ - 所有统计数据存储在本地 SQLite 数据库
123
+ - 可随时删除 `~/.local/share/agentic_metric/` 清除所有数据
@@ -0,0 +1,123 @@
1
+ # Agentic Metric
2
+
3
+ [中文文档](README-CN.md)
4
+
5
+ A local-only monitoring tool for AI coding agents. Track token usage and costs across Claude Code, Codex, Cursor, OpenCode, VS Code (Copilot Chat), and more — with a TUI dashboard and CLI.
6
+
7
+ **All data stays on your machine. No network requests, no telemetry, no data leaves your computer.** The tool only reads local agent data files (e.g. `~/.claude/`) and process info.
8
+
9
+ ## Features
10
+
11
+ - **Live monitoring** — Detect running agent processes, incremental JSONL session parsing
12
+ - **Cost estimation** — Estimated based on token usage and per-model pricing tables, not actual billing. Useful as a reference, but may differ from real costs due to caching discounts, plan-specific pricing, etc.
13
+ - **Today overview** — Sessions, token usage, and cost summary for the current day
14
+ - **Historical trends** — 30-day daily token/cost trends
15
+ - **TUI dashboard** — Terminal UI with 1-second live refresh, stacked token charts, and trend lines
16
+ - **Multi-agent** — Plugin architecture, supports Claude Code and Cursor, extensible
17
+
18
+ ## Data Sources
19
+
20
+ | Agent | Path | Data |
21
+ |-------|------|------|
22
+ | Claude Code | `~/.claude/projects/` | JSONL sessions, token usage, model, branch |
23
+ | Claude Code | `~/.claude/stats-cache.json` | Daily activity stats |
24
+ | Cursor | `~/.config/Cursor/User/globalStorage/state.vscdb` | Composer sessions, token usage, model |
25
+ | Cursor | Process detection | Running status, working directory |
26
+ | Codex | `~/.codex/sessions/` | JSONL sessions, token usage, model |
27
+ | VS Code | `~/.config/Code/User/workspaceStorage/*/chatSessions/` | Chat sessions (JSON + JSONL), token usage (JSONL only), model |
28
+ | VS Code | `~/.config/Code/User/globalStorage/emptyWindowChatSessions/` | Empty-window chat sessions |
29
+ | VS Code | Process detection | Running status, working directory |
30
+ | OpenCode | `~/.local/share/opencode/opencode.db` | SQLite sessions, messages, token usage, model |
31
+ | OpenCode | Process detection | Running status, active session matching |
32
+
33
+ All aggregated data is stored locally in `~/.local/share/agentic_metric/data.db` (SQLite).
34
+
35
+ ## Installation
36
+
37
+ ```bash
38
+ pip install agentic-metric
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ ```bash
44
+ agentic-metric status # Show currently active agents
45
+ agentic-metric today # Today's usage overview
46
+ agentic-metric history # Historical trends (default 30 days)
47
+ agentic-metric history -d 7 # Last 7 days
48
+ agentic-metric sync # Force sync data to local database
49
+ agentic-metric tui # Launch TUI dashboard
50
+ agentic-metric bar # One-line summary for status bars
51
+ ```
52
+
53
+ ### Status Bar Integration
54
+
55
+ `agentic-metric bar` outputs a compact one-line summary (e.g. `AM: $1.23 | 4.5M`) for embedding into status bars like i3blocks, waybar, tmux, vim statusline, etc.
56
+
57
+ **i3blocks / waybar:**
58
+
59
+ ```ini
60
+ [agentic-metric]
61
+ command=agentic-metric bar
62
+ interval=60
63
+ ```
64
+
65
+ **tmux:**
66
+
67
+ ```tmux
68
+ set -g status-right '#(agentic-metric bar | head -1)'
69
+ set -g status-interval 60 # refresh every 60 seconds (default 15)
70
+ ```
71
+
72
+ **vim / neovim statusline:**
73
+
74
+ ```vim
75
+ set statusline+=%{system('agentic-metric\ bar\ \|\ head\ -1')}
76
+ " statusline refreshes on cursor move, mode change, etc.
77
+ " to force a periodic refresh, add a timer:
78
+ autocmd CursorHold * redrawstatus
79
+ set updatetime=60000 " trigger CursorHold after 60s idle
80
+ ```
81
+
82
+ ### TUI Keybindings
83
+
84
+ | Key | Action |
85
+ |-----|--------|
86
+ | `q` | Quit |
87
+ | `r` | Refresh data |
88
+ | `Tab` | Switch Dashboard / History tab |
89
+
90
+ ## Agent Data Coverage
91
+
92
+ Different agents expose different levels of local data. Here's what's available for each:
93
+
94
+ | Field | Claude Code | Codex | Cursor | VS Code (Copilot) | OpenCode |
95
+ |-------|:-----------:|:-----:|:------:|:-----------------:|:--------:|
96
+ | Session ID | ✓ JSONL | ✓ JSONL | ✓ composerId | ✓ sessionId | ✓ session table |
97
+ | Project path | ✓ JSONL | ✓ JSONL | ◐ partial (from bubble or conversationState) | ✓ workspace.json URI | ✓ session.directory (launch cwd) |
98
+ | Git branch | ✓ JSONL | ✓ JSONL | ✗ not stored | ✗ not stored | ✗ not stored |
99
+ | Model | ✓ JSONL | ✓ JSONL | ✓ modelConfig / bubble modelInfo | ✓ result.details (e.g. "Claude Haiku 4.5 • 1x") | ✓ message.modelID |
100
+ | Input tokens | ✓ per-message | ✓ cumulative | ◐ older versions only | ◐ JSONL format only | ✓ per-message |
101
+ | Output tokens | ✓ per-message | ✓ cumulative | ◐ older versions only | ◐ JSONL format only | ✓ per-message (includes reasoning) |
102
+ | Cache tokens | ✓ read + write | ✓ read only | ✗ not exposed | ✗ not exposed | ◐ read only (write always 0) |
103
+ | User turns | ✓ | ✓ | ✓ | ✓ | ✓ |
104
+ | Message count | ✓ all messages | ✓ AI replies only | ✓ all messages | ✓ turns × 2 | ✓ all messages |
105
+ | First/last prompt | ✓ | ✓ | ✓ from bubble text | ✓ message.text | ✓ from part table |
106
+ | Cost estimation | ✓ | ✓ | ◐ only when tokens available | ◐ only when tokens available | ◐ estimated only (reported cost always 0) |
107
+ | Live active status | ✓ PID + session file match | ✓ PID + session file match | ◐ process-level only (latest session marked active) | ◐ process-level only | ✓ PID + DB session match |
108
+
109
+ **Key differences:**
110
+
111
+ - **Claude Code & Codex** — Each running process maps to a JSONL session file with a unique session ID. This allows precise matching between live processes and DB sessions for accurate active status.
112
+ - **Cursor** — Live detection only sees the process PID, while historical sessions use composer UUIDs from `state.vscdb`. There is no way to link a running Cursor process to a specific composer session, so the most recent session is marked active when the process is running.
113
+ - **Token coverage** — Cursor stored per-bubble `tokenCount` (input/output) in `state.vscdb` in earlier versions (~2025-05 to ~2025-12), but newer versions no longer populate this field — all values are zero. Cursor appears to have moved usage tracking to a server-side system, so local token data is unavailable for recent sessions. Cache token breakdown (read/write) has never been available.
114
+ - **Model name** — Cursor's "default" model setting doesn't record which model was actually used on the backend. These sessions show `default` in the model column.
115
+ - **VS Code (Copilot Chat)** — Has two storage formats: legacy JSON (older sessions, no token data) and newer incremental JSONL (with `result.usage` containing `promptTokens`/`completionTokens`). Token usage is only available for sessions stored in JSONL format. Model names are extracted from Copilot's display strings (e.g. "GPT-4o • 1x") and normalized to pricing keys. Workspace paths support local (`file://`), SSH remote (`vscode-remote://ssh-remote+host`), and container (`attached-container+...`) URIs.
116
+ - **OpenCode** — Stores all data in a local SQLite database (`opencode.db`). Token data is per-message with `input`, `output`, `reasoning`, and `cache.read`/`cache.write` fields. Reasoning tokens are counted as output tokens (billed at output rate). The `cost` field in messages is always 0, so all costs are estimated using the pricing table. `cache.write` is also always 0.
117
+
118
+ ## Privacy
119
+
120
+ - **Fully offline** — no network requests, no data sent anywhere
121
+ - **Read-only** — never modifies agent config or data files
122
+ - All stats stored in a local SQLite database
123
+ - Delete `~/.local/share/agentic_metric/` at any time to remove all data
@@ -0,0 +1,44 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "agentic-metric"
7
+ version = "0.1.0"
8
+ description = "Agentic coding metric monitor — multi-agent, TUI, CLI"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.10"
12
+ authors = [
13
+ { name = "MrQianjinsi", email = "mrqianjinsi@gmail.com" },
14
+ ]
15
+ keywords = ["ai", "coding-agent", "metrics", "tui", "claude-code", "cursor", "codex"]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Environment :: Console",
19
+ "Intended Audience :: Developers",
20
+ "License :: OSI Approved :: MIT License",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Programming Language :: Python :: 3.13",
26
+ "Topic :: Software Development :: Quality Assurance",
27
+ ]
28
+ dependencies = [
29
+ "textual>=1.0.0",
30
+ "textual-plotext>=0.3.0",
31
+ "rich>=13.0.0",
32
+ "typer>=0.9.0",
33
+ ]
34
+
35
+ [project.urls]
36
+ Homepage = "https://github.com/MrQianjinsi/agentic_metric"
37
+ Repository = "https://github.com/MrQianjinsi/agentic_metric"
38
+ Issues = "https://github.com/MrQianjinsi/agentic_metric/issues"
39
+
40
+ [project.scripts]
41
+ agentic-metric = "agentic_metric.cli:app"
42
+
43
+ [tool.hatch.build.targets.wheel]
44
+ packages = ["src/agentic_metric"]
@@ -0,0 +1,3 @@
1
+ """Agentic Metric — multi-agent coding metric monitor."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,6 @@
1
+ """Entry point: python -m agentic_metric."""
2
+
3
+ from .cli import app
4
+
5
+ if __name__ == "__main__":
6
+ app()