้•œๅƒ็ซ™็‚น ยท ๆœฌ้กต็”ฑ็ฌฌไธ‰ๆ–น GitHub ๅช่ฏป้•œๅƒๆไพ›๏ผŒ้ž GitHub ๅฎ˜ๆ–น็ซ™็‚น๏ผŒไธๆŽฅๅ—ไปปไฝ•็™ปๅฝ•ๆˆ–ๅ‡ญๆฎ่พ“ๅ…ฅใ€‚ๅ‰ๅพ€ github.com
Skip to content

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

1 star

Watchers

0 watching

Forks

Latest commit

ย 

History

20 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

English | ไธญๆ–‡ | ๆ—ฅๆœฌ่ชž | Franรงais | Espaรฑol | ุงู„ุนุฑุจูŠุฉ | ํ•œ๊ตญ์–ด | Portuguรชs | ะ ัƒััะบะธะน | Deutsch

Agent Trace Banner

npm version npm downloads License: MIT GitHub Stars Node 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 @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

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

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 โ€”

๐Ÿ”„ 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 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

๐Ÿง  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:

Repository Description
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!

First run with synthetic logs / ๅˆๆˆๆ—ฅๅฟ—้ฆ–ๆฌก่ฟ่กŒ ยท Unreleased source fixes / ๆบ็ ๅ˜ๆ›ด

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

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages