@@ -233,14 +233,20 @@ function shouldRetryWithContinue({ attempt, maxRetries, exitCode, hasOutput, isN
233233
234234/**
235235 * Resolve --prompt-file arguments for the initial Claude run.
236- * Strips the --prompt-file <path> pair from args and appends the file content
237- * as the last positional argument, which is where Claude Code expects the prompt.
236+ * Strips the --prompt-file <path> pair from args and appends -- followed by
237+ * the file content as the last positional argument.
238+ *
239+ * The end-of-options marker (--) is essential: Claude Code 2.x treats any
240+ * non-flag argument that follows --mcp-config as an additional config file
241+ * path (variadic flag). Without --, a long prompt appended after
242+ * --mcp-config <path> would be used as a file path, producing an
243+ * ENAMETOOLONG error when the prompt exceeds PATH_MAX (~4096 bytes).
238244 *
239245 * For --continue retries the prompt should be omitted entirely (Claude resumes
240246 * from its on-disk session state). Call this function only for the initial run.
241247 *
242248 * @param {string[] } args
243- * @returns {string[] } Args with --prompt-file resolved to inline prompt content
249+ * @returns {string[] } Args with --prompt-file resolved to ["--", < content>]
244250 */
245251function resolveClaudePromptFileArgs ( args ) {
246252 /** @type {string[] } */
@@ -275,8 +281,13 @@ function resolveClaudePromptFileArgs(args) {
275281 i ++ ; // Skip the prompt-file path argument
276282 }
277283
278- // Append the prompt content as the last positional argument (Claude Code convention).
284+ // Append an end-of-options marker followed by the prompt content.
285+ // The '--' prevents Claude Code from treating the prompt text as an additional
286+ // --mcp-config value (Claude Code 2.x accepts that flag variadically, so any
287+ // non-flag positional argument that follows --mcp-config <path> would otherwise
288+ // be tried as a second config file path, causing ENAMETOOLONG for long prompts).
279289 if ( promptContent !== null ) {
290+ filteredArgs . push ( "--" ) ;
280291 filteredArgs . push ( promptContent ) ;
281292 }
282293
@@ -346,11 +357,12 @@ async function main() {
346357 // initialArgs carries prompt text as its last positional arg.
347358 const hadPromptFile = args . includes ( "--prompt-file" ) ;
348359
349- // Safe arg list for logging: when --prompt-file was present, the last element of
350- // initialArgs is the resolved prompt content. Replace it with a placeholder so that
351- // task instructions are never written to stderr or captured in agent logs.
352- const safeInitialArgs = hadPromptFile && initialArgs . length > 0 ? [ ...initialArgs . slice ( 0 , - 1 ) , "<prompt omitted>" ] : initialArgs ;
353- const safeFreshRetryArgs = hadPromptFile && freshRetryArgs . length > 0 ? [ ...freshRetryArgs . slice ( 0 , - 1 ) , "<prompt omitted>" ] : freshRetryArgs ;
360+ // Safe arg list for logging: when --prompt-file was present, the last two elements of
361+ // initialArgs are the -- end-of-options marker and the resolved prompt content.
362+ // Strip both and replace with a placeholder so task instructions are never written
363+ // to stderr or captured in agent logs.
364+ const safeInitialArgs = hadPromptFile && initialArgs . length > 0 ? [ ...initialArgs . slice ( 0 , - 2 ) , "<prompt omitted>" ] : initialArgs ;
365+ const safeFreshRetryArgs = hadPromptFile && freshRetryArgs . length > 0 ? [ ...freshRetryArgs . slice ( 0 , - 2 ) , "<prompt omitted>" ] : freshRetryArgs ;
354366
355367 // Fetch AWF API proxy reflection data before running the agent to capture initial proxy state.
356368 // This is best-effort: failures are logged but do not affect the agent run.
0 commit comments