Skip to content

Session ID not updated correctly - Second and subsequent prompts fail in conversation #92

@tethiro

Description

@tethiro

Bug Description

Claudia fails to continue conversations after the first prompt because it does not properly handle Claude CLI's session ID management. This affects all platforms (Windows, macOS, Linux).

Root Cause

Claude CLI returns a new session ID with every response, but Claudia only stores the initial session ID and never updates it. This causes all subsequent prompts to fail with "No conversation found with session ID" error.

Critical Issue: Sequential Mode Conversation Continuity

When using --output-format json (the correct format), Claude CLI operates in a sequential request-response mode. Without proper session ID management, it's impossible to maintain conversation context between prompts. Each Claude CLI invocation is stateless - the ONLY way to maintain conversation continuity is through the session ID returned in each response. This makes proper session ID handling absolutely critical for any multi-turn conversation.

Steps to Reproduce

  1. Start a new Claude Code session in Claudia
  2. Send first prompt (e.g., "Hello") - works correctly
  3. Send second prompt (e.g., "What did I just say?") - fails with session not found error

Expected Behavior

Claudia should:

  1. Extract the new session ID from each Claude CLI response
  2. Use the latest session ID for the next --resume command
  3. Successfully continue the conversation

Actual Behavior

  • Claudia stores only the first session ID in claudeSessionId state
  • Uses the outdated session ID for all subsequent prompts
  • Claude CLI returns "No conversation found" error

Technical Details

Problem in ClaudeCodeSession.tsx:

// Line ~314: Only updates if claudeSessionId is null
if (!claudeSessionId) {
  setClaudeSessionId(message.session_id);
}

// Line ~384: Uses outdated session ID
await api.resumeClaudeCode(projectPath, effectiveSession.id, prompt, model);

Claude CLI behavior with --output-format json:

# First prompt
$ claude -p "Hello" --output-format json
# Returns JSON with: {"session_id": "abc-123", ...}

# Second prompt MUST use the NEW session ID from previous response
$ claude --resume abc-123 -p "Next question" --output-format json
# Returns JSON with: {"session_id": "def-456", ...}  # NEW session ID!

# Third prompt MUST use def-456, not abc-123
$ claude --resume def-456 -p "Another question" --output-format json
# Returns JSON with: {"session_id": "ghi-789", ...}  # Again, NEW session ID!

Additional Issues Found

  1. Incorrect output format option:

    • Currently uses: --output-format stream-json
    • Should be: --output-format json
    • Note: stream-json is not a valid option for Claude CLI
  2. Windows/WSL issues: No proper WSL support for Windows users (related to Windows Support for Claudia - Community Fix Available 4.2 FINAL #78)

Why This Is Critical

The current implementation fundamentally breaks the core functionality of Claudia. Since Claude CLI in JSON mode operates as discrete invocations, the session ID is the only mechanism for maintaining conversation state. Without updating the session ID after each response, Claudia cannot:

  • Continue conversations beyond the first prompt
  • Maintain context between messages
  • Provide the interactive experience it promises

This is not a minor bug - it's a fundamental flaw that makes the application unusable for its primary purpose.

Proposed Solution

  1. Always update claudeSessionId with the latest value:
// Remove the condition
setClaudeSessionId(message.session_id);
  1. Use the latest session ID for resume:
if (effectiveSession && !isFirstPrompt && claudeSessionId) {
  await api.resumeClaudeCode(projectPath, claudeSessionId, prompt, model);
}
  1. Fix output format option in all places from stream-json to json

Environment

  • Claudia version: Latest from main branch
  • Claude CLI version: 0.6.8
  • OS: Tested on Windows 11 (WSL), but affects all platforms
  • Node version: v22.16.0

Related Issues

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