English | ไธญๆ | ๆฅๆฌ่ช | Franรงais | Espaรฑol | ุงูุนุฑุจูุฉ | ํ๊ตญ์ด | Portuguรชs | ะ ัััะบะธะน | Deutsch
๐ What is your AI agent actually doing? Track costs, tokens, tool health, and every conversation โ locally, in seconds.
npx @liangzhengtao/agent-trace ย ยทย No API keys ย ยทย No cloud services ย ยทย 100% local
๐ Table of Contents
Your AI coding agent runs for hours. It calls tools, burns tokens, retries failed operations. But you have no idea:
- ๐ธ How much it actually cost
- ๐ง Which tools keep failing
- ๐ Why it retried 15 times
- ๐ Whether the model was slow or the tools were broken
- โฑ๏ธ How long each conversation took
npx @liangzhengtao/agent-traceOne command. No API keys. No cloud services. Everything runs locally.
# Install
npm install -g @liangzhengtao/agent-trace
# Auto-detect and analyze all sessions
agent-trace
# Analyze Kimi Code sessions
agent-trace -a kimi-code
# Analyze Claude Code sessions
agent-trace -a claude-code
# Show top 10 most expensive sessions
agent-trace -n 10
# Output as JSON
agent-trace --json ๐ Summary
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Sessions: 64
Total Cost: $4681.95
Total Tokens: 2,323,222,286
Total Messages: 3256
Total Tools: 11570
Total Time: 1593h 49m
๐ฐ Top 5 Most Expensive Sessions
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Rank Session ID Cost Tokens Messages
โโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโ โโโโโโโโ โโโโโโโโ
1 session_37ce506c-ecbd-4ac9- $1517.15 757,285,306 1177
2 session_bd1b6c0e-a4cc-402c- $1210.12 596,458,795 508
3 session_daecc013-3b5b-44a8- $1080.48 538,333,781 489
๐ Agent Trace Report
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Session Overview
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Duration: 45m 23s
Messages: 127 (User: 32, AI: 64, Tool: 31)
Tool Calls: 89 (12 unique tools)
Errors: 3
Retries: 2
๐ฐ Cost Analysis
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Input Tokens: 245,891 ($0.0738)
Output Tokens: 89,234 ($0.1339)
Total Tokens: 335,125
Estimated Cost: $0.2076
๐ง Tool Health
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Read โโโโโโโโโโโโโโโโโโโโ 100% (45 calls, avg 120ms)
โ Write โโโโโโโโโโโโโโโโโโโโ 100% (23 calls, avg 85ms)
โ Bash โโโโโโโโโโโโโโโโโโโโ 75% (12 calls, avg 2s)
โ Browser โโโโโโโโโโโโโโโโโโโโ 44% (9 calls, avg 5s)
โ ๏ธ Anomalies
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ High tool failure rate: 18/89
โ High estimated cost: $5.23
โฑ๏ธ Active Periods
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
09:15:23 โ 09:47:56 (32m 33s, 45 messages)
10:02:11 โ 10:31:44 (29m 33s, 52 messages)
๐ฌ Conversation
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
[YOU] Fix the authentication bug... 10:31:12
[AI ] I'll check the auth middleware... 10:31:14 (+2s)
[YOU] What about the token validation? 10:31:30 (+16s)
[AI ] Fixed. The issue was... 10:31:44 (+14s)
agent-trace [options] [directory]
Options:
-s, --session <id> Analyze specific session
-j, --json Output as JSON
-v, --verbose Show detailed timeline
-a, --agent <name> Agent type (opencode, kimi-code, claude-code, codex)
-n, --top <n> Show top N sessions by cost (default: 5)
--all Show all sessions (including empty)
--list-agents List supported agents
-h, --help Display help
-V, --version Display version
| Agent | Status | Config Path |
|---|---|---|
| OpenCode | โ Supported | ~/.opencode/sessions/ |
| Claude Code | โ Supported | ~/.claude/projects/ |
| Kimi Code | โ Supported | ~/.kimi-code/sessions/ |
| Codex | โ Supported | ~/.codex/sessions/ |
| Cursor | ๐ Coming soon | โ |
| Windsurf | ๐ Coming soon | โ |
| Cline | ๐ Coming soon | โ |
| Continue | ๐ Coming soon | โ |
By default, agent-trace scans all known paths and auto-detects which agent you're using:
agent-trace # Auto-detect and analyze all sessionsagent-trace -a claude-code # Only analyze Claude Code
agent-trace -a kimi-code # Only analyze Kimi Code
agent-trace -a opencode # Only analyze OpenCode
agent-trace -a codex # Only analyze Codex# GitHub Actions - check agent costs
- name: Check agent costs
run: |
npx @liangzhengtao/agent-trace --json > trace.json
COST=$(jq '.costBreakdown.total.cost' trace.json)
if (( $(echo "$COST > 10" | bc -l) )); then
echo "Agent cost too high: $COST"
exit 1
fi- Reads local session files โ No network requests, no API calls
- Parses message history โ Extracts roles, tokens, timestamps
- Analyzes tool calls โ Tracks success/failure rates
- Calculates costs โ Based on standard API pricing
- Detects anomalies โ High retries, failures, costs
- Generates report โ Terminal output or JSON
- โ 100% local โ no data leaves your machine
- โ Read-only โ never modifies session files
- โ No API keys โ no external services
- โ No tracking โ no analytics, no telemetry
Contributions are welcome! Here's how to get started:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-thing - Commit your changes:
git commit -m 'feat: add amazing thing' - Push to the branch:
git push origin feature/amazing-thing - Open a Pull Request
See CONTRIBUTING.md for full guidelines.
MIT ยฉ Serennity007
Other tools by Serennity007:
| Repository | Description |
|---|---|
| agent-trace | ๐ Observe your AI agents โ costs, tokens, tool health |
Have a project to list here? Open a PR!
โญ Star this repo if Agent Trace helped you observe your AI agents!
First run with synthetic logs / ๅๆๆฅๅฟ้ฆๆฌก่ฟ่ก ยท Unreleased source fixes / ๆบ็ ๅๆด