Skip to content

fix(cli): prevent session flags from leaking through on retry#644

Open
kmizzi wants to merge 1 commit intoslopus:mainfrom
kmizzi:fix/continue-flag-leaking
Open

fix(cli): prevent session flags from leaking through on retry#644
kmizzi wants to merge 1 commit intoslopus:mainfrom
kmizzi:fix/continue-flag-leaking

Conversation

@kmizzi
Copy link
Contributor

@kmizzi kmizzi commented Feb 16, 2026

Summary

  • Bug: happy --continue errors with "--session-id can only be used with --continue or --resume if --fork-session is also specified" while claude --continue works fine
  • Root cause: Session flags (--continue, -c) were only extracted from claudeArgs when startFrom was null. On retry after error (where the SessionStart hook had already set session.sessionId), extraction was skipped — causing --continue to leak through alongside --resume <id>, producing conflicting flags
  • Fix: Extract all session flags unconditionally from claudeArgs, then conditionally use the extracted values to determine startFrom. Also consume one-time flags on error in the launcher retry loop, and enhance consumeOneTimeFlags() to handle -c, -r shorthands and --session-id

Changes

claudeLocal.ts

  • Move all session flag extraction (--session-id, --resume <id>, --continue) to happen unconditionally before the startFrom check
  • Extracted values are only used to set startFrom when it's not already set
  • Bare --resume/-r (without value) still passes through to Claude for the interactive session picker
  • Fix hasContinueFlag reference → continueFlag.found

claudeLocalLauncher.ts

  • Call session.consumeOneTimeFlags() in the catch block of the retry loop, preventing flags from leaking on subsequent retries

session.ts

  • Enhance consumeOneTimeFlags() to handle -c (alias for --continue), -r (alias for --resume), and --session-id flag
  • Simplify value detection (any non-flag next arg, not just UUID pattern)

claudeLocal.test.ts

  • Add 2 regression tests for the retry scenario where sessionId is already set from a previous hook notification

Test plan

  • All 12 unit tests pass (10 existing + 2 new regression tests)
  • Manual test: happy --continue resumes last session without error
  • Manual test: happy --resume <id> resumes specific session
  • Manual test: happy -c works as alias for --continue
  • Manual test: happy -r opens Claude's session picker

🤖 Generated with Claude Code
via Happy

When `happy --continue` was used, the `--continue` flag was only
extracted from claudeArgs when `startFrom` was null. On retry after
an error (where the SessionStart hook had already set session.sessionId),
the extraction was skipped, causing `--continue` to leak through
alongside `--resume <id>` — triggering Claude's error:
"--session-id can only be used with --continue or --resume if
--fork-session is also specified."

Fix: Extract all session flags unconditionally, then conditionally
use the extracted values. Also consume one-time flags on error in
the launcher retry loop, and enhance consumeOneTimeFlags() to handle
-c, -r shorthands and --session-id.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
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.

1 participant