v2/docs/development/token-tracking-status.md
We've researched and implemented real token tracking capabilities for Claude API calls. The implementation provides infrastructure for capturing actual token usage from Claude Code CLI, though there are limitations due to how Claude Code handles telemetry in interactive mode.
CLAUDE_CODE_ENABLE_TELEMETRY=1input_tokens, output_tokens, cache_read_tokens, cache_creation_tokensclaude-telemetry.js/cost commandclaude-track.js.claude-flow/metrics/token-usage.jsonanalysis setup-telemetry - Configure token trackinganalysis claude-monitor - Monitor Claude session in real-timeanalysis claude-cost - Get current session costswarm.js to handle telemetry properlyanalysis.js with new commands--claude flag for interactive mode, telemetry must be disabled to prevent console output interferenceThe fundamental issue is that Claude Code's telemetry system outputs to console when OTEL_METRICS_EXPORTER=console (or any valid exporter), which interferes with the interactive CLI experience. Setting it to an invalid value like "none" causes Claude to throw an error.
Token tracking works perfectly for non-interactive Claude commands where console output doesn't interfere.
Parse Claude's JSONL session files after execution (requires access to Claude's data directory).
Run a monitoring process alongside Claude that captures telemetry data.
Set up a local OTLP collector to receive telemetry data without console output.
/cost command within Claude sessionsTo fully enable real token tracking, consider:
Implement OTLP Collector: Set up a lightweight local collector
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
OTEL_METRICS_EXPORTER=otlp
Parse Session Files: Access Claude's session JSONL files directly
Hook Integration: Use Claude's session hooks to capture data post-execution
/src/cli/simple-commands/claude-telemetry.js - Core telemetry module/src/cli/simple-commands/claude-track.js - Background tracker/src/cli/simple-commands/analysis.js - Updated with new commands/src/cli/simple-commands/swarm.js - Fixed telemetry handling/docs/token-tracking-guide.md - Comprehensive guide/docs/token-tracking-status.md - This status documentReal token tracking infrastructure is implemented and functional. The main constraint is Claude Code's telemetry system outputting to console in interactive mode. The solution currently disables telemetry for interactive sessions to ensure proper Claude operation. For production token tracking, implementing a local OTLP collector would be the ideal solution.