Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

πŸ”– Checkpoint: Edit /workspaces/claude-code-flow/docs/stream-chaining.md

rUvc37771442002
diff --git a/.claude/checkpoints/task-1754397364.json b/.claude/checkpoints/task-1754397364.json
new file mode 100644
index 0000000000..8b5de00a38
--- /dev/null
+++ b/.claude/checkpoints/task-1754397364.json
@@ -0,0 +1 @@
+{"checkpoint": "task-20250805-123603", "task": "{{user_prompt}} ", "timestamp": "2025-08-05T12:36:04Z", "commit": "c60e843554eb6e05fcb641dd77c1ff0df38de5b0", "github_release": "true"}
diff --git a/docs/stream-chaining.md b/docs/stream-chaining.md
index a891eea278..acf1c53aaa 100644
--- a/docs/stream-chaining.md
+++ b/docs/stream-chaining.md
@@ -1,22 +1,75 @@
# Stream-JSON Chaining in Claude Flow
-## Overview
+## πŸ” Overview: Stream Chaining in Claude Code
+
+**Stream chaining** in Claude Code is the technique of connecting multiple `claude -p` (non-interactive) processes using real-time **JSON streams**, allowing you to build **modular, recursive, multi-agent pipelines**.
Stream-JSON chaining enables Claude instances to pipe their outputs directly to other Claude instances, creating a seamless workflow where agents can build upon each other's work without intermediate storage.
-## How It Works
+## 🧱 How It Works
-When tasks have dependencies and stream-json output format is enabled, Claude Flow automatically:
+### Core Claude Code Flags
+
+Claude Code supports two key flags that enable stream chaining:
-1. Captures the stdout from the first agent
-2. Pipes it directly to the stdin of the dependent agent
-3. Adds `--input-format stream-json` flag to the receiving agent
-4. Maintains the stream connection throughout execution
+* `--output-format stream-json`: emits newline-delimited JSON (`NDJSON`) with every token, turn, and tool interaction
+* `--input-format stream-json`: accepts a stream of messages in NDJSON format, simulating a continuous conversation
-## Example Flow
+By combining them:
+```bash
+claude -p --output-format stream-json "First task" \
+ | claude -p --input-format stream-json --output-format stream-json "Process results" \
+ | claude -p --input-format stream-json "Final report"
```
-Agent A (analyzer) β†’ stdout (stream-json) β†’ stdin β†’ Agent B (processor) β†’ stdout β†’ stdin β†’ Agent C (reporter)
+
+Each agent processes input, emits structured responses, and hands them off to the next agent in the chain.
+
+### Automatic Chaining in Claude Flow
+
+When tasks have dependencies and stream-json output format is enabled, Claude Flow automatically:
+
+1. Detects task dependencies from workflow definitions
+2. Captures the stdout stream from the dependency task
+3. Pipes it directly to stdin of the dependent task
+4. Adds `--input-format stream-json` flag to the receiving agent
+5. Maintains the stream connection throughout execution
+
+## πŸ”„ What You Can Do With Stream Chaining
+
+* **Subagent orchestration**: planner β†’ executor β†’ reviewer
+* **Recursive pipelines**: refinement loops, ablation agents, iterative optimization
+* **Live feedback systems**: feed Claude output into a scoring or mutation agent
+* **Task decomposition**: outer loop breaks work into subtasks, inner loop completes each
+* **Multi-stage analysis**: data analysis β†’ feature engineering β†’ model training β†’ validation
+* **Complex workflows**: research β†’ design β†’ implementation β†’ testing β†’ documentation
+
+## 🧠 Key Features
+
+### Structured Message Types
+
+Stream-JSON format includes structured message types:
+- `init`: Session initialization
+- `message`: Assistant/user messages
+- `tool_use`: Tool invocations with parameters
+- `tool_result`: Tool execution results
+- `result`: Final task completion status
+
+### Advanced Control Options
+- Supports `--session` for session management
+- `--max-turns` for granular conversation control
+- Works seamlessly with shell scripts, `jq`, and Python SDKs
+- Can simulate multi-turn conversation without REPL
+- Preserves full context including reasoning and tool usage
+
+### Example Stream-JSON Output
+
+```json
+{"type":"init","session_id":"abc123","timestamp":"2024-01-01T00:00:00Z"}
+{"type":"message","role":"assistant","content":[{"type":"text","text":"Analyzing data..."}]}
+{"type":"tool_use","name":"Bash","input":{"command":"ls -la"}}
+{"type":"tool_result","output":"total 64\ndrwxr-xr-x 10 user staff 320 Jan 1 00:00 ."}
+{"type":"result","status":"success","duration_ms":1234}
```
## Enabling Stream Chaining