Skip to content

claude: SessionOptions.resume and fork allow CLI flag injection and title resolution; guard argv resume values across adapters #975

Closed

Description

@stamp-build

Summary

When an adapter passes caller-supplied SessionOptions.resume into CLI argv as a separate token (or unguarded positional argument) without checking canonical ID shape or confirming the opened native session ID, a runtime whose --resume flag accepts an optional value or session title interprets options.resume as a CLI flag or title.

On Claude (packages/oar/src/runtimes/claude/launch.ts:42-47, packages/oar/src/runtimes/claude/session.ts:17,34, packages/oar/src/runtimes/claude/open-settings.ts:97-102,129-145 at main 7d0318ee), claudeSessionArgs passes ["--resume", sessionId] on plain resume and ["--resume", options.resume, "--fork-session", "--session-id", sessionId, ...] on fork as separate argv tokens (even though through on line 46 uses --resume-session-at=${through} specifically so dash-leading values cannot be parsed as flags), and claudeSession only runs confirmSessionId(sessionId) when options.fork !== undefined. Note that SessionOptions.resume is also reachable from external callers through oar mcp's run tool (packages/cli/src/mcp-tools.ts:53).

All live reproductions below ran on Linux x64 in isolated temporary HOME and workspace directories against local synthetic aimock HTTP providers with zero real credentials, accounts, or paid model calls.

Live Reproductions on Claude Code 2.1.326 and 2.1.328

1. CLI flag injection via options.resume on plain resume and fork

Claude's -r, --resume [value] takes an optional argument, and packages/oar/src/runtimes/claude/launch-args.ts:13-14 explicitly forbids -c and --continue ("OAR assigns the session id; use SessionOptions.resume with the id to continue"). Because claudeSessionArgs passes ["--resume", value] as two tokens, any dash-leading options.resume leaves --resume valueless and is parsed by Claude as a CLI flag:

  • Plain resume hijack ({ cwd, resume: "-c" } and { cwd, resume: "--continue" }):
    claudeRuntime.session(inst, { cwd, resume: "-c" }) opens without error, attaches to and mutates the most recent saved session in cwd (replaying its saved prompt/assistant history to the provider on the next turn), while session.id === "-c" and every emitted OAR record stamps sessionId: "-c" even though system/init.session_id and get_status report the hijacked session's UUID.
  • Fork hijack ({ cwd, resume: "-c", fork: {} }):
    claudeRuntime.session(inst, { cwd, resume: "-c", fork: {} }) spawns claude ... --resume -c --fork-session --session-id <new-uuid>. confirmSessionId(<new-uuid>) passes because --session-id assigns <new-uuid> to the forked transcript, and Claude silently forks the most recent saved session in cwd instead of failing on "-c".
  • --flag=value control:
    Passing --resume=-c prevents -c from being parsed as --continue; Claude exits immediately with Error: --resume requires a valid session ID or session title when used with --print (-p). Provided value "-c" is not a UUID and does not match any session title.

2. Session title resolution (--name) and Session.id / record mismatch

Claude Code 2.1.326 and 2.1.328 resolve -p --resume <session-id|title> against saved session titles (SessionOptions.name / --name) as well as UUIDs:

  • With a single saved session named "UNIQUE_TITLE_ONE" (UUID a1c1eea1-cb11-4dd0-be73-3481755f8074), claudeRuntime.session(inst, { cwd, resume: "UNIQUE_TITLE_ONE" }) opens and mutates a1c1eea1-... (replaying its transcript to the provider) while reporting session.id === "UNIQUE_TITLE_ONE" and stamping sessionId: "UNIQUE_TITLE_ONE" on every OAR record (system/init.session_id reports a1c1eea1-...).
  • claudeRuntime.session(inst, { cwd, resume: "UNIQUE_TITLE_ONE", fork: {} }) likewise resolves "UNIQUE_TITLE_ONE" by title and forks a1c1eea1-... into a new UUID.
  • When multiple saved sessions in cwd share the same title, --resume "<title>" fails startup listing their UUIDs (--resume "SOURCE_TITLE" matches 3 sessions...).

3. Missing-resume error drift for non-UUID values (open-settings.ts:97-101)

