Analyzes Claude Code conversation history to identify token optimization opportunities and generate helper scripts
npm install agent-trace-opsagent-trace-ops (ato) analyzes your conversation’s tool-call chains and auto-suggests refactors to reduce tokens and latency.
1. Extracts and enriches tool call metadata with timing, token counts, and file ranges
2. Compresses session data with RLE for efficient pattern detection
3. Generates actionable optimization suggestions:
- Quick Commands: One-liner chains for package.json/Makefile
- Parameterized Scripts: Reusable workflows that handle different inputs
- File Refactorings: Merge/split files accessed together to reduce token overhead
https://github.com/user-attachments/assets/cac017c2-0fe7-4a8e-841c-e431a9324769
``bash`
/plugin marketplace add peerbot-ai/claude-code-optimizer
/plugin install agent-trace-ops
After installing the plugin, use the /plan command for on-demand analysis:
`bash`
/agent-trace-ops:plan
`bash`
npx agent-trace-ops
Install globally for repeated use:
`bash`
npm install -g agent-trace-ops
ato --project-path=
This will:
1. Check for existing analysis reports
2. Ask if you want to reuse or regenerate the report
3. Let you select which optimization categories to analyze:
- Quick Commands (one-liner chains for package.json/Makefile)
- Parameterized Scripts (reusable workflows)
- File Refactorings (merge/split frequently accessed files)
4. Analyze patterns and generate optimization suggestions
5. Show helpers with potential token savings calculations
Every conversation in Claude Code is saved as JSONL (JSON Lines) files in ~/.claude/projects/. The tool analyzes these sessions and generates a report:
`Sessions
Claude inspects the behavioral data from it's own agent and suggests different optimizations.
$3
Quick Commands - Combine repeated bash sequences (package.json/Makefile):
`bash
Detected pattern (found 23 times in sessions):
4. Bash: [+1s cmd=8b] make build-packages
5. Bash: [+8s cmd=16b] docker compose restart gateway
6. Bash: [+1s cmd=17b] sleep 5
7. Bash: [+6s cmd=23b] docker compose logs gateway --tail=50Suggested: Add to Makefile or package.json
make deploy-gateway # Reduces 4 calls → 1 call
`Parameterized Scripts - Reusable workflows with different parameters:
`bash
Detected pattern (found 15 times with different worker IDs):
8. Bash: [+0s cmd=30b] docker ps --filter "name=worker-1762140643"
9. Bash: [+2s cmd=32b] docker logs worker-1762140643-abc --tail=50
10. Bash: [+1s cmd=33b] docker logs worker-1762140643-abc | grep "error"Suggested script: ./scripts/worker-logs.sh
./scripts/worker-logs.sh 1762140643 50 "error" # Reduces 3 calls → 1 call
`File Refactorings - Merge co-accessed files:
`bash
Detected pattern (found 23 times):
1. Read: [+0s 6156b] src/interactions.ts[L1-L812]
2. Read: [+2s 4720b] src/types.ts[L1-L203]
3. Read: [+1s 2696b] src/custom-tools.ts[L1-L156]Suggested: Merge into src/core.ts (1171 lines)
1. Read: [+0s 13572b] src/core.ts[L1-L1171] # Reduces 3 reads → 1 read
``> See instructions.md for detailed pattern examples and optimization strategies.