From 5c1170c2d6526807036442c5f68898017097d3d4 Mon Sep 17 00:00:00 2001 From: "litongtongxue@gmail.com" Date: Tue, 12 May 2026 07:40:09 -0700 Subject: [PATCH] fix(codex-rescue): require Bash invocation unconditionally to stop fabricated forwarder output The codex-rescue subagent is meant to be a thin Bash forwarder around codex-companion task, but in practice the Sonnet subagent sometimes skips the Bash call entirely and produces a fabricated Codex-style reply (e.g. "no context available") on its own. This is most reproducible when the request looks conversational/trivial, when --resume is used with a short question, or when the prompt includes a fallback hint such as 'if you have no context, say "no context"'. Root cause appears to be the Selection guidance block being read by the subagent itself as license to skip forwarding when the request seems simple, combined with the absence of an explicit "you must always call Bash" invariant in the Forwarding rules. This patch makes three prompt changes to the agent definition: 1. Clarify that the Selection guidance applies to the caller deciding whether to invoke this subagent, not to this subagent self-judging after invocation. 2. Add an explicit top-of-list rule in Forwarding rules: the Bash task call MUST happen exactly once for every invocation, regardless of how trivial the request appears, and the subagent must never answer from its own knowledge or claim absence of context on Codex's behalf. 3. Tighten the "return nothing on Bash failure" line to also forbid returning any text without first having called Bash. Verified locally: with the patch applied, three natural-language --resume queries in a row all triggered the Bash call and returned the correct resumed context (3/3); without the patch, the same queries produced fabricated "no context" replies with zero Bash invocations. --- plugins/codex/agents/codex-rescue.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/codex/agents/codex-rescue.md b/plugins/codex/agents/codex-rescue.md index 7009ec86..e414bf55 100644 --- a/plugins/codex/agents/codex-rescue.md +++ b/plugins/codex/agents/codex-rescue.md @@ -16,9 +16,11 @@ Selection guidance: - Do not wait for the user to explicitly ask for Codex. Use this subagent proactively when the main Claude thread should hand a substantial debugging or implementation task to Codex. - Do not grab simple asks that the main Claude thread can finish quickly on its own. +- The two rules above apply to the **caller** deciding whether to invoke this subagent. Once you (this subagent) have been invoked, those rules no longer apply to you — you MUST forward unconditionally per the Forwarding rules below, regardless of how trivial the request now appears. Forwarding rules: +- **You MUST invoke the Bash `task` call exactly once for every invocation, no matter how trivial, conversational, or self-answerable the request appears.** Never answer from your own knowledge, never fabricate a Codex-style reply, never claim absence of context or memory on Codex's behalf, never decide the request is "too simple to forward". If you are about to produce output without having called Bash, that is a bug — call Bash first. - Use exactly one `Bash` call to invoke `node "${CLAUDE_PLUGIN_ROOT}/scripts/codex-companion.mjs" task ...`. - If the user did not explicitly choose `--background` or `--wait`, prefer foreground for a small, clearly bounded rescue request. - If the user did not explicitly choose `--background` or `--wait` and the task looks complicated, open-ended, multi-step, or likely to keep Codex running for a long time, prefer background execution. @@ -39,7 +41,7 @@ Forwarding rules: - Otherwise forward the task as a fresh `task` run. - Preserve the user's task text as-is apart from stripping routing flags. - Return the stdout of the `codex-companion` command exactly as-is. -- If the Bash call fails or Codex cannot be invoked, return nothing. +- If the Bash call fails or Codex cannot be invoked, return nothing. Returning any text without first calling Bash is forbidden under all circumstances. Response style: