Claude Code Channels: real-time event streaming between concurrent sessions, pub/sub patterns, event filtering, cross-session state synchronization, and reactive agent workflows
Instrucciones de origen · Vista previa de solo lectura
name
channels-event-streaming
description
Claude Code Channels: real-time event streaming between concurrent sessions, pub/sub patterns, event filtering, cross-session state synchronization, and reactive agent workflows
Channels — Real-Time Event Streaming
When to activate
Running multiple Claude Code sessions that need to share state or coordinate work
Building reactive workflows that respond to events (file changes, CI results, deployment status)
Implementing pub/sub patterns where one session publishes events and others subscribe
Streaming progress updates from a long-running background session to the main session
Coordinating multi-agent workflows where agents need real-time awareness of each other's progress
Building event-driven development loops (code → test → deploy → monitor → react)
When NOT to use
Single-session workflows with no cross-session communication needs
One-shot tasks that don't benefit from event-driven architecture
Simple file-based state passing (just read/write a shared file)
When eventual consistency is fine and polling works just as well
Instructions
1. Channel Architecture
Channels provide real-time event streams between Claude Code sessions:
channel:"ci-pipeline"subscribe:filter:types: ["build.complete", "build.failed"] # only these eventson_event:build.complete:"Summarize what changed and prepare release notes"build.failed:"Analyze the error and suggest a fix"
4. Event Filtering
Reduce noise by filtering events before processing:
filters:# Type filter: only process specific event typestype: ["deploy.started", "deploy.complete", "deploy.failed"]
# Source filter: only events from specific sessionssource: ["session-ci-runner", "session-deploy-bot"]
# Data filter: match on event payload fieldsdata:environment:"production"# only production eventsseverity: ["critical", "high"] # only high-severity alerts# Rate filter: throttle high-frequency eventsrate:max_per_minute:10strategy:"latest"# keep only the latest if throttled
Session A (dev): publishes {current_file: "src/api.ts", task: "refactor auth"}
Session B (tests): subscribes → auto-runs tests on src/api.ts when it changes
Session C (docs): subscribes → updates API docs when src/api.ts changes
workflow:"parallel-research"agents:-session:"researcher-frontend"channel:"research-progress"publishes: ["topic.complete", "finding.interesting"]
-session:"researcher-backend"channel:"research-progress"publishes: ["topic.complete", "finding.interesting"]
-session:"synthesizer"channel:"research-progress"subscribes: ["topic.complete"]
on_event:"check if all topics covered, begin synthesis when ready"
Coordinating a build-test-deploy pipeline across 3 sessions:
# Session 1: Builderchannel:"release-pipeline"publish:- {type:"build.started", data: {version:"1.11.0"}}
- {type:"build.complete", data: {artifacts: ["dist/uitkit-1.11.0.tgz"]}}
# Session 2: Tester (subscribes to build events)channel:"release-pipeline"subscribe:filter: {types: ["build.complete"]}
on_event:"run full validation suite against artifacts"publish:- {type:"tests.passed", data: {coverage:87, suites:12, duration:"4m22s"}}
# Session 3: Deployer (subscribes to test events)channel:"release-pipeline"subscribe:filter: {types: ["tests.passed"]}
on_event:"deploy to staging, run smoke tests, then promote to production"publish:- {type:"deploy.complete", data: {environment:"production", url:"..."}}
Anti-Patterns
Chatty channels: Publishing every minor event floods subscribers — aggregate at source, publish only milestones
No backpressure: If publisher outpaces subscriber, events queue infinitely — set buffer limits and drop/summarize old events
Missing event types: Publishing untyped events ("something happened") makes filtering impossible — always use structured type names (domain.action)
Tight coupling: Subscriber hard-codes publisher's session ID — use channel names and event types, not session references
Silent failures: Subscriber crashes on malformed event without logging — always wrap event handlers in try/catch with dead-letter logging
Stale state: Subscribing to state changes but not requesting current state on connect — always sync initial state before processing incremental updates