Skip to content

Comments

fix: detect running Claude before restarting to prevent session ID conflicts#321

Open
aronchick wants to merge 1 commit intodlorenc:mainfrom
aronchick:work/calm-owl
Open

fix: detect running Claude before restarting to prevent session ID conflicts#321
aronchick wants to merge 1 commit intodlorenc:mainfrom
aronchick:work/calm-owl

Conversation

@aronchick
Copy link
Contributor

Summary

Fixes bug where multiclaude claude command fails with "Session ID already in use" error when Claude is already running in the agent context.

Problem

The command would attempt to restart Claude with --session-id or --resume flags without checking if a Claude process was already active using that session ID. This resulted in conflicts when the session ID was already in use by a running Claude instance.

Solution

  • Added process alive check for stored agent PID before attempting restart
  • Added double-check for any running process in the tmux pane (in case PID differs)
  • Provides clear, actionable error messages with steps to exit and restart
  • Users can choose to properly exit and restart, or attach to the existing session

Changes

  • Import syscall package for signal-based process detection
  • Check if stored agent.PID is still alive using signal 0
  • Query tmux pane PID to catch cases where a different process is running
  • Return helpful error messages with next steps instead of attempting conflicting restart

Test Plan

  • All existing tests pass (go test ./...)
  • Code compiles without errors
  • Manual testing would verify:
    • Running multiclaude claude when Claude is already active shows helpful error
    • Running multiclaude claude when Claude is not running starts it successfully
    • Error messages include both exit-and-restart and attach options

Related Files

  • internal/cli/cli.go:5047 - restartClaude function

🤖 Generated with Claude Code

…nflicts

The 'multiclaude claude' command was failing with "Session ID already in use"
error when Claude was already running in the agent context. This happened because
the command would attempt to restart Claude with --session-id or --resume flags
without checking if a Claude process was already active with that session ID.

Changes:
- Add process alive check for stored agent PID before restarting
- Add double-check for any running process in the tmux pane
- Provide helpful error messages with steps to exit and restart
- Import syscall package for signal-based process detection

The fix detects:
1. If the stored agent PID is still running
2. If a different process is running in the tmux pane

Users now get clear instructions on how to properly restart Claude or attach
to the existing session.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@buggtb
Copy link

buggtb commented Jan 29, 2026

Superseded by PR #326

PR #326 includes this fix plus additional lint fixes needed to pass CI. This PR is superseded and likely doesn't need to be merged separately.

🤖 Merge-queue agent

aronchick added a commit to aronchick/multiclaude that referenced this pull request Jan 29, 2026
Changed two error messages to start with lowercase to comply with
Go's error formatting conventions (staticcheck rule ST1005):

- "Claude is already running..." → "claude is already running..."
- "A process..." → "a process..."

These are multi-line user-facing error messages that remain helpful
while following Go's convention that error strings should not be
capitalized (since they may be wrapped in other error contexts).

Fixes lint failures in PR dlorenc#321

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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.

2 participants