Universal agent session tracing, replay, and analysis. Think "OpenTelemetry for AI agents" but lightweight and opinionated.
npx agentrace list --scan # Discover and list all agent sessions
npx agentrace stats --last 7d # Show analytics for last week
npx agentrace replay <session> # Step-by-step session replay
npx agentrace export <session> --format markdown # Export session reportWorks out of the box with Claude Code, Codex, OpenClaw, and more.
π― Zero config β Auto-detects agent sessions from known paths π Universal tracing β Supports Claude Code, Codex, OpenClaw, Cursor π Rich analytics β Cost tracking, pattern detection, success rates π¬ Session replay β Step-by-step visualization with file changes π° Cost analysis β Token usage and spend tracking by model/agent π Pattern detection β Identifies loops, failures, and inefficiencies π File tracking β Monitor code changes across sessions π MCP server β Query your session history programmatically π Export formats β Markdown, JSON, HTML reports ποΈ Local-first β SQLite storage, no cloud dependencies
npx agentrace --helpnpm install -g agentrace
agentrace --helpbrew install agentraceList and discover agent sessions.
agentrace list # Last 7 days
agentrace list --last 30d # Last 30 days
agentrace list --agent claude-code # Filter by agent
agentrace list --status completed # Filter by status
agentrace list --scan # Scan for new sessions first
agentrace list --json # JSON outputOptions:
--agent <name>- Filter by agent: claude-code, codex, openclaw, cursor--last <duration>- Time period: 7d, 2w, 1m (default: 7d)--status <status>- Filter by: running, completed, failed, abandoned--limit <number>- Max sessions to show (default: 50)--working-dir <path>- Filter by working directory--scan- Scan filesystem for new sessions first--json- Output as JSON
Watch a live or recent session in real-time.
agentrace watch # Watch most recent active session
agentrace watch --agent claude-code # Watch latest claude-code session
agentrace watch --session abc123 # Watch specific sessionOptions:
--agent <name>- Filter by agent type--session <id>- Watch specific session ID--follow- Follow updates in real-time (default: true)--interval <ms>- Polling interval (default: 2000ms)
Step-by-step replay with rich terminal output.
agentrace replay abc123 # Normal speed replay
agentrace replay abc123 --speed 5 # 5x speed
agentrace replay abc123 --step # Manual stepping
agentrace replay abc123 --filter tool_call # Filter event typesOptions:
--speed <1-10>- Playback speed multiplier (default: 3)--filter <type>- Filter events: tool_call, message, error, etc.--from <timestamp>- Start from specific time--to <timestamp>- End at specific time--step- Manual stepping (press Enter)--detailed- Show full event content
Analytics dashboard with session statistics.
agentrace stats # Last 7 days overview
agentrace stats --last 30d --costs # Include cost breakdown
agentrace stats --agent claude-code # Agent-specific stats
agentrace stats --by model --patterns # Group by model, show patternsOptions:
--last <duration>- Time period (default: 7d)--agent <name>- Filter by agent type--by <grouping>- Group by: day, week, agent, model (default: agent)--costs- Include detailed cost breakdown--patterns- Include pattern analysis (loops, failures)--json- Output as JSON
Side-by-side comparison of two sessions.
agentrace diff abc123 def456 # Compare two sessions
agentrace diff abc123 def456 --files # Include file changes
agentrace diff abc123 def456 --json # JSON outputOptions:
--metrics-only- Show only metrics, not detailed events--events- Include detailed event comparison--files- Include file change comparison--json- Output as JSON
Export session as shareable document.
agentrace export abc123 # Export as Markdown
agentrace export abc123 --format html # Export as HTML
agentrace export abc123 --format json --detailed # Detailed JSON
agentrace export abc123 --output report.md # Custom filenameOptions:
--format <format>- Output format: markdown, json, html (default: markdown)--output <file>- Output file path--include-costs- Include cost analysis--include-patterns- Include pattern analysis--include-timeline- Include detailed timeline--detailed- Include full event content
Start MCP server for programmatic access.
agentrace serve # Start on port 3000
agentrace serve --port 8080 # Custom port
agentrace serve --auto-scan # Auto-discover sessionsOptions:
--port <port>- Port to listen on (default: 3000)--auto-scan- Scan for sessions on startup--scan-interval <minutes>- Auto-scan interval (default: 0/disabled)
Status: β
Full support
Location: ~/.claude/projects/*/sessions/
Format: JSONL files with tool_use blocks
Status: β
Full support
Location: ~/.codex/sessions/
Format: JSON conversation logs
Status: β
Full support
Location: ~/.openclaw/sessions/, ./data/sessions
Format: JSON log files
Status: π§ Placeholder (format TBD)
Location: ~/.cursor/logs/
Format: Log format not yet documented
Want to add support for your agent? See the adapter guide.
Start the MCP server to query session data programmatically:
agentrace serve --port 3000query_sessions - Search and filter sessions
{
"name": "query_sessions",
"arguments": {
"agent": "claude-code",
"status": "completed",
"since": "2024-01-01",
"limit": 10
}
}get_timeline - Get session event timeline
{
"name": "get_timeline",
"arguments": {
"session_id": "abc123",
"include_content": false
}
}get_stats - Aggregate statistics
{
"name": "get_stats",
"arguments": {
"agent": "claude-code",
"since": "2024-01-01",
"include_patterns": true
}
}get_file_changes - File modification history
{
"name": "get_file_changes",
"arguments": {
"session_id": "abc123",
"change_type": "modify"
}
}scan_for_sessions - Discover new sessions
{
"name": "scan_for_sessions",
"arguments": {
"agent": "claude-code",
"force_rescan": false
}
}agentrace uses SQLite with the following schema:
Sessions - High-level session metadata
CREATE TABLE sessions (
id TEXT PRIMARY KEY,
agent TEXT NOT NULL,
started_at TEXT NOT NULL,
ended_at TEXT,
status TEXT DEFAULT 'running',
prompt TEXT,
working_dir TEXT,
total_tokens INTEGER DEFAULT 0,
estimated_cost_usd REAL DEFAULT 0,
model TEXT
);Events - Individual session events (tool calls, messages, etc.)
CREATE TABLE events (
id INTEGER PRIMARY KEY AUTOINCREMENT,
session_id TEXT NOT NULL,
timestamp TEXT NOT NULL,
type TEXT NOT NULL, -- 'tool_call', 'message', 'error', etc.
name TEXT,
content TEXT,
duration_ms INTEGER,
tokens INTEGER
);File Changes - Code modifications tracked per session
CREATE TABLE file_changes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
session_id TEXT NOT NULL,
file_path TEXT NOT NULL,
change_type TEXT NOT NULL, -- 'create', 'modify', 'delete'
diff TEXT,
lines_added INTEGER DEFAULT 0,
lines_removed INTEGER DEFAULT 0
);Data is stored in ~/.agentrace/agentrace.db by default.
# Generate comprehensive weekly report
agentrace stats --last 7d --costs --patterns > weekly-report.txt
agentrace list --last 7d --json > sessions.json# Track spend by agent and model
agentrace stats --by model --costs
agentrace stats --agent claude-code --last 30d --costs# Find and analyze failures
agentrace list --status failed --last 30d
agentrace replay <failed-session-id> --filter error
agentrace export <failed-session-id> --format markdown# Compare two different implementation approaches
agentrace diff session-A session-B --files# Monitor active session
agentrace watch --followNo configuration files needed! agentrace auto-detects agent installations and uses sensible defaults.
Environment Variables:
AGENTRACE_DB_PATH- Custom database locationAGENTRACE_LOG_LEVEL- Logging: debug, info, warn, error
# Force scan for new sessions
agentrace list --scan
# Check if agent directories exist
ls ~/.claude/projects/
ls ~/.codex/sessions/# Limit query scope
agentrace list --last 7d --limit 20
# Use JSON for faster processing
agentrace stats --json | jq '.basic_stats'# Reset database (WARNING: deletes all data)
rm ~/.agentrace/agentrace.db
agentrace list --scanWe welcome contributions! Please see CONTRIBUTING.md for guidelines.
To add support for a new agent, implement the AgentAdapter interface:
export class MyAgentAdapter implements AgentAdapter {
name = 'my-agent';
detect(): boolean {
// Return true if agent is installed
}
findSessions(): string[] {
// Return array of session file paths
}
parseSession(sessionPath: string): ParsedSession | null {
// Parse session file into standard format
}
}Full adapter development guide
- FastMCP - Python MCP framework
- MCP SDK - TypeScript MCP framework
- Claude Code - AI coding assistant
- OpenTelemetry - Observability framework inspiration
MIT License - see LICENSE file for details.
Built with β€οΈ by the agentrace team Making AI agents observable, one session at a time.
π Report Bug β’ π‘ Request Feature β’ π Docs β’ π¬ Discussions