Skip to content

Repository files navigation

English | δΈ­ζ–‡ | ζ—₯本θͺž | FranΓ§ais | EspaΓ±ol | Ψ§Ω„ΨΉΨ±Ψ¨ΩŠΨ© | ν•œκ΅­μ–΄ | PortuguΓͺs | Русский | Deutsch

Agent Trace Banner

npm versionnpm downloadsLicense: MITGitHub StarsNode version

πŸ” 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


Agent Trace Demo


πŸ“‘ Table of Contents

🧩 The Problem

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

πŸ’‘ The Solution

npx @liangzhengtao/agent-trace

One command. No API keys. No cloud services. Everything runs locally.


πŸš€ Quick Start

# Install
npm install -g 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

πŸ“Š What It Shows

πŸ“‹ Summary View (Multiple Sessions)

 πŸ“Š 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

πŸ” Session Detail

 πŸ” 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)

βš™οΈ Options

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

πŸ€– Supported Agents

AgentStatusConfig 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β€”

πŸ”„ Auto-Detection

By default, agent-trace scans all known paths and auto-detects which agent you're using:

agent-trace # Auto-detect and analyze all sessions

🎯 Force Specific Agent

agent-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

πŸ”§ CI Integration

# GitHub Actions - check agent costs
- name: Check agent costsrun: | 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

🧠 How It Works

  1. Reads local session files β€” No network requests, no API calls
  2. Parses message history β€” Extracts roles, tokens, timestamps
  3. Analyzes tool calls β€” Tracks success/failure rates
  4. Calculates costs β€” Based on standard API pricing
  5. Detects anomalies β€” High retries, failures, costs
  6. Generates report β€” Terminal output or JSON

πŸ”’ Privacy

  • βœ… 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

🀝 Contributing

Contributions are welcome! Here's how to get started:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-thing
  3. Commit your changes: git commit -m 'feat: add amazing thing'
  4. Push to the branch: git push origin feature/amazing-thing
  5. Open a Pull Request

See CONTRIBUTING.md for full guidelines.

Contributors

πŸ“– License

MIT Β© Serennity007


πŸ”— See Also

Other tools by Serennity007:

RepositoryDescription
agent-traceπŸ” Observe your AI agents β€” costs, tokens, tool health

Have a project to list here? Open a PR!


🌐 δΈ­ζ–‡η‰ˆζœ¬

README.zh.md


Footer wave

⭐ Star this repo if Agent Trace helped you observe your AI agents!

About

πŸ” Track AI agent costs, tokens, tool health. CLI for monitoring Claude, Cursor, Kimi Code sessions. npx @liangzhengtao/agent-trace

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages