[BUG] Session ID Mismatch When Using --dangerously-skip-permissions
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
sessionIdfield 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
-
Start a Claude Code session normally:
claude- This creates session
***.jsonl
- This creates session
-
Work in the session, send some messages to accumulate context (e.g., 48.7%)
-
Exit Claude Code (Ctrl+C or
/exit) -
Restart Claude Code with
--continue --dangerously-skip-permissionsflag:claude --continue --dangerously-skip-permissions -
Send a message in the new session (e.g., "continue with next")
-
Check the statusline display - it will show the OLD session ID
-
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:
- Generate a new UUID for the transcript filename
- But NOT update the internal session tracking to use the new UUID
- 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
/compactdifficult 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:
- Extract the UUID from the new transcript filename
- Update the internal session ID to match
- Ensure all subsequent transcript records use the correct session ID
- 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.