How Do Multiple Claude Code Instances Talk to Each Other? A Deep Dive into AI Agent Team Collaboration Mechanisms

How multiple Claude Code instances communicate using file-based Pub/Sub and signal mechanisms for AI Agent teamwork.
This article explores the underlying communication mechanisms that enable multiple Claude Code instances to collaborate as an AI Agent team. It covers the Pub/Sub publish-subscribe pattern, file-based signal monitoring, and inbox file systems that allow Agents to send, receive, and process messages autonomously. The approach uses files as message queues and file change events as triggers, providing a lightweight yet effective alternative to complex networking protocols for inter-Agent communication.
When building AI Agent teams, a core question emerges: how do multiple AI agents (such as Claude Code instances) actually interact and collaborate? This article, based on the third installment of a Chinese Bilibili creator's series on "Building AI Teams," breaks down the underlying mechanisms that enable AI Agents to communicate with each other, helping readers build a clear technical understanding of the architecture involved.
Three Core Dimensions of AI Team Collaboration
Before diving into the specifics, we need to understand the three dimensions of AI team collaboration, which provide the conceptual framework for the entire system design.
The first dimension is how roles interact with each other. If a team has three roles, how exactly do they pass information and collaborate? This forms the skeleton of the entire system. In Multi-Agent System (MAS) research, interaction patterns typically fall into two paradigms: centralized orchestration (where one primary Agent dispatches tasks to others) and decentralized negotiation (where Agents communicate as equals). The chosen interaction pattern directly impacts the system's flexibility and robustness.
The second dimension is context management. During conversations, an AI's context window gradually fills up or even loses information. Ensuring collaboration continuity under these conditions is an engineering challenge that must be addressed. A large language model's Context Window refers to the maximum number of tokens the model can process in a single inference pass — Claude 3.5 Sonnet supports 200K tokens, while DeepSeek-V3 supports 128K tokens. In multi-Agent continuous dialogue scenarios, as messages accumulate, the context window gradually fills up, causing early information to be truncated or forgotten. Common engineering strategies include: summarizing and compressing conversation history, using external memory storage (such as vector databases), and controlling context growth rate by clearing already-read messages.
The third dimension is task progression workflow. When a team receives a task, how do you achieve a step-by-step progression of "analyze first, design second, develop third," enabling multiple Agents to collaboratively complete an entire workflow?
This article focuses on the first dimension — the interaction mechanisms between Agents.
Claude Code's Native Agent Team Capabilities and Their Limitations
The concept of an Agent Team isn't new. Claude Code itself has built-in functionality similar to this — you can assign it a task, such as "conduct a research investigation for me," and it will internally spawn multiple instances that operate in parallel: one handles the investigation, one handles review, one handles follow-up processing, and they can collaborate with each other.
It's worth explaining Claude Code's operating model here: Claude Code is a command-line AI coding tool released by Anthropic. Each instance is essentially an independent terminal process with its own context window and tool-calling capabilities. It supports extending tools via MCP (Model Context Protocol) and can call custom functions to perform file read/write operations, command execution, and more. Multiple Claude Code instances can run in parallel on the same machine, each maintaining independent conversation state. This process-level isolation ensures stability while providing a natural concurrency foundation for multi-Agent collaboration.

However, this native mode has obvious limitations. Once a task is completed, these instances terminate and stop right there. While you can choose not to close them and keep them alive, they lack sustained, flexible communication channels. You can use keyboard arrow keys to view the status of these instances, but the entire operation process is quite cumbersome and the user experience is far from friendly.
In other words, the native Agent Team is better suited for "one-off tasks" rather than sustained team collaboration.
A More Intuitive Multi-Agent Dialogue Interface
To address the shortcomings of the native mode, the author demonstrated a multi-Agent dialogue interface solution that better aligns with human usage habits.
In this interface, several AI roles are given names, such as "Lishi," "Shali," "Catherine," etc. Users can issue instructions as if speaking to a real team: "Go chat with the whole team and figure out what we should do next." Then, one Agent thinks it through, sends messages to other members, and the team begins a collective discussion.

Here's a noteworthy practical insight: Model selection directly impacts response speed. Using a high-performance model like Opus results in slower Agent thinking and responses, while switching to DeepSeek-series models noticeably speeds up team discussions. The reason behind this is that different large language models have significant differences in inference speed. Claude Opus, as Anthropic's flagship model, has a large parameter count and strong reasoning capabilities, but response latency typically ranges from 10-30 seconds. DeepSeek-series models (such as DeepSeek-V3, DeepSeek-R1) maintain strong capabilities while offering faster inference speeds and lower API prices. In multi-Agent scenarios, a single complete team discussion may involve dozens of model calls, and latency gets amplified several times over. Therefore, choosing a high-value, low-latency model is critical for the actual experience. The author's demonstrations all use DeepSeek models, which is why the Agents can "chat" rapidly, reach conclusions after discussions, and report back to the user.
For daily use, it's recommended to have a 4K large-format display so you can clearly see multiple Agent dialogue windows simultaneously for a more comfortable experience.
Under the Hood: Pub/Sub + Signal Mechanism Explained
So how exactly do these Agents pass information to each other? This is the most critical part of the entire solution. Implementing this mechanism requires coding ability — "people without coding skills can hardly imagine how the internal mechanism can be properly implemented."
Before getting into the specific implementation, some background: Pub/Sub (Publish/Subscribe) is a classic message-passing pattern in distributed systems, widely used in middleware such as Apache Kafka, Redis Pub/Sub, and Google Cloud Pub/Sub. Its core idea is to decouple message producers from consumers — publishers don't need to know who's receiving messages, and subscribers don't need to know where messages come from. In traditional software architecture, this pattern is commonly used for event-driven communication between microservices. In this AI Agent team solution, Pub/Sub is cleverly simplified to a file-level implementation, dramatically reducing infrastructure complexity.
The Inbox Is Essentially a File
The core idea is: Each Agent has an "inbox," and this inbox is essentially a file (or folder). When an Agent wants to send a message, it calls a function to deliver the information, while simultaneously appending a line of text to a related file as a signal.

The Complete Signal-Triggered Listening Flow
The entire system uses a Pub/Sub (Publish/Subscribe) plus Signal architecture. The Signal mechanism here relies on operating system-level file monitoring capabilities — in Linux, the inotify API can monitor file creation, modification, deletion, and other events; on macOS, the equivalent is the FSEvents framework; in Node.js, commonly used libraries include fs.watch and chokidar. Since Claude Code is a terminal-based AI coding assistant with native file system read/write capabilities, using file changes as signal triggers is an extremely low-cost Inter-Process Communication (IPC) approach that avoids the need to introduce complex network protocols like WebSocket or gRPC.
The specific flow works as follows:
- Send message: The sender calls a function to deliver the message to the recipient's inbox file;
- Write signal: Simultaneously, a line of text is appended to a monitored signal file;
- Trigger reading: The recipient's Claude Code continuously monitors this file — as soon as the file is modified, it triggers a read of its own inbox;
- Process message: The recipient calls another function to read all messages from the inbox, hands them off for processing, and then clears these read messages.

This way, when a message is broadcast, all relevant Agents receive the signal, call functions to read the information, think and process independently, and then send a reply message informing the rest of the team: "Here's my response after thinking it through."
It's worth noting that while this file-based message queue approach is simple, it's fundamentally consistent with the core principles of industrial-grade message middleware: producers write messages to a queue (file), consumers read and process messages from the queue, and acknowledge consumption upon completion (clear read messages). It's a "minimum viable product" level implementation that works perfectly well in scenarios with a modest number of Agents and moderate communication frequency.
Broadcasting Beats One-on-One Communication: A Practical Insight
Regarding interaction strategy, an important lesson learned through testing is: "One-on-one" communication often yields worse results than broadcasting information directly to all members.
When a message is broadcast to the entire team, the Supervisor (the orchestrating role) can also see it. The Supervisor pattern is a classic orchestration pattern in multi-Agent systems, widely adopted in mainstream multi-Agent frameworks such as LangGraph, CrewAI, and AutoGen: a central Agent handles task decomposition, assignment, and result aggregation, while other Agents serve as executors completing specific subtasks. The advantage of this pattern is controllable workflow and clear responsibilities; the disadvantage is that the Supervisor can become a bottleneck for information relay. In this article's approach, the broadcast mechanism partially alleviates this problem — since all members can see global information, the Supervisor plays more of a decision-making role rather than an information relay station. It can evaluate and filter, and may even discover that a team member has raised a point it hadn't previously considered, prompting another round of thinking and continued contribution. This open information flow actually stimulates more thorough collaboration and thinking.
Additionally, you can use Prompts to constrain Agent behavior, for example:
- "You must reply once you receive a request"
- "After processing information, proactively send a message to notify the team"
- "The user is busy — don't keep asking them questions"
These rules are essentially defining Agent Behavioral Protocols using natural language. In traditional distributed systems, such rules are typically implemented through strict code logic and state machines; in LLM-driven Agent systems, using Prompts to constrain behavior is a more flexible but also more uncertain approach. In practice, repeated testing and tuning are necessary to ensure Agents follow preset rules across various edge cases.
These rules collectively ensure the autonomy and continuity of team collaboration. Ultimately, after all Agents finish processing, results are aggregated and returned to the orchestrator, which decides whether to proceed to the next workflow stage.
Summary: Building a Sustainably Operating AI Agent Team
This mechanism based on Pub/Sub and file signal monitoring, while dependent on coding ability for implementation, follows a remarkably clear logic: Use files as message queues, use file modification events as signal triggers, and let multiple independent Claude Code instances send and receive messages and collaborate like team members.
For developers looking to build AI Agent teams, this provides a pragmatic and implementable reference architecture. It circumvents the native Agent Team's limitation of "terminating when the task ends," achieving a sustainably operating, visual, broadcastable multi-Agent collaboration system. Unlike the high-level abstractions provided by frameworks like LangGraph and CrewAI, this approach is more low-level and transparent — developers can fully control every step of the message flow, making it easier to customize and debug according to actual needs.
Of course, issues like model selection, context management, and task workflow progression still need to be addressed in ongoing practice. As AI Agent capabilities continue to strengthen, the "AI team" paradigm is likely to become an important model for future software development and automation workflows. Understanding the underlying interaction mechanisms is the first step toward building reliable AI teams.
Related articles

Edu-QuRating: How Multi-Dimensional Educational Data Curation Improves LLM Training Quality
Deep dive into the Edu-QuRating multi-dimensional educational data curation framework, achieving 0.917 accuracy via distilled pairwise judgments across six dimensions to improve LLM pre-training and GRPO post-training.

The AI Filmmaking Cost Revolution: A $2 Million Production Completed for $90
A creator spent just $90 on AI tools to independently produce a short film that would traditionally cost $2 million. Explore how AI is revolutionizing filmmaking from visuals to voice to music.

Vercel AI SDK xAI Integration Adds Batch Management Features
Vercel AI SDK xAI provider releases v4.0.57 with batch cancellation and listing features, improving cost management and task observability for Grok model apps.