packages/oar/src/runtimes/claude/open-settings.ts:97-101 classifies SessionNotFoundError by matching native.errors[0].startsWith("No conversation found with session ID") (pinned by tests/fixtures/claude-missing-resume.json, which uses "claude-resume-secret-sentinel").

On live Claude Code 2.1.326 and 2.1.328:

  • A missing canonical UUID ("00000000-0000-4000-8000-000000000099") still emits "No conversation found with session ID: ..." and throws SessionNotFoundError.
  • Any non-UUID string that matches no title (including "claude-resume-secret-sentinel") now emits 'Error: --resume requires a valid session ID or session title when used with --print (-p). Provided value "..." is not a UUID and does not match any session title.', so open-settings.ts:102 throws a plain Error instead of SessionNotFoundError.

4. confirmSessionId redaction and error-cause gap (open-settings.ts:140-141)

Unlike confirm() (open-settings.ts:80,93-102), confirmSessionId throws new Error(refusal) directly without passing refusal through sessionCredentialRedactor(options) or attaching nativeErrorCause("get_status", ...).

Cross-Runtime Audit of the Class (SessionOptions.resume)

Checked all 14 core runtimes at 7d0318ee (static audit of all 14 plus live adversarial probes with "", "-c", "--continue", "--help", "UNIQUE_TITLE_ONE", and "id\0<secret>" across claude 2.1.326/2.1.328, codex 0.169.0/0.170.0, qwen 0.27.4, qoder 1.1.81, opencode 1.19.5, grok 1.0.70, kimi 2.6.3, factory 1.12.1, dsh 0.2.1-rc.5, pi-durable 1.5.2, and antigravity 1.5.11):

  • OpenCode v1 (packages/oar/src/runtimes/opencode/prompt-config.ts:77): Secondary argv instance when options.systemPrompt is combined with options.resume. query(command, ["export", options.resume, "--sanitize"], ...) spawns opencode export before opening ACP:
    • resume: "" causes opencode 1.19.5 export to treat sessionID as omitted, launch its interactive TUI (Select session to export), and hang for the full 30_000 ms timeout before SIGTERM.
    • resume: "-c" / "--continue" / "--help" is parsed as a yargs CLI flag by opencode export (--help prints help text to stdout and fails JSON.parse).
  • Qwen (packages/oar/src/runtimes/qwen/launch.ts:16, qwen/session.ts:57) and Qoder (packages/oar/src/runtimes/qoder/launch.ts:52): Both also pass ["--resume", sessionId] as two tokens in argv (on Qoder when protocol !== "daemon"). Live qwen 0.27.4 and qoder 1.1.81 rejected all 6 adversarial inputs, and qwen/session.ts:57 already verifies native?.session_id === sessionId, but using --resume=${sessionId} (or shared input validation) removes any reliance on native flag-parser details.
  • Codex, Grok, Kimi, Factory, DSH, Pi, Pi Durable, Antigravity, Cursor, Devin, CodeBuddy: Pass resume over structured JSON-RPC / SDK calls or validate session ID format before launch; all live probes rejected all 6 inputs without opening a session or leaking credentials.

Suggested Direction (Fix the Class)

  1. Guard CLI resume arguments with one shared check (rejecting empty, NUL-containing, or dash-leading strings before spawning any child process, including opencode/prompt-config.ts:77) and pass --resume=${...} in claude/launch.ts:44,46 (and qwen/launch.ts:16 / qoder/launch.ts:52 if supported by their parsers, verified against native binaries).
  2. On Claude, enforce canonical session ID identity (either rejecting non-UUID options.resume like Codex or running confirmSessionId(sessionId) on plain resume as well as fork so title-resolved mismatches cannot slip through with a wrong Session.id), align non-UUID missing-resume handling with SessionNotFoundError, and wire sessionCredentialRedactor(options) + nativeErrorCause into confirmSessionId.
  3. Add a cross-runtime SessionOptions.resume contract test covering "", "-c", "--continue", and non-ID title strings across adapters.

Lookout opened this issue through Stamp · server open-agent-runtime
View in Stamp →

Activity

  1. added a commit that references this issue on Nov 19, 2026
    4ffe3b5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions