Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

fix(mcp): refuse a claude_flags value after a Claude Code boolean flag

Jack Rudenko3541459b9de1
diff --git a/packages/cli/src/pane/child-flags.test.ts b/packages/cli/src/pane/child-flags.test.ts
index 464ca07e..bffc7ce2 100644
--- a/packages/cli/src/pane/child-flags.test.ts
+++ b/packages/cli/src/pane/child-flags.test.ts
@@ -89,6 +89,27 @@ describe("checkChildFlags — positionals and subcommand words", () => {
for (const w of SUBCOMMAND_WORDS) expect(refused(["--agent", w])).toContain("subcommand");
});
+ test("a token after a flag Claude Code reads as a boolean would be its first prompt: refused", () => {
+ // --verbose is claudish's own boolean, so its walker already sees a positional
+ expect(refused(["--verbose", "do X"])).toContain("positional");
+ // --brief / --ide are Claude Code booleans claudish does not know: the walker read the
+ // token as a value, Claude Code would read it as the prompt
+ expect(refused(["--brief", "do X"])).toContain("--brief takes no value in Claude Code");
+ expect(refused(["--ide", "x"])).toContain("first prompt");
+ // a flag no list knows is refused with a value rather than guessed at
+ expect(refused(["--some-future-flag", "v"])).toContain("--some-future-flag");
+ for (const ok of [
+ ["--verbose"],
+ ["--agent", "reviewer"],
+ ["--allowedTools", "Read,Bash"],
+ ["--permission-mode", "plan"],
+ ["--settings", "/s.json"],
+ ["--effort=high"],
+ ["--verbose", "--agent", "reviewer"],
+ ])
+ expect(checkChildFlags(ok)).toEqual({ ok: true });
+ });
+
test("the walker the check uses agrees with classifyPassthroughTokens", () => {
for (const flags of [
["--agent", "x"],
diff --git a/packages/cli/src/pane/pane-launch.ts b/packages/cli/src/pane/pane-launch.ts
index 5bf6f5e4..e4ba93fb 100644
--- a/packages/cli/src/pane/pane-launch.ts
+++ b/packages/cli/src/pane/pane-launch.ts
@@ -19,7 +19,12 @@ import { type ChildProcess, execFileSync, spawn } from "node:child_process";
import { randomBytes } from "node:crypto";
import { chmodSync, lstatSync, mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
import { join, resolve } from "node:path";
-import { CLAUDISH_EXITING_FLAGS, CLAUDISH_FLAG_ARITY, classifyPassthroughTokens } from "../cli.js";
+import {
+ CLAUDISH_EXITING_FLAGS,
+ CLAUDISH_FLAG_ARITY,
+ type PassthroughClassification,
+ classifyPassthroughTokens,
+} from "../cli.js";
import { ENV } from "../config.js";
import { findMagmuxBinaryOrNull } from "../launcher/magmux-binary.js";
import { STRIPPED_CHILD_VARS } from "../launcher/magmux-wrapper.js";
@@ -355,9 +360,79 @@ function splitFlag(token: string): [string, string | undefined] {
return eq > 0 ? [token.slice(0, eq), token.slice(eq + 1)] : [token, undefined];
}
+/**
+ * Claude Code flags that take a value: every option `claude --help` (2.1.291) prints with
+ * `<…>` or `[…]`, plus the `-file` variants it names in prose. Any other passthrough flag
+ * is a boolean to Claude Code, so a token after it is Claude Code's POSITIONAL PROMPT
+ * (`--verbose "do X"` boots the pane with a turn the server never typed), even though
+ * claudish's own walker reads it as the flag's value. Unknown flags are refused with a
+ * value rather than guessed at: a refusal is visible, a stray turn is not.
+ */
+export const CLAUDE_CODE_VALUE_FLAGS: readonly string[] = [
+ "--add-dir",
+ "--agent",
+ "--agents",
+ "--allowedTools",
+ "--allowed-tools",
+ "--append-system-prompt",
+ "--append-system-prompt-file",
+ "--autocompact",
+ "--betas",
+ "--cloud",
+ "-d",
+ "--debug",
+ "--debug-file",
+ "--disallowedTools",
+ "--disallowed-tools",
+ "--effort",
+ "--environment",
+ "--fallback-model",
+ "--file",
+ "--from-pr",
+ "--input-format",
+ "--json-schema",
+ "--max-budget-usd",
+ "--mcp-config",
+ "--model",
+ "-n",
+ "--name",
+ "--output-format",
+ "--permission-mode",
+ "--permission-prompt-tool",
+ "--permission-prompts",
+ "--plugin-dir",
+ "--plugin-url",
+ "--prompt-suggestions",
+ "--remote-control",
+ "--remote-control-session-name-prefix",
+ "-r",
+ "--resume",
+ "--session-id",
+ "--setting-sources",
+ "--settings",
+ "--system-prompt",
+ "--system-prompt-file",
+ "--system-prompt-snapshot",
+ "--teleport",
+ "--tools",
+ "-w",
+ "--worktree",
+];
+
+/** A value token after a passthrough flag Claude Code reads as a boolean. */
+function booleanFlagValue(c: PassthroughClassification): { flag: string; value: string } | null {
+ for (const t of c.tokens) {
+ if (t.kind !== "passthrough-value") continue;
+ const flag = splitFlag(c.tokens.find((x) => x.index === t.index - 1)?.token ?? "")[0];
+ if (!CLAUDE_CODE_VALUE_FLAGS.includes(flag)) return { flag, value: t.token };
+ }
+ return null;
+}
+
/**
* The server-side check of `claude_flags` (D18): reserved tokens, subcommand words, and
- * any positional token or `--` (claudish would turn a positional into a `-p` prompt).
+ * any positional token or `--` (claudish would turn a positional into a `-p` prompt),
+ * including a value after a flag Claude Code reads as a boolean.
*/
export function checkChildFlags(flags: string[]): FlagCheck {
for (const token of flags) {
@@ -384,6 +459,12 @@ export function checkChildFlags(flags: string[]): FlagCheck {
ok: false,
message: `claude_flags contains a positional token (${JSON.stringify(c.positionals[0])}); claudish takes one value per flag: write \`--allowedTools Read,Bash\``,
};
+ const stray = booleanFlagValue(c);
+ if (stray)
+ return {
+ ok: false,
+ message: `claude_flags: ${stray.flag} takes no value in Claude Code, so ${JSON.stringify(stray.value)} would become the session's first prompt; pass the flag alone`,
+ };
return { ok: true };
}