[BUG] Session files deleted after --print exit, making --resume impossible
Resolved 💬 3 comments Opened Mar 29, 2026 by oharu121 Closed May 3, 2026
Description
Session files created by --print mode are deleted when the process exits, making --resume impossible for programmatic multi-turn workflows.
When using claude --print --output-format stream-json, the response includes a session_id. However, after the CLI process exits, the session file in ~/.claude/sessions/ is cleaned up. A subsequent claude --resume <session_id> --print fails with "No conversation found with session ID".
Reproduction
# 1. Run a --print command and extract the session ID
SID=$(echo "What is 2+2?" | claude --print --output-format stream-json 2>&1 \
| grep -o '"session_id":"[^"]*"' | tail -1 | cut -d'"' -f4)
echo "Session ID: $SID"
# 2. Verify session file is gone after exit
ls -la ~/.claude/sessions/
# Result: empty directory — session file was deleted on process exit
# 3. Attempt to resume
echo "Now what is 3+3?" | claude --resume "$SID" --print --output-format stream-json 2>&1
# Result: {"type":"result","subtype":"error_during_execution","is_error":true,...,"errors":["No conversation found with session ID: ..."]}
Expected behavior
Either:
- Session files persist after
--printexits (so--resumeworks), or --printmode returns a clear error/warning when--resumeis passed, indicating sessions are not persisted in this mode
Actual behavior
--printoutputs asession_idin the response (suggesting it can be resumed)- Session file is silently deleted on process exit
--resumefails with a generic "No conversation found" error
Environment
- Claude Code version: 2.1.86
- OS: Linux (Docker container,
python:3.14-slim) - Auth: OAuth token (
CLAUDE_CODE_OAUTH_TOKEN)
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