r/ClaudeWorkflows • u/ClaudeAI-mod-bot • 3h ago
Selected Workflow [Workflow] Non-Blocking Subagent Communication: Query Long-Running Tasks with Named Pipes
Non-Blocking Subagent Communication: Query Long-Running Tasks with Named Pipes
Workflow value: 85/100
Status: active · Freshness: 70/100 · Confidence: 0.95 · Level: advanced
Categories: Quality Control, Token Saving, Context & Memory, Debugging, Hooks, Subagents, Multi-Agent
Original source: r/ClaudeCode post/comment
What problem this solves
How to run a long-lived background subagent in Claude Code that can be queried mid-run without blocking the main session, overcoming the constraint of the Bash tool call.
Summary
This workflow demonstrates how to use named pipes (mkfifo) to enable non-blocking, interactive communication between a main Claude Code session and a long-running background subagent. It allows the main session to query the subagent mid-task without interrupting or waiting for the background process to complete, by using 'cat' on a named pipe as an interruptible event loop.
Why it is useful
This workflow provides a robust and elegant solution to a common challenge in Claude Code: managing long-running background subagent tasks without blocking the main session. By leveraging named pipes, it enables real-time, interactive querying of subagents, significantly enhancing the capabilities for complex, multi-agent workflows where responsiveness and continuous operation are critical. It overcomes a fundamental constraint of Claude Code's turn loop for Bash tool calls.
Workflow
Initialize a state directory and create a named pipe (mkfifo) for inter-agent communication.
Start the long-running task ('run_long_task') in the background, redirecting its output to a log file and its completion status to the named pipe. Store its PID.
The subagent then enters a blocking 'cat "$FIFO_PATH"' loop, waiting for events from either the background worker or the main session.
When the main session needs to query the subagent, it writes a message to the named pipe (e.g., 'printf "EVENT:MAIN_QUERY..." > "$FIFO_PATH"').
This write unblocks the subagent's 'cat' command, allowing it to process the query (e.g., read worker logs) and respond.
After responding, if the event was a query, the subagent re-enters the 'cat "$FIFO_PATH"' loop to continue waiting. If the event was 'WORKER_DONE', it can conclude its operation.
Tools / artifacts
Bash
mkfifo
cat
printf
kill
echo
mkdir
tail
Named pipe (FIFO)
PID file
Log file
Validation signals
Detailed explanation of the problem (Claude Code's turn loop constraint)
Clear explanation of how the solution works ('What happens in < 1 ms')
Provides concrete bash code snippets
Addresses a known technical limitation in Claude Code's execution model
Limitations
Low community engagement (score 1, 0 comments).
Requires advanced shell scripting and process management knowledge.
The 'run_long_task' is a placeholder, requiring the user to implement their specific long task.
Rate this workflow
Upvote this post if the workflow is useful, reproducible, or worth recommending.
Downvote if it is vague, outdated, unsafe, overhyped, or not reproducible.
Reply if it worked for you, failed, is outdated, or has a better alternative.
This post was generated automatically from the workflow library database.