{"record":{"id":"0a4994fe9a824179","repo":"mastra-ai/mastra","slug":"continue-and-thread-cannot-be-used-together","errorCode":null,"errorMessage":"--continue and --thread cannot be used together","messagePattern":"--continue and --thread cannot be used together","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/sdk/src/headless/cli.ts","lineNumber":113,"sourceCode":"  for (const flag of FLAGS) {\n    if (!flag.field) continue; // e.g. --help, handled by the caller\n    const raw = values[flag.key];\n    if (raw === undefined) continue;\n\n    if (flag.type === 'boolean') {\n      sink[flag.field] = Boolean(raw);\n    } else if (typeof raw === 'string') {\n      sink[flag.field] = flag.coerce ? flag.coerce(raw) : raw;\n    }\n  }\n\n  // A bare positional acts as the prompt when --prompt/-p is absent.\n  if (args.prompt === undefined && positionals[0] !== undefined) {\n    args.prompt = positionals[0];\n  }\n\n  if (args.continue_ && args.thread) {\n    throw new Error('--continue and --thread cannot be used together');\n  }\n\n  return args;\n}\n\nexport function printHeadlessUsage(): void {\n  process.stdout.write(`\nUsage: mastracode --prompt <text> [options]\n\nHeadless (non-interactive) mode options:\n${renderFlagUsage()}\n\nThread behavior:\n  By default, a new thread is created for each run.\n  Use --continue to resume the most recent thread, or --thread to target a specific one.\n  Use --clone-thread to branch off a copy before running.\n\nSettings file:","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/sdk/src/headless/cli.ts#L95-L131","documentation":"parseHeadlessArgs() enforces that the --continue and --thread CLI flags are mutually exclusive: --continue implicitly resumes the most recent thread, while --thread names a specific one, and both together are ambiguous. When both are set it throws during argument parsing, before any agent runs.","triggerScenarios":"Running the headless CLI with both flags, e.g. `mastracode --continue --thread abc123 ...`, or programmatic parsing of an args object where continue_ and thread are both populated (scripts that append flags conditionally).","commonSituations":"Shell aliases/wrappers that already bake in --continue while the user adds --thread; CI scripts concatenating flag arrays; migration from an older invocation pattern where --thread was assumed compatible with --continue.","solutions":["Drop --continue and keep --thread <id> when you know which thread to resume.","Drop --thread and keep --continue when you want the most recent thread.","In wrapper scripts, reject the combination early and print usage via printHeadlessUsage()."],"exampleFix":"// before\nmastracode --continue --thread thread_42 -p \"summarize\"\n// after\nmastracode --thread thread_42 -p \"summarize\"","handlingStrategy":"validation","validationCode":"if (argv.includes('--continue') && (argv.includes('--thread') || argv.some(a => a.startsWith('--thread=')))) {\n  throw new Error('--continue and --thread cannot be used together');\n}","typeGuard":"null","tryCatchPattern":"let args;\ntry {\n  args = parseHeadlessArgs(rawArgs);\n} catch (err) {\n  console.error(String(err.message));\n  printHeadlessUsage();\n  process.exit(2);\n}","preventionTips":["Pick one resume strategy per invocation: --continue for latest, --thread for specific.","Audit shell aliases/wrappers for baked-in --continue before appending --thread.","Validate flag combinations in CI scripts before invoking the CLI."],"tags":["cli","argument-parsing","conflicting-flags"],"backgroundTag":"conflicting-cli-flags","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}