v2/docs/sdk/INTEGRATION-ROADMAP.md
Making NPX commands and MCP tools use real SDK features
npx claude-flow@alpha sparc run dev "task" # Uses old implementation
npx claude-flow@alpha hooks pre-task "desc" # Doesn't use checkpoints
npx claude-flow@alpha swarm init mesh # Doesn't use session forking
mcp__claude-flow__swarm_init // Doesn't create real forks
mcp__claude-flow__task_orchestrate // Doesn't use pause/resume
mcp__claude-flow__agent_spawn // Doesn't checkpoint
File to update: src/mcp/tools/swarm.ts
Before (fake forking):
export async function swarm_init({ topology }) {
// Uses Promise.allSettled (not real forking)
const results = await Promise.allSettled(tasks);
return { results };
}
After (real SDK forking):
import { RealSessionForking } from '../../sdk/session-forking.js';
const forking = new RealSessionForking();
export async function swarm_init({ topology, sessionId }) {
// Create base session
const baseQuery = query({ prompt: '...', options: {} });
await forking.trackSession(sessionId, baseQuery);
// Fork for each agent in swarm
const forks = await Promise.all(
agentIds.map(id => forking.fork(sessionId, {}))
);
return {
swarmId: sessionId,
agents: forks.map(f => ({ id: f.sessionId, parent: f.parentSessionId }))
};
}
File to update: src/cli/commands/hooks.ts
Add checkpoint commands:
// src/cli/commands/checkpoint.ts (NEW FILE)
import { checkpointManager } from '../../sdk/checkpoint-manager.js';
export async function checkpointCreate(sessionId: string, description: string) {
const id = await checkpointManager.createCheckpoint(sessionId, description);
console.log(`Checkpoint created: ${id}`);
return id;
}
export async function checkpointList(sessionId: string) {
const checkpoints = checkpointManager.listCheckpoints(sessionId);
console.table(checkpoints);
return checkpoints;
}
export async function checkpointRollback(checkpointId: string, prompt?: string) {
const query = await checkpointManager.rollbackToCheckpoint(checkpointId, prompt);
console.log(`Rolled back to checkpoint: ${checkpointId}`);
return query;
}
Usage:
npx claude-flow@alpha checkpoint create <session-id> "Before deployment"
npx claude-flow@alpha checkpoint list <session-id>
npx claude-flow@alpha checkpoint rollback <checkpoint-id>
File to update: src/hooks/handlers.ts
Add auto-checkpoint on important operations:
import { checkpointManager } from '../sdk/checkpoint-manager.js';
export async function postTaskHook(event: PostTaskEvent) {
const { taskId, sessionId, success } = event;
// Auto-checkpoint after successful tasks
if (success) {
await checkpointManager.createCheckpoint(
sessionId,
`After task: ${taskId}`
);
}
}
export async function preCompactHook(event: PreCompactEvent) {
const { sessionId } = event;
// Always checkpoint before compaction (lossy operation)
await checkpointManager.createCheckpoint(
sessionId,
'Before compaction (safety checkpoint)'
);
}
File to update: src/mcp/server.ts
Add in-process servers to MCP server list:
import {
createMathMcpServer,
createSessionMcpServer,
createCheckpointMcpServer,
createQueryControlMcpServer,
} from '../sdk/in-process-mcp.js';
export function createClaudeFlowMcpServer() {
return {
stdio: createStdioMcpServer(), // Existing stdio server
inProcess: {
math: createMathMcpServer(), // Fast math operations
session: createSessionMcpServer(), // Session state management
checkpoint: createCheckpointMcpServer(), // Checkpoint management
queryControl: createQueryControlMcpServer(), // Pause/resume
}
};
}
User configuration:
# Install Claude Flow MCP
claude mcp add claude-flow npx claude-flow@alpha mcp start
# Now has access to BOTH:
# - stdio tools (swarm_init, agent_spawn, etc.)
# - in-process tools (checkpoint_create, session_get, etc.)
File to update: src/sparc/orchestrator.ts
Add checkpoint support to SPARC workflow:
import { checkpointManager } from '../sdk/checkpoint-manager.js';
export async function runSparcMode(mode: string, task: string) {
const sessionId = `sparc-${mode}-${Date.now()}`;
// Create checkpoint at each SPARC phase
const phases = ['specification', 'pseudocode', 'architecture', 'refinement', 'completion'];
for (const phase of phases) {
console.log(`Starting phase: ${phase}`);
// Checkpoint before phase
const beforeCheckpoint = await checkpointManager.createCheckpoint(
sessionId,
`Before ${phase}`
);
// Execute phase
const result = await executePhase(phase, task);
// Checkpoint after phase
const afterCheckpoint = await checkpointManager.createCheckpoint(
sessionId,
`After ${phase} (${result.success ? 'success' : 'failed'})`
);
// If phase failed, rollback to before-checkpoint
if (!result.success) {
console.log(`Phase ${phase} failed, rolling back...`);
await checkpointManager.rollbackToCheckpoint(beforeCheckpoint);
break;
}
}
}
Usage:
npx claude-flow@alpha sparc run dev "Build API"
# Now automatically creates checkpoints at each phase
# Can rollback if any phase fails
# Initialize swarm with real session forking
npx claude-flow@alpha swarm init mesh --enable-forking
# Fork swarm to try different approach
npx claude-flow@alpha swarm fork <swarm-id> "Try hierarchical"
# Commit or rollback fork
npx claude-flow@alpha swarm commit <fork-id>
npx claude-flow@alpha swarm rollback <fork-id>
# Run SPARC with auto-checkpointing
npx claude-flow@alpha sparc run dev "Build feature" --enable-checkpoints
# List checkpoints
npx claude-flow@alpha checkpoint list <session-id>
# Rollback to any phase
npx claude-flow@alpha checkpoint rollback <checkpoint-id>
# Start long task
npx claude-flow@alpha task run "Build entire app" --session-id my-task
# Pause if needed (saves state to disk)
npx claude-flow@alpha task pause my-task
# Resume hours/days later
npx claude-flow@alpha task resume my-task
// In Claude Code query
const result = query({
prompt: `
Use mcp__claude-flow__swarm_init to create mesh swarm.
Enable session forking for parallel exploration.
Create checkpoint before risky operations.
Then use in-process checkpoint tool to manage state.
`,
options: {
// MCP tools auto-available
}
});
src/mcp/tools/swarm.ts - Add session forking to swarmsrc/mcp/tools/task-orchestrator.ts - Add pause/resumesrc/mcp/tools/agent.ts - Add checkpoint supportsrc/mcp/server.ts - Register in-process serverssrc/cli/commands/checkpoint.ts - NEW: Checkpoint commandssrc/cli/commands/swarm.ts - Add fork/commit/rollbacksrc/cli/commands/task.ts - Add pause/resumesrc/cli/commands/sparc.ts - Add auto-checkpointsrc/hooks/handlers.ts - Auto-checkpoint on key eventssrc/hooks/post-task.ts - Checkpoint after taskssrc/hooks/pre-compact.ts - Checkpoint before compactsrc/sparc/orchestrator.ts - Phase checkpointingsrc/sparc/modes/dev.ts - Fork for experimentssrc/sparc/modes/tdd.ts - Checkpoint before tests# Features disabled by default, opt-in with flags
npx claude-flow@alpha swarm init mesh --enable-forking
npx claude-flow@alpha sparc run dev "task" --enable-checkpoints
# Features enabled by default, opt-out with flags
npx claude-flow@alpha swarm init mesh --disable-forking
npx claude-flow@alpha sparc run dev "task" --disable-checkpoints
# Features always enabled, no flags needed
npx claude-flow@alpha swarm init mesh # Forking enabled
npx claude-flow@alpha sparc run dev "task" # Checkpoints enabled
.claude-flow.json{
"sdk": {
"sessionForking": {
"enabled": true,
"autoCleanup": true
},
"checkpoints": {
"enabled": true,
"autoInterval": 10,
"maxPerSession": 50,
"persistPath": ".claude-flow/checkpoints"
},
"queryControl": {
"enabled": true,
"autoPauseOnError": true,
"persistPath": ".claude-flow/paused-queries"
},
"inProcessMcp": {
"enabled": true,
"servers": ["math", "session", "checkpoint", "queryControl"]
}
}
}
CLAUDE_FLOW_ENABLE_FORKING=true
CLAUDE_FLOW_ENABLE_CHECKPOINTS=true
CLAUDE_FLOW_CHECKPOINT_INTERVAL=10
CLAUDE_FLOW_ENABLE_PAUSE_RESUME=true
Week 1-2: Core Integration
Week 3-4: CLI Commands
Week 5-6: SPARC & Hooks
Week 7-8: Testing & Documentation
Week 9: Release v2.5.0
Before (Fake Features):
Promise.allSettled (not real)interrupt() (can't resume)After (Real SDK Features):
Current Phase: Phase 0 - SDK features created but not integrated ✅ Next Phase: Phase 1 - Update MCP tool implementations ⏳ Target Release: v2.5.0-alpha.140+ (with SDK integration)
All SDK code is functional and validated. Integration into existing NPX/MCP commands is the next step.