claude-flow 2.5.0-alpha.141 → 2.7.0-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/.claude/agents/reasoning/README.md +171 -0
  2. package/.claude/agents/reasoning/agent.md +816 -0
  3. package/.claude/agents/reasoning/example-reasoning-agent-template.md +362 -0
  4. package/.claude/agents/reasoning/goal-planner.md +73 -0
  5. package/.claude/commands/coordination/README.md +9 -0
  6. package/.claude/commands/memory/README.md +9 -0
  7. package/.claude/settings.json +3 -3
  8. package/.claude/sparc-modes.json +108 -0
  9. package/README.md +1 -6
  10. package/bin/claude-flow +1 -1
  11. package/dist/src/cli/command-registry.js +70 -6
  12. package/dist/src/cli/command-registry.js.map +1 -1
  13. package/dist/src/cli/help-formatter.js +0 -3
  14. package/dist/src/cli/help-formatter.js.map +1 -1
  15. package/dist/src/cli/help-text.js +53 -5
  16. package/dist/src/cli/help-text.js.map +1 -1
  17. package/dist/src/cli/simple-cli.js +182 -172
  18. package/dist/src/cli/simple-cli.js.map +1 -1
  19. package/dist/src/cli/simple-commands/agent-booster.js +415 -0
  20. package/dist/src/cli/simple-commands/agent-booster.js.map +1 -0
  21. package/dist/src/cli/simple-commands/agent.js +856 -13
  22. package/dist/src/cli/simple-commands/agent.js.map +1 -1
  23. package/dist/src/cli/simple-commands/env-template.js +180 -0
  24. package/dist/src/cli/simple-commands/env-template.js.map +1 -0
  25. package/dist/src/cli/simple-commands/init/help.js +23 -0
  26. package/dist/src/cli/simple-commands/init/help.js.map +1 -1
  27. package/dist/src/cli/simple-commands/init/index.js +63 -0
  28. package/dist/src/cli/simple-commands/init/index.js.map +1 -1
  29. package/dist/src/cli/simple-commands/memory.js +307 -16
  30. package/dist/src/cli/simple-commands/memory.js.map +1 -1
  31. package/dist/src/cli/simple-commands/proxy.js +304 -0
  32. package/dist/src/cli/simple-commands/proxy.js.map +1 -0
  33. package/dist/src/cli/simple-commands/sparc.js +16 -19
  34. package/dist/src/cli/simple-commands/sparc.js.map +1 -1
  35. package/dist/src/cli/validation-helper.js.map +1 -1
  36. package/dist/src/core/version.js +1 -1
  37. package/dist/src/execution/agent-executor.js +181 -0
  38. package/dist/src/execution/agent-executor.js.map +1 -0
  39. package/dist/src/execution/index.js +12 -0
  40. package/dist/src/execution/index.js.map +1 -0
  41. package/dist/src/execution/provider-manager.js +110 -0
  42. package/dist/src/execution/provider-manager.js.map +1 -0
  43. package/dist/src/hooks/redaction-hook.js +89 -0
  44. package/dist/src/hooks/redaction-hook.js.map +1 -0
  45. package/dist/src/memory/swarm-memory.js +340 -421
  46. package/dist/src/memory/swarm-memory.js.map +1 -1
  47. package/dist/src/utils/key-redactor.js +108 -0
  48. package/dist/src/utils/key-redactor.js.map +1 -0
  49. package/dist/src/utils/metrics-reader.js +37 -39
  50. package/dist/src/utils/metrics-reader.js.map +1 -1
  51. package/docs/AGENT-BOOSTER-INTEGRATION.md +407 -0
  52. package/docs/AGENTIC-FLOW-INTEGRATION-GUIDE.md +753 -0
  53. package/docs/AGENTIC_FLOW_EXECUTION_FIX_REPORT.md +474 -0
  54. package/docs/AGENTIC_FLOW_INTEGRATION_STATUS.md +143 -0
  55. package/docs/AGENTIC_FLOW_MVP_COMPLETE.md +367 -0
  56. package/docs/AGENTIC_FLOW_SECURITY_TEST_REPORT.md +369 -0
  57. package/docs/COMMAND-VERIFICATION-REPORT.md +441 -0
  58. package/docs/COMMIT_SUMMARY.md +247 -0
  59. package/docs/DEEP_REVIEW_COMPREHENSIVE_REPORT.md +922 -0
  60. package/docs/DOCKER-VALIDATION-REPORT.md +281 -0
  61. package/docs/ENV-SETUP-GUIDE.md +270 -0
  62. package/docs/FINAL_PRE_PUBLISH_VALIDATION.md +823 -0
  63. package/docs/FINAL_VALIDATION_REPORT.md +165 -0
  64. package/docs/HOOKS-V2-MODIFICATION.md +146 -0
  65. package/docs/INDEX.md +568 -0
  66. package/docs/INTEGRATION_COMPLETE.md +414 -0
  67. package/docs/MEMORY_REDACTION_TEST_REPORT.md +300 -0
  68. package/docs/PERFORMANCE-SYSTEMS-STATUS.md +340 -0
  69. package/docs/PRE_RELEASE_FIXES_REPORT.md +435 -0
  70. package/docs/README.md +35 -0
  71. package/docs/REASONING-AGENTS.md +482 -0
  72. package/docs/REASONINGBANK-AGENT-CREATION-GUIDE.md +813 -0
  73. package/docs/REASONINGBANK-ANALYSIS-COMPLETE.md +479 -0
  74. package/docs/REASONINGBANK-BENCHMARK-RESULTS.md +166 -0
  75. package/docs/REASONINGBANK-BENCHMARK.md +396 -0
  76. package/docs/REASONINGBANK-CLI-INTEGRATION.md +455 -0
  77. package/docs/REASONINGBANK-CORE-INTEGRATION.md +658 -0
  78. package/docs/REASONINGBANK-COST-OPTIMIZATION.md +329 -0
  79. package/docs/REASONINGBANK-DEMO.md +419 -0
  80. package/docs/REASONINGBANK-INTEGRATION-COMPLETE.md +249 -0
  81. package/docs/REASONINGBANK-VALIDATION.md +532 -0
  82. package/docs/REASONINGBANK_ARCHITECTURE.md +475 -0
  83. package/docs/REASONINGBANK_INTEGRATION_COMPLETE.md +558 -0
  84. package/docs/REASONINGBANK_INTEGRATION_PLAN.md +1188 -0
  85. package/docs/REGRESSION-ANALYSIS-REPORT.md +500 -0
  86. package/docs/RELEASE_v2.6.0-alpha.2.md +658 -0
  87. package/docs/api/API_DOCUMENTATION.md +721 -0
  88. package/docs/architecture/ARCHITECTURE.md +1690 -0
  89. package/docs/ci-cd/README.md +368 -0
  90. package/docs/development/DEPLOYMENT.md +2348 -0
  91. package/docs/development/DEVELOPMENT_WORKFLOW.md +1333 -0
  92. package/docs/development/build-analysis-report.md +252 -0
  93. package/docs/development/pair-optimization.md +156 -0
  94. package/docs/development/token-tracking-status.md +103 -0
  95. package/docs/development/training-pipeline-demo.md +163 -0
  96. package/docs/development/training-pipeline-real-only.md +196 -0
  97. package/docs/epic-sdk-integration.md +1269 -0
  98. package/docs/experimental/RIEMANN_HYPOTHESIS_PROOF.md +124 -0
  99. package/docs/experimental/computational_verification.py +436 -0
  100. package/docs/experimental/novel_approaches.md +560 -0
  101. package/docs/experimental/riemann_hypothesis_analysis.md +263 -0
  102. package/docs/experimental/riemann_proof_attempt.md +124 -0
  103. package/docs/experimental/riemann_synthesis.md +277 -0
  104. package/docs/experimental/verification_results.json +12 -0
  105. package/docs/experimental/visualization_insights.md +720 -0
  106. package/docs/guides/USER_GUIDE.md +1138 -0
  107. package/docs/guides/token-tracking-guide.md +291 -0
  108. package/docs/reference/AGENTS.md +1011 -0
  109. package/docs/reference/MCP_TOOLS.md +2188 -0
  110. package/docs/reference/SPARC.md +717 -0
  111. package/docs/reference/SWARM.md +2000 -0
  112. package/docs/sdk/CLAUDE-CODE-SDK-DEEP-ANALYSIS.md +649 -0
  113. package/docs/sdk/CLAUDE-FLOW-SDK-INTEGRATION-ANALYSIS.md +242 -0
  114. package/docs/sdk/INTEGRATION-ROADMAP.md +420 -0
  115. package/docs/sdk/MCP-TOOLS-UPDATE.md +270 -0
  116. package/docs/sdk/SDK-ADVANCED-FEATURES-INTEGRATION.md +723 -0
  117. package/docs/sdk/SDK-ALL-FEATURES-INTEGRATION-MATRIX.md +612 -0
  118. package/docs/sdk/SDK-INTEGRATION-COMPLETE.md +358 -0
  119. package/docs/sdk/SDK-INTEGRATION-PHASES-V2.5.md +750 -0
  120. package/docs/sdk/SDK-LEVERAGE-REAL-FEATURES.md +676 -0
  121. package/docs/sdk/SDK-VALIDATION-RESULTS.md +400 -0
  122. package/docs/sdk/epic-sdk-integration.md +1269 -0
  123. package/docs/setup/remote-setup.md +93 -0
  124. package/docs/validation/final-validation-summary.md +220 -0
  125. package/docs/validation/verification-integration.md +190 -0
  126. package/docs/validation/verification-validation.md +349 -0
  127. package/docs/wiki/background-commands.md +1213 -0
  128. package/docs/wiki/session-persistence.md +342 -0
  129. package/docs/wiki/stream-chain-command.md +537 -0
  130. package/package.json +4 -2
  131. package/src/cli/command-registry.js +70 -5
  132. package/src/cli/help-text.js +26 -5
  133. package/src/cli/simple-cli.ts +18 -7
  134. package/src/cli/simple-commands/agent-booster.js +515 -0
  135. package/src/cli/simple-commands/agent.js +1001 -12
  136. package/src/cli/simple-commands/agent.ts +137 -0
  137. package/src/cli/simple-commands/config.ts +127 -0
  138. package/src/cli/simple-commands/env-template.js +190 -0
  139. package/src/cli/simple-commands/init/help.js +23 -0
  140. package/src/cli/simple-commands/init/index.js +84 -6
  141. package/src/cli/simple-commands/memory.js +363 -16
  142. package/src/cli/simple-commands/proxy.js +384 -0
  143. package/src/cli/simple-commands/sparc.js +16 -19
  144. package/src/execution/agent-executor.ts +306 -0
  145. package/src/execution/index.ts +19 -0
  146. package/src/execution/provider-manager.ts +187 -0
  147. package/src/hooks/redaction-hook.ts +115 -0
  148. package/src/utils/key-redactor.js +178 -0
  149. package/src/utils/key-redactor.ts +184 -0
@@ -0,0 +1,291 @@
1
+ # Claude Token Tracking Guide
2
+
3
+ ## Overview
4
+
5
+ Claude Flow now includes **REAL** token tracking capabilities that capture actual Claude API usage, not simulated data. This guide shows how to enable and use token tracking with the Claude Code CLI.
6
+
7
+ ## Quick Start
8
+
9
+ ### Step 1: Enable Telemetry
10
+
11
+ First, enable telemetry for token tracking:
12
+
13
+ ```bash
14
+ ./claude-flow analysis setup-telemetry
15
+ ```
16
+
17
+ This will:
18
+ - Set `CLAUDE_CODE_ENABLE_TELEMETRY=1` environment variable
19
+ - Create `.env` file with telemetry settings
20
+ - Initialize token tracking directory (`.claude-flow/metrics/`)
21
+
22
+ ### Step 2: Run Claude with Token Tracking
23
+
24
+ Use the `--claude` flag with telemetry enabled:
25
+
26
+ ```bash
27
+ # Option 1: Set environment variable inline
28
+ CLAUDE_CODE_ENABLE_TELEMETRY=1 ./claude-flow swarm "your task" --claude
29
+
30
+ # Option 2: Export environment variable
31
+ export CLAUDE_CODE_ENABLE_TELEMETRY=1
32
+ ./claude-flow swarm "your task" --claude
33
+
34
+ # Option 3: Use wrapper directly
35
+ ./claude-flow analysis claude-monitor # Start monitoring in one terminal
36
+ ./claude-flow swarm "your task" --claude # Run Claude in another terminal
37
+ ```
38
+
39
+ ### Step 3: View Token Usage
40
+
41
+ After running Claude commands:
42
+
43
+ ```bash
44
+ # View comprehensive token usage report
45
+ ./claude-flow analysis token-usage --breakdown --cost-analysis
46
+
47
+ # Get current session cost
48
+ ./claude-flow analysis claude-cost
49
+
50
+ # Monitor session in real-time
51
+ ./claude-flow analysis claude-monitor [session-id]
52
+ ```
53
+
54
+ ## Architecture
55
+
56
+ ### How It Works
57
+
58
+ 1. **Claude Telemetry Integration**: The system integrates with Claude's native OpenTelemetry support
59
+ 2. **Process Wrapping**: When telemetry is enabled, Claude commands are wrapped to capture output
60
+ 3. **Token Extraction**: Token usage is extracted from:
61
+ - Claude CLI output patterns
62
+ - Session JSONL files (if accessible)
63
+ - `/cost` command output
64
+ 4. **Persistent Storage**: Token data is stored in `.claude-flow/metrics/token-usage.json`
65
+
66
+ ### Key Components
67
+
68
+ - **`claude-telemetry.js`**: Core telemetry wrapper module
69
+ - **`token-tracker.js`**: Token tracking and cost calculation
70
+ - **`analysis.js`**: Analysis commands and reporting
71
+
72
+ ## Features
73
+
74
+ ### Real-Time Monitoring
75
+
76
+ Monitor Claude sessions as they run:
77
+
78
+ ```bash
79
+ # Monitor with default 5-second interval
80
+ ./claude-flow analysis claude-monitor
81
+
82
+ # Monitor with custom interval (3 seconds)
83
+ ./claude-flow analysis claude-monitor current --interval 3000
84
+ ```
85
+
86
+ ### Cost Analysis
87
+
88
+ Track costs based on Claude 3 pricing:
89
+
90
+ | Model | Input (per 1M tokens) | Output (per 1M tokens) |
91
+ |--------|----------------------|------------------------|
92
+ | Opus | $15.00 | $75.00 |
93
+ | Sonnet | $3.00 | $15.00 |
94
+ | Haiku | $0.25 | $1.25 |
95
+
96
+ ### Token Breakdown
97
+
98
+ View token usage by:
99
+ - Agent type
100
+ - Command
101
+ - Session
102
+ - Time period
103
+
104
+ ```bash
105
+ # Detailed breakdown
106
+ ./claude-flow analysis token-usage --breakdown
107
+
108
+ # Agent-specific analysis
109
+ ./claude-flow analysis token-usage --agent coordinator --cost-analysis
110
+ ```
111
+
112
+ ## Advanced Usage
113
+
114
+ ### Programmatic Token Tracking
115
+
116
+ You can also use the telemetry wrapper programmatically:
117
+
118
+ ```javascript
119
+ import { runClaudeWithTelemetry } from './claude-telemetry.js';
120
+
121
+ const result = await runClaudeWithTelemetry(
122
+ ['chat', 'Hello, Claude!'],
123
+ {
124
+ sessionId: 'my-session-123',
125
+ agentType: 'custom-agent'
126
+ }
127
+ );
128
+ ```
129
+
130
+ ### Session Monitoring
131
+
132
+ Monitor specific sessions:
133
+
134
+ ```javascript
135
+ import { monitorClaudeSession } from './claude-telemetry.js';
136
+
137
+ const stopMonitor = await monitorClaudeSession('session-id', 5000);
138
+
139
+ // Stop monitoring when done
140
+ stopMonitor();
141
+ ```
142
+
143
+ ## Troubleshooting
144
+
145
+ ### No Token Data Showing
146
+
147
+ 1. Verify telemetry is enabled:
148
+ ```bash
149
+ echo $CLAUDE_CODE_ENABLE_TELEMETRY # Should output: 1
150
+ ```
151
+
152
+ 2. Check token usage file exists:
153
+ ```bash
154
+ cat .claude-flow/metrics/token-usage.json
155
+ ```
156
+
157
+ 3. Ensure Claude is installed:
158
+ ```bash
159
+ which claude # Should show Claude path
160
+ ```
161
+
162
+ ### Token Tracking Not Working
163
+
164
+ 1. Clear existing metrics:
165
+ ```bash
166
+ rm -rf .claude-flow/metrics/token-usage.json
167
+ ```
168
+
169
+ 2. Re-enable telemetry:
170
+ ```bash
171
+ ./claude-flow analysis setup-telemetry
172
+ ```
173
+
174
+ 3. Run with explicit telemetry:
175
+ ```bash
176
+ CLAUDE_CODE_ENABLE_TELEMETRY=1 ./claude-flow swarm "test" --claude
177
+ ```
178
+
179
+ ## Integration with CI/CD
180
+
181
+ For automated environments:
182
+
183
+ ```yaml
184
+ # GitHub Actions example
185
+ env:
186
+ CLAUDE_CODE_ENABLE_TELEMETRY: '1'
187
+
188
+ steps:
189
+ - name: Setup telemetry
190
+ run: ./claude-flow analysis setup-telemetry
191
+
192
+ - name: Run Claude task
193
+ run: ./claude-flow swarm "${{ inputs.task }}" --claude
194
+
195
+ - name: Report costs
196
+ run: ./claude-flow analysis claude-cost
197
+ ```
198
+
199
+ ## Privacy & Security
200
+
201
+ - **No sensitive data**: Only token counts and costs are tracked
202
+ - **Local storage**: All data is stored locally in `.claude-flow/metrics/`
203
+ - **Opt-in**: Telemetry must be explicitly enabled
204
+ - **No external transmission**: Data is never sent to external servers
205
+
206
+ ## Best Practices
207
+
208
+ 1. **Enable telemetry once**: Set it in your `.env` file for persistence
209
+ 2. **Monitor long tasks**: Use `claude-monitor` for tasks > 5 minutes
210
+ 3. **Regular cost checks**: Run `claude-cost` after expensive operations
211
+ 4. **Batch operations**: Group Claude calls to optimize token usage
212
+ 5. **Use appropriate models**: Choose Haiku for simple tasks, Opus for complex
213
+
214
+ ## API Reference
215
+
216
+ ### Commands
217
+
218
+ | Command | Description |
219
+ |---------|-------------|
220
+ | `analysis setup-telemetry` | Configure token tracking |
221
+ | `analysis token-usage` | View token usage report |
222
+ | `analysis claude-monitor` | Monitor session in real-time |
223
+ | `analysis claude-cost` | Get current session cost |
224
+
225
+ ### Environment Variables
226
+
227
+ | Variable | Description | Default |
228
+ |----------|-------------|---------|
229
+ | `CLAUDE_CODE_ENABLE_TELEMETRY` | Enable token tracking | `0` |
230
+ | `OTEL_METRICS_EXPORTER` | OpenTelemetry exporter | `console` |
231
+ | `OTEL_LOGS_EXPORTER` | Log exporter type | `console` |
232
+
233
+ ### Files
234
+
235
+ | File | Purpose |
236
+ |------|---------|
237
+ | `.claude-flow/metrics/token-usage.json` | Token usage data |
238
+ | `.claude-flow/metrics/sessions/*.json` | Session metrics |
239
+ | `.env` | Environment configuration |
240
+
241
+ ## Examples
242
+
243
+ ### Complete Workflow
244
+
245
+ ```bash
246
+ # 1. Setup
247
+ ./claude-flow analysis setup-telemetry
248
+
249
+ # 2. Run task with tracking
250
+ export CLAUDE_CODE_ENABLE_TELEMETRY=1
251
+ ./claude-flow swarm "Create a REST API with authentication" --claude
252
+
253
+ # 3. Check usage
254
+ ./claude-flow analysis token-usage --breakdown --cost-analysis
255
+
256
+ # 4. Monitor next session
257
+ ./claude-flow analysis claude-monitor & # Run in background
258
+ ./claude-flow swarm "Add tests to the API" --claude
259
+
260
+ # 5. Final cost report
261
+ ./claude-flow analysis claude-cost
262
+ ```
263
+
264
+ ### Optimization Example
265
+
266
+ ```bash
267
+ # Analyze token usage patterns
268
+ ./claude-flow analysis token-usage --breakdown
269
+
270
+ # Identify high-consumption agents
271
+ ./claude-flow analysis token-usage --agent coordinator
272
+
273
+ # Get optimization suggestions
274
+ ./claude-flow analysis bottleneck-detect --scope agent
275
+ ```
276
+
277
+ ## Support
278
+
279
+ For issues or questions:
280
+ - GitHub Issues: https://github.com/ruvnet/claude-flow/issues
281
+ - Documentation: https://github.com/ruvnet/claude-flow/docs
282
+
283
+ ## Conclusion
284
+
285
+ Real token tracking in Claude Flow provides transparency into API usage and costs. By following this guide, you can:
286
+ - Track actual Claude API token consumption
287
+ - Monitor costs in real-time
288
+ - Optimize token usage patterns
289
+ - Make informed decisions about model selection
290
+
291
+ Remember: This tracks **REAL** usage, not simulated data!