Skip to content

fix: extract_cli_args misses bare --resume and leaves --continue (claude)#29

Open
cannonpalms wants to merge 1 commit into
timvw:mainfrom
cannonpalms:fix/resume-cli-args-feedback-loop
Open

fix: extract_cli_args misses bare --resume and leaves --continue (claude)#29
cannonpalms wants to merge 1 commit into
timvw:mainfrom
cannonpalms:fix/resume-cli-args-feedback-loop

Conversation

@cannonpalms
Copy link
Copy Markdown

Summary

Two fixes in extract_cli_args for claude in scripts/save-assistant-sessions.sh:

  1. Bare --resume not stripped. The old regex s/--resume[= ] *[^ ]*// requires [= ] after --resume, so a bare --resume at end-of-args (produced by claude --resume interactive-picker invocations or the /resume slash command) survives extraction and corrupts subsequent restores. New regex makes the value group optional and forbids consuming a following flag as the value.
  2. --continue / -c not stripped. Once the plugin supplies --resume <session_id>, --continue is ambiguous baggage -- it conflicts in spirit and may fall back to "most recent in cwd" if --resume fails to resolve.

The combined bug produces a feedback loop: the restored claude's cmdline ends up with a stray UUID positional (claude treats it as the first user prompt of the resumed conversation), the next save captures that stray UUID into cli_args, and the corruption perpetuates across cold-starts.

Closes #28 -- see the issue for a full reproduction, root-cause walkthrough, and notes on remediation for users already in the stuck state.

Test plan

Verified each input below against the patched extract_cli_args (after the binary-name strip on line 380, so the inputs below represent the post-binary-strip arg string):

Input Output Note
--dangerously-skip-permissions --resume eaf5f4d6-bd5f-49a8-ba6d-fe69af2dd537 --dangerously-skip-permissions normal --resume <uuid>
--dangerously-skip-permissions --dangerously-skip-permissions --resume --dangerously-skip-permissions --dangerously-skip-permissions bare --resume at EOS (the bug)
--dangerously-skip-permissions --dangerously-skip-permissions eaf5f4d6-bd5f-49a8-ba6d-fe69af2dd537 --resume eaf5f4d6-bd5f-49a8-ba6d-fe69af2dd537 --dangerously-skip-permissions --dangerously-skip-permissions eaf5f4d6-bd5f-49a8-ba6d-fe69af2dd537 corrupted state -- the --resume <uuid> tail is stripped; the leading stray UUID still requires user remediation (see issue)
--resume --model claude-opus-4-7 --model claude-opus-4-7 greedy-consumption fix
--dangerously-skip-permissions --resume=eaf5f4d6-bd5f-49a8-ba6d-fe69af2dd537 --dangerously-skip-permissions equals form
--dangerously-skip-permissions --dangerously-skip-permissions --continue --dangerously-skip-permissions --dangerously-skip-permissions --continue stripped
--add-dir /a --add-dir /b --add-dir /a --add-dir /b legit repeated flag preserved

Scope

The opencode and codex branches of extract_cli_args (lines 404, 408) share the same regex pattern and likely have the analogous bare-flag and greedy-value bugs. Happy to add those fixes in a follow-up if you'd like -- I've kept this PR scoped to claude since that's what I verified end-to-end against a real claude process.

…ude)

The claude branch of extract_cli_args in scripts/save-assistant-sessions.sh
had two bugs that combined to corrupt cli_args across save/restore cycles:

1. The regex `s/--resume[= ] *[^ ]*//` required `[= ]` after --resume, so a
   bare `--resume` at end-of-args (produced by `claude --resume` interactive
   picker invocations or the `/resume` slash command) survived extraction.
   Subsequent restores built `command claude ... --resume --resume <uuid>`,
   after which claude's self-re-exec left a stray UUID positional in argv --
   which claude treats as the first user prompt for the resumed
   conversation. The stray UUID then perpetuated across saves.

   Fix: make the value group optional and require the first char of a
   space-separated value to be non-dash, so `--resume --foo` doesn't
   greedily consume `--foo` either.

2. `--continue` / `-c` was preserved. Once the plugin supplies
   `--resume <session_id>` the `--continue` flag is redundant and risks
   falling back to "most recent in cwd" if `--resume` fails to resolve.

   Fix: strip `--continue` / `-c` unconditionally.

Closes timvw#28.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cli_args extraction for claude misses bare --resume, corrupting subsequent restores

1 participant