Skip to content

Conversation

@ahundt
Copy link

@ahundt ahundt commented Dec 16, 2025

Problem

Users can't use happy --continue since Claude Code 2.0.64 - it crashes with:

Error: --session-id cannot be used with --continue or --resume

This blocks anyone trying to continue their last session, which is a core workflow.

Related: Issue #87 (--resume --continue not working since 0.12.0)

Root Cause

Claude Code 2.0.64 introduced mutual exclusivity between --session-id and --continue/--resume flags. Happy was adding --session-id for session tracking while users passed --continue, triggering the conflict.

Solution

Intercept --continue and convert it to --resume <last-session-id>:

  1. claudeFindLastSession() - Scans ~/.claude/projects/ for the most recent valid session
  2. claudeLocal.ts - Detects --continue, finds last session, replaces with --resume <id>
  3. Fallback - If no sessions exist, starts fresh (no --resume, no conflict)

Changes

File Change
src/claude/utils/claudeFindLastSession.ts New utility to find most recent UUID session
src/claude/claudeLocal.ts Intercept --continue, convert to --resume; handle --resume without ID
src/claude/claudeLocal.test.ts Unit tests for flag conversion logic

Bug Fix: Preserve Claude's Native --resume Picker

Commit: e56fb57

Happy was breaking Claude's native --resume picker by always adding --session-id. Now properly delegates to Claude's existing interactive session picker when --resume is used without an ID.

Changes:

  • extractFlag() - Returns {found: false} when value required but missing
  • Spawn args check - Detects --resume in claudeArgs before adding --session-id
  • Preserves Claude's existing picker behavior instead of interfering with it

Testing

# Verify --continue works without crash
happy --continue

# Verify new sessions still work
happy

# Run unit tests
bun run test src/claude/claudeLocal.test.ts

Why Merge This

  • Fixes broken workflow - Users expect --continue to work
  • Backward compatible - No changes to CLI interface
  • Well tested - Comprehensive unit tests included
  • Low risk - Only affects flag handling, not core logic

Claude Code 2.0.64+ rejects --session-id when used with --continue, causing:
"Error: --session-id cannot be used with --continue or --resume"

Solution: Convert --continue to --resume by finding the last session ID.

Changes:
- Add claudeFindLastSession() utility to find most recent valid session
- claudeLocal.ts: Intercept --continue flag and convert to --resume with last session
- Handle all session-related flags (--continue, --resume, --session-id) transparently
- Only UUID-format sessions are returned for --resume compatibility
- Add comprehensive unit tests for the --continue conversion logic

Fixes critical bug where "happy --continue" failed with flag conflict error.
Reverts:
- README.md: restore claude-code-router link (line 39)
- package.json: restore version 0.12.0 (was 0.12.0-0)
- src/index.ts: restore --claude-env parsing (lines 271-284)

Removes:
- src/api/apiSession.test.ts: belongs in server-unreachable PR, not here

Fixes:
- src/claude/claudeLocal.test.ts:5-8: apply vi.hoisted pattern for vitest compatibility

The vi.hoisted() wrapper ensures mock variables are available during
vitest's module hoisting phase, fixing "Cannot access 'mockFn' before
initialization" errors.

Note: One test (should remove --continue from claudeArgs after conversion)
has a pre-existing logic issue in the implementation - the test expects
the claudeArgs array to be mutated, but the implementation uses array
filtering which creates a new array.
Previous behavior: Test checked if original claudeArgs array was mutated
to remove --continue, but filter() creates a new array.

What changed: Check mockSpawn.mock.calls[0][1] (actual spawn arguments)
instead of the original claudeArgs array.

Why: The implementation uses filter() which returns a new array rather
than mutating the original. The test should verify what actually gets
passed to spawn, not internal implementation details.
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