Skip to content

Clarify Claude reply routing in paired mode#36

Merged
axeldelafosse merged 8 commits intomainfrom
fix/claude-reply-routing
Mar 25, 2026
Merged

Clarify Claude reply routing in paired mode#36
axeldelafosse merged 8 commits intomainfrom
fix/claude-reply-routing

Conversation

@axeldelafosse
Copy link
Owner

Summary

  • teach Claude tmux prompts to use the reply tool for Codex channel replies and keep proactive messages on send_to_agent
  • make forwarded paired-loop prompts explicitly route replies back to the peer instead of the human
  • add regression coverage for tmux prompts, bridge instructions, and forwarded bridge prompts

Verification

  • bun test tests/loop/bridge.test.ts tests/loop/paired-loop.test.ts tests/loop/tmux.test.ts
  • bun run check
  • git diff --check

Review

  • Self-review: PASS
  • Claude peer review: PASS

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the communication protocols between Claude and Codex agents in paired mode. The primary goal is to improve the clarity and correctness of message routing, ensuring that agents use the appropriate tools for replies and proactive messages, and preventing unintended human interaction in agent-to-agent conversations. These changes aim to streamline the agent collaboration workflow and reduce potential confusion.

Highlights

  • Claude Prompt Refinement: Refined Claude's prompt instructions in tmux mode to ensure the 'reply' tool is used for inbound Codex messages and 'send_to_agent' for proactive messages.
  • Paired-Loop Reply Routing: Updated paired-loop prompts to explicitly direct forwarded replies back to the peer agent, preventing unintended human intervention.
  • Test Coverage Expansion: Expanded test coverage to include new instructions for tmux prompts, bridge guidance, and forwarded bridge prompts, ensuring correct behavior.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refines and clarifies the instructions given to agents (Claude and Codex) in a paired programming/review setup, particularly concerning interactions with the human and the appropriate use of bridge tools. The changes aim to prevent agents from directly answering the human when a response is expected by the peer agent and to provide more precise guidance on when to use send_to_agent or reply. The review comments suggest further improvements by breaking down multi-part instructions into single, distinct lines or parts.push() calls to enhance clarity for the agents and improve prompt readability and maintainability.

[
`Messages from the Codex agent arrive as <channel source="${BRIDGE_SERVER}" chat_id="..." user="${CLAUDE_CHANNEL_USER}" ...>.`,
'When you are replying to an inbound channel message, use the "reply" tool and pass back the same chat_id.',
"Never answer the human when the inbound message came from Codex. Send the response back through the bridge tools instead.",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This line contains two distinct instructions. To improve clarity for the agent, it would be better to split them into separate lines.

Suggested change
"Never answer the human when the inbound message came from Codex. Send the response back through the bridge tools instead.",
"Never answer the human when the inbound message came from Codex.",
"Send the response back through the bridge tools instead.",

"Paired mode:",
`You are in a persistent Claude/Codex pair. Use the MCP tool "send_to_agent" when you want ${peer} to act, review, or answer.`,
'Do not ask the human to relay messages between agents. Use "bridge_status" if you need the current bridge state.',
'Do not ask the human to relay messages between agents or answer the human on the other agent\'s behalf. Use "bridge_status" if you need the current bridge state.',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This line combines multiple instructions. For better clarity for the agent, consider splitting it into separate lines, each with a single instruction.

    'Do not ask the human to relay messages between agents.',
    'Do not answer the human on the other agent\'s behalf.',
    'Use "bridge_status" if you need the current bridge state.',

`Message from ${capitalize(source)} via the loop bridge:`,
message.trim(),
"Treat this as direct agent-to-agent coordination. Reply with send_to_agent only when you have something useful for the other agent to act on. Do not acknowledge receipt without new information.",
"Treat this as direct agent-to-agent coordination. Do not reply to the human.",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better clarity and to ensure each instruction is distinct for the agent, consider splitting this line into two separate instructions. This aligns with the goal of breaking down complex instructions into simpler, more direct ones.

Suggested change
"Treat this as direct agent-to-agent coordination. Do not reply to the human.",
"Treat this as direct agent-to-agent coordination.",
"Do not reply to the human.",

src/loop/tmux.ts Outdated
"You are in a persistent Claude/Codex pair.",
'When Codex sends you an inbound channel message, reply to Codex with the MCP tool "reply" and reuse the same chat_id.',
'Use "send_to_agent" only when you need to start a new proactive message to Codex.',
"Do not ask the human to relay messages between agents. Do not answer the human when Codex is waiting for the response.",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve clarity for the agent, consider splitting this line into two separate instructions. This ensures each directive is distinct and easy to process.

Suggested change
"Do not ask the human to relay messages between agents. Do not answer the human when Codex is waiting for the response.",
"Do not ask the human to relay messages between agents.",
"Do not answer the human when Codex is waiting for the response.",

Comment on lines 233 to 235
parts.push(
`Your first action is to use "send_to_agent" to tell ${primary}: "Reviewer ready. No task yet. I am waiting for your request." After that, wait for the human or ${primary} to provide a concrete task or review request.`
`Your first action is to use "send_to_agent" to tell ${primary}: "Reviewer ready. No task yet. I am waiting for your request." After that, wait for ${primary} to provide a concrete task or review request. If the human clearly assigns you separate work in this pane, treat that as a new task. If you are answering ${primary}, use the bridge tools instead of a human-facing reply.`
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This parts.push() call adds a long string with multiple concatenated instructions. For better readability and maintainability of the prompt, and to make instructions clearer for the agent, consider breaking this down into multiple parts.push() calls. Each call would add a distinct instruction, which will be separated by double newlines in the final prompt. This aligns with the principle of using newline-delimited messages for agent communication, as outlined in the rules.

For example:

  parts.push(
    `Your first action is to use "send_to_agent" to tell ${primary}: "Reviewer ready. No task yet. I am waiting for your request."`
  );
  parts.push(
    `After that, wait for ${primary} to provide a concrete task or review request.`
  );
  parts.push(
    `If the human clearly assigns you separate work in this pane, treat that as a new task.`
  );
  parts.push(
    `If you are answering ${primary}, use the bridge tools instead of a human-facing reply.`
  );
References
  1. When communicating between agents in a paired tmux runtime, use newline-delimited JSON on stdout for agent CLIs, as Content-Length framing can break registration/connection. This principle extends to structuring prompts for clarity and distinct instructions, ensuring agents process messages correctly.

@axeldelafosse axeldelafosse marked this pull request as ready for review March 25, 2026 05:39
@axeldelafosse axeldelafosse merged commit 0a73ce6 into main Mar 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant