v3/@claude-flow/cli/docs/CONFIG_LOADING.md
The CLI module now supports loading configuration from multiple sources with proper validation and type conversion.
src/config-adapter.ts (NEW)
SystemConfig (from @claude-flow/shared) and V3Config (CLI-specific format)systemConfigToV3Config() - Convert SystemConfig to V3Configv3ConfigToSystemConfig() - Convert V3Config to SystemConfigsrc/index.ts (MODIFIED)
loadConfig() method (previously TODO)__tests__/config-adapter.test.ts (NEW)
__tests__/config-loading.test.ts (NEW)
The CLI loads configuration in the following priority order:
--config flag is provided~/.claude-flow/claude-flow.config.jsonclaude-flow.config.jsclaude-flow.json.claude-flow.jsonConfiguration can also be overridden via environment variables:
CLAUDE_FLOW_MAX_AGENTS - Maximum concurrent agentsCLAUDE_FLOW_DATA_DIR - Data directory pathCLAUDE_FLOW_MEMORY_TYPE - Memory backend typeCLAUDE_FLOW_MCP_TRANSPORT - MCP transport typeCLAUDE_FLOW_MCP_PORT - MCP server portCLAUDE_FLOW_SWARM_TOPOLOGY - Swarm topology typeinterface V3Config {
version: string;
projectRoot: string;
agents: {
defaultType: string;
autoSpawn: boolean;
maxConcurrent: number;
timeout: number;
providers: ProviderConfig[];
};
swarm: {
topology: 'hierarchical' | 'mesh' | 'ring' | 'star' | 'hybrid';
maxAgents: number;
autoScale: boolean;
coordinationStrategy: 'consensus' | 'leader' | 'distributed';
healthCheckInterval: number;
};
memory: {
backend: 'agentdb' | 'sqlite' | 'memory' | 'hybrid';
persistPath: string;
cacheSize: number;
enableHNSW: boolean;
vectorDimension: number;
};
mcp: {
serverHost: string;
serverPort: number;
autoStart: boolean;
transportType: 'stdio' | 'http' | 'websocket';
tools: string[];
};
cli: {
colorOutput: boolean;
interactive: boolean;
verbosity: 'quiet' | 'normal' | 'verbose' | 'debug';
outputFormat: 'text' | 'json' | 'table';
progressStyle: 'bar' | 'spinner' | 'dots' | 'none';
};
hooks: {
enabled: boolean;
autoExecute: boolean;
hooks: HookDefinition[];
};
}
# Use default config search paths
claude-flow agent spawn -t coder
# Use specific config file
claude-flow agent spawn -t coder --config ./custom-config.json
# Override with environment variables
CLAUDE_FLOW_MAX_AGENTS=20 claude-flow swarm init
{
"orchestrator": {
"lifecycle": {
"autoStart": true,
"maxConcurrentAgents": 15,
"shutdownTimeoutMs": 30000,
"cleanupOrphanedAgents": true
},
"session": {
"dataDir": "./data",
"persistState": true,
"stateFile": "session.json"
},
"monitoring": {
"enabled": true,
"metricsIntervalMs": 5000,
"healthCheckIntervalMs": 10000
}
},
"swarm": {
"topology": "hierarchical-mesh",
"maxAgents": 15
},
"memory": {
"type": "hybrid",
"agentdb": {
"dimensions": 1536,
"indexType": "hnsw"
}
},
"mcp": {
"enabled": true,
"transport": {
"type": "stdio",
"host": "localhost",
"port": 3000
},
"enabledTools": ["agent/*", "swarm/*", "memory/*"]
},
"logging": {
"level": "info",
"pretty": true,
"destination": "console",
"format": "text"
},
"hooks": {
"enabled": true,
"autoExecute": false,
"definitions": []
}
}
The config loading implementation handles errors gracefully:
Debug mode (DEBUG=1) provides additional error details.
All tests pass successfully:
# Run config adapter unit tests
npx vitest run __tests__/config-adapter.test.ts
# Run config loading integration tests
npx vitest run __tests__/config-loading.test.ts
@claude-flow/shared.ts files)claude-flow config validate)