claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Session ID Mismatch When Using --dangerously-skip-permissions

Open vrknetha opened this issue 3 months ago • 1 comments

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When restarting Claude Code with the --dangerously-skip-permissions flag, a new transcript file is created with a new UUID filename, but the old session ID continues to be written inside the transcript records. This causes the statusline to display incorrect session IDs and context usage percentages.

Symptoms:

  • Statusline shows old session ID (e.g., 5ca7cbb1...) even though actual work is in new session (e.g., bf310f55...)
  • Context percentage displays incorrect value from previous session (48.7% instead of actual 32.4%)
  • Makes it impossible to accurately monitor current context usage
  • Transcript records contain mismatched session IDs

What Should Happen?

When a new transcript file is created (e.g., bf310f55-ff31-4ecd-9a01-3b190b35a916.jsonl):

  • The sessionId field inside transcript records should match the filename: bf310f55-ff31-4ecd-9a01-3b190b35a916
  • The statusline should display the correct session ID
  • The context percentage should reflect the actual usage in the current session

Error Messages/Logs

No explicit error messages, but transcript analysis reveals the mismatch:

Steps to Reproduce

  1. Start a Claude Code session normally:

    claude
    
    • This creates session ***.jsonl
  2. Work in the session, send some messages to accumulate context (e.g., 48.7%)

  3. Exit Claude Code (Ctrl+C or /exit)

  4. Restart Claude Code with --continue --dangerously-skip-permissions flag:

    claude --continue --dangerously-skip-permissions
    
  5. Send a message in the new session (e.g., "continue with next")

  6. Check the statusline display - it will show the OLD session ID

  7. Verify the bug by examining the transcript files:

    # Find the newest transcript file
    ls -t ~/.claude/projects/*/bf*.jsonl | head -1
    
    # Check the sessionId inside
    grep -o '"sessionId":"[^"]*"' <transcript-file> | head -1
    

Result: The new transcript file contains records with the old session ID

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

N/A - Unknown when this started

Claude Code Version

2.0.2 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Warp

Additional Information

Root Cause Analysis:

When --dangerously-skip-permissions is used, Claude Code appears to:

  1. Generate a new UUID for the transcript filename
  2. But NOT update the internal session tracking to use the new UUID
  3. Continue writing the old session ID into new transcript records

This suggests the session ID is cached/stored separately from the transcript path and is not properly reinitialized when the flag is used.

Impact:

  • User Impact: Cannot accurately monitor context usage; confusing UX with wrong session IDs; makes /compact difficult to use effectively
  • Developer Impact: Statusline scripts receive mismatched data; session tracking and telemetry may be incorrect

Suggested Fix:

When --dangerously-skip-permissions flag is detected and a new transcript file is created:

  1. Extract the UUID from the new transcript filename
  2. Update the internal session ID to match
  3. Ensure all subsequent transcript records use the correct session ID
  4. Pass the correct session ID to statusline and other integrations

Note: This bug only manifests when using --dangerously-skip-permissions. Normal session creation/continuation works correctly.

vrknetha avatar Oct 01 '25 07:10 vrknetha