-
Notifications
You must be signed in to change notification settings - Fork 2k
Non Interactive Mode
Claude Flow supports fully automated, non-interactive operation for CI/CD pipelines, containerized environments, and headless servers. This guide covers everything you need to run Claude Flow without user interaction, including the NEW automation commands and stream-json chaining capabilities.
- How It Works
- Environment Detection
- Command Line Flags
- NEW: Automation Commands
- NEW: Stream-JSON Chaining
- Authentication
- JSON Output Format
- Docker & Container Usage
- Common Use Cases
- Troubleshooting
Claude Flow automatically detects non-interactive environments by checking:
-
TTY Availability
-
process.stdin.isTTY- Input terminal check -
process.stdout.isTTY- Output terminal check
-
-
CI/CD Environments
- GitHub Actions (
GITHUB_ACTIONS) - GitLab CI (
GITLAB_CI) - Jenkins (
JENKINS_URL) - CircleCI (
CIRCLECI) - Travis CI (
TRAVIS) - AWS CodeBuild (
CODEBUILD_BUILD_ID)
- GitHub Actions (
-
Container Environments
- Docker (
DOCKER_CONTAINER) - Kubernetes (
KUBERNETES_SERVICE_HOST)
- Docker (
-
Terminal Types
- WSL (
WSL_DISTRO_NAME,WSL_INTEROP) - Windows Command Prompt
- VS Code Terminal (
TERM_PROGRAM)
- WSL (
-
Environment Variables
CLAUDE_FLOW_NON_INTERACTIVE=true
When non-interactive mode is active:
- No prompts: All interactive prompts use default values
- No spinners: Simple text-based progress indicators
- No colors: Plain text output (unless forced)
-
Auto permissions: Enables
--dangerously-skip-permissionsby default - Structured output: JSON format available for parsing
# Force non-interactive mode
export CLAUDE_FLOW_NON_INTERACTIVE=true
# Set API key for authentication
export ANTHROPIC_API_KEY="sk-ant-..."
# Optional: Claude API key (alternative)
export CLAUDE_API_KEY="sk-ant-..."- Explicit flags (
--no-interactive,--headless) - Environment variable (
CLAUDE_FLOW_NON_INTERACTIVE) - JSON output format (
--output-format json) - CI/CD environment detection
- TTY availability check
# Explicit non-interactive mode
npx claude-flow@alpha swarm "task" --no-interactive
# Headless mode (forces non-interactive + JSON output)
npx claude-flow@alpha swarm "task" --headless
# JSON output (auto-enables non-interactive)
npx claude-flow@alpha swarm "task" --output-format json
# Save output to file
npx claude-flow@alpha swarm "task" --output-format json --output-file results.json# Disable auto permissions (requires manual approval)
npx claude-flow@alpha swarm "task" --no-interactive --no-auto-permissions
# Stream JSON output (real-time updates)
npx claude-flow@alpha swarm "task" --output-format stream-json
# JSON-formatted logs
npx claude-flow@alpha swarm "task" --json-logs
# Verbose output in non-interactive mode
npx claude-flow@alpha swarm "task" --no-interactive --verboseClaude Flow v2 introduces powerful automation commands designed specifically for non-interactive operation. These commands provide intelligent agent orchestration, workflow automation, and the flagship MLE-STAR methodology.
Automatically spawns optimal agents based on task complexity:
# Enterprise-level complexity with 15 agents
claude-flow automation auto-agent --task-complexity enterprise --no-interactive
# Simple task with minimal agents
claude-flow automation auto-agent --task-complexity low --no-interactiveIntelligently selects agents based on specific requirements:
# Web development project
claude-flow automation smart-spawn --requirement "web-development" --max-agents 8 --no-interactive
# Data analysis workflow
claude-flow automation smart-spawn --requirement "data-analysis" --max-agents 6 --no-interactiveExecute workflows from JSON/YAML files:
# Run custom workflow with Claude integration
claude-flow automation run-workflow my-workflow.json --claude --non-interactive
# With JSON output for CI/CD integration
claude-flow automation run-workflow workflow.json --claude --non-interactive --output-format jsonThe premier ML engineering automation workflow:
# Basic MLE-STAR execution (non-interactive by default)
claude-flow automation mle-star --dataset data.csv --target price --claude
# Full configuration for production pipelines
claude-flow automation mle-star \
--dataset sales-data.csv \
--target revenue \
--output models/revenue/ \
--name "revenue-prediction" \
--search-iterations 5 \
--refinement-iterations 8 \
--claude \
--non-interactive \
--output-format json- 🧠 Intelligent Agent Selection: Automatically chooses optimal agents for tasks
- ⚡ Zero Configuration: Works out-of-the-box with sensible defaults
- 📊 Production Ready: Designed for CI/CD and automated pipelines
- 🔍 Comprehensive Logging: Detailed progress and status reporting
- 🎯 Task-Specific Optimization: Each command optimized for specific use cases
name: MLE-STAR ML Pipeline
on: [push]
jobs:
ml-training:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install Claude Flow
run: npm install -g claude-flow@alpha
- name: Run MLE-STAR Workflow
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
claude-flow automation mle-star \
--dataset data/training.csv \
--target conversion \
--claude \
--non-interactive \
--output-format json > results.json
- name: Upload Results
uses: actions/upload-artifact@v3
with:
name: ml-results
path: results.jsonFROM node:18-alpine
RUN npm install -g claude-flow@alpha
COPY data/ /app/data/
WORKDIR /app
ENV ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
CMD ["claude-flow", "automation", "mle-star", "--dataset", "data/input.csv", "--target", "outcome", "--claude", "--non-interactive"]Stream-JSON chaining enables real-time agent-to-agent output piping in non-interactive mode, creating seamless workflows without intermediate file storage.
When --output-format stream-json is enabled, agents automatically pipe their outputs to dependent agents:
# Agent A generates stream-json output → Agent B receives it → Agent C completes chain
claude-flow automation mle-star --dataset data.csv --target price --claude --output-format stream-json- 🔄 Real-time Processing: Downstream agents start immediately
- 💾 Memory Efficient: No intermediate file storage required
- 🎯 Context Preservation: Full conversation history flows between agents
- ⚡ Faster Execution: 40-60% improvement over file-based handoffs
- 🔍 Rich Metadata: Tool usage and reasoning preserved across chain
# MLE-STAR with automatic stream chaining
claude-flow automation mle-star \
--dataset data.csv \
--target price \
--claude \
--output-format stream-json \
--non-interactive
# Custom workflow with chaining
claude-flow automation run-workflow workflow.json \
--claude \
--non-interactive \
--output-format stream-json
# Disable chaining if needed
claude-flow automation mle-star \
--dataset data.csv \
--target price \
--claude \
--output-format stream-json \
--no-chainingMonitor active chains in non-interactive mode:
# Status with chain information
claude-flow automation status --show-chains --output-format jsonOutput example:
{
"chains": [
{
"id": "chain-1",
"agents": ["search_agent", "foundation_agent", "refinement_agent"],
"status": "running",
"phase": "2/3",
"dataFlow": "2.3MB",
"latency": "145ms"
}
]
}Non-interactive mode requires API keys via environment variables:
# Option 1: Anthropic API Key
export ANTHROPIC_API_KEY="sk-ant-api03-..."
# Option 2: Claude API Key (alternative)
export CLAUDE_API_KEY="sk-ant-api03-..."
# Run command
npx claude-flow@alpha swarm "analyze codebase" --no-interactiveClaude Flow validates authentication before execution:
// Automatic validation in non-interactive mode
if (!process.env.ANTHROPIC_API_KEY && !process.env.CLAUDE_API_KEY) {
console.error('❌ Non-interactive mode requires API key');
console.error('Set ANTHROPIC_API_KEY or CLAUDE_API_KEY');
process.exit(1);
}npx claude-flow@alpha swarm "build API" --output-format jsonOutput structure:
{
"swarmId": "swarm-abc123",
"objective": "build API",
"status": "completed",
"startTime": "2024-07-31T12:00:00Z",
"endTime": "2024-07-31T12:15:00Z",
"metadata": {
"version": "2.0.0-alpha",
"strategy": "auto",
"mode": "centralized",
"maxAgents": 5
},
"agents": [
{
"agentId": "agent-1",
"name": "Architect",
"type": "architect",
"status": "completed",
"outputs": ["Designed REST API structure"],
"errors": []
}
],
"tasks": [
{
"taskId": "task-1",
"name": "Design API",
"status": "completed",
"assignedTo": "agent-1"
}
],
"results": {
"outputs": ["API design complete", "Endpoints documented"],
"errors": [],
"insights": ["Consider rate limiting for public endpoints"],
"artifacts": {
"apiSpec": { "type": "openapi", "path": "./api-spec.yaml" }
}
},
"summary": {
"totalAgents": 5,
"totalTasks": 10,
"completedTasks": 10,
"failedTasks": 0,
"successRate": 1.0,
"duration": "15m"
}
}npx claude-flow@alpha swarm "task" --output-format stream-jsonReal-time updates as newline-delimited JSON:
{"type":"init","swarmId":"swarm-abc123","timestamp":"2024-07-31T12:00:00Z"}
{"type":"agent_spawn","agentId":"agent-1","agentType":"coder","timestamp":"2024-07-31T12:00:01Z"}
{"type":"task_start","taskId":"task-1","taskName":"Implement auth","timestamp":"2024-07-31T12:00:02Z"}
{"type":"progress","taskId":"task-1","progress":50,"timestamp":"2024-07-31T12:05:00Z"}
{"type":"task_complete","taskId":"task-1","status":"success","timestamp":"2024-07-31T12:10:00Z"}
{"type":"complete","status":"success","summary":{...},"timestamp":"2024-07-31T12:15:00Z"}FROM node:18-alpine
# Install Claude Flow
RUN npm install -g claude-flow@alpha
# Set non-interactive mode
ENV CLAUDE_FLOW_NON_INTERACTIVE=true
# Add API key at runtime
ENV ANTHROPIC_API_KEY=""
# Run command
CMD ["npx", "claude-flow@alpha", "swarm", "analyze", "--output-format", "json"]version: '3.8'
services:
claude-flow:
image: node:18-alpine
environment:
- CLAUDE_FLOW_NON_INTERACTIVE=true
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
volumes:
- ./code:/workspace
working_dir: /workspace
command: |
sh -c "
npm install -g claude-flow@alpha &&
npx claude-flow@alpha swarm 'analyze codebase' --output-format json --output-file /workspace/analysis.json
"apiVersion: batch/v1
kind: Job
metadata:
name: claude-flow-analysis
spec:
template:
spec:
containers:
- name: claude-flow
image: node:18-alpine
env:
- name: CLAUDE_FLOW_NON_INTERACTIVE
value: "true"
- name: ANTHROPIC_API_KEY
valueFrom:
secretKeyRef:
name: claude-secrets
key: api-key
command:
- sh
- -c
- |
npm install -g claude-flow@alpha
npx claude-flow@alpha swarm "analyze and optimize" \
--output-format json \
--output-file /results/analysis.json
volumeMounts:
- name: results
mountPath: /results
volumes:
- name: results
persistentVolumeClaim:
claimName: analysis-results
restartPolicy: Never# .github/workflows/claude-analysis.yml
name: Code Analysis with Claude Flow
on: [push, pull_request]
jobs:
analyze:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install Claude Flow
run: npm install -g claude-flow@alpha
- name: Run Analysis
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
npx claude-flow@alpha swarm "analyze code quality and security" \
--output-format json \
--output-file analysis-results.json
- name: Upload Results
uses: actions/upload-artifact@v3
with:
name: analysis-results
path: analysis-results.json#!/bin/bash
# scheduled-review.sh
export ANTHROPIC_API_KEY="sk-ant-..."
export CLAUDE_FLOW_NON_INTERACTIVE=true
# Run daily code review
npx claude-flow@alpha swarm "review recent commits for issues" \
--output-format json \
--output-file "reviews/review-$(date +%Y%m%d).json"
# Process results
if [ $? -eq 0 ]; then
# Send notification or create issues
echo "Review complete: reviews/review-$(date +%Y%m%d).json"
fi// generate-docs.js
const { exec } = require('child_process');
const fs = require('fs');
async function generateAPIDocs() {
const command = `
npx claude-flow@alpha swarm "generate OpenAPI documentation from code" \
--no-interactive \
--output-format json
`;
exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
const result = JSON.parse(stdout);
const apiSpec = result.results.artifacts.apiSpec;
fs.writeFileSync('openapi.yaml', apiSpec.content);
console.log('API documentation generated successfully');
});
}
generateAPIDocs();#!/bin/bash
# batch-process.sh
tasks=(
"analyze security vulnerabilities"
"optimize database queries"
"review API endpoints"
"check dependency updates"
)
for task in "${tasks[@]}"; do
echo "Processing: $task"
npx claude-flow@alpha swarm "$task" \
--no-interactive \
--output-format json \
--output-file "results/${task// /-}.json" &
done
# Wait for all background jobs
wait
echo "All tasks completed"Cause: Terminal doesn't support TTY
Solution: Use --no-interactive flag or set CLAUDE_FLOW_NON_INTERACTIVE=true
Cause: Missing authentication in non-interactive mode
Solution: Set ANTHROPIC_API_KEY or CLAUDE_API_KEY environment variable
Cause: WSL raw mode issues
Solution: Use --no-interactive flag or run in native Linux
Cause: CI environment detection
Solution: Use --output-format json or --verbose flag
Enable detailed logging for troubleshooting:
# Verbose output
npx claude-flow@alpha swarm "task" --no-interactive --verbose
# Debug environment detection
DEBUG=claude-flow:* npx claude-flow@alpha swarm "task" --no-interactive
# JSON logs for parsing
npx claude-flow@alpha swarm "task" --json-logsTest your environment setup:
# Check environment detection
npx claude-flow@alpha env check
# Validate API key
npx claude-flow@alpha auth validate --no-interactive
# Test non-interactive mode
npx claude-flow@alpha test non-interactive# In .env file
ANTHROPIC_API_KEY=sk-ant-...
# In CI/CD secrets
# GitHub: Settings > Secrets > Actions
# GitLab: Settings > CI/CD > Variables# Parse results with jq
npx claude-flow@alpha swarm "task" --output-format json | jq '.summary'
# Save for later processing
npx claude-flow@alpha swarm "task" --output-format json > results.json#!/bin/bash
set -e
npx claude-flow@alpha swarm "task" --no-interactive || {
echo "Task failed"
exit 1
}# Limit execution time
timeout 30m npx claude-flow@alpha swarm "task" --no-interactive
# Monitor memory usage
/usr/bin/time -v npx claude-flow@alpha swarm "task" --no-interactive- GitHub Actions Tutorial - Complete GitHub Actions integration
- WebSocket Server Tutorial - Headless WebSocket deployment
- Docker Guide - Containerization best practices
- API Reference - Complete API documentation