/clear should expose new conversation ID (e.g. via hook or env var)
Resolved 💬 2 comments Opened Jun 28, 2026 by lexuzieel Closed Jun 28, 2026
Problem
When using Claude Code inside tmux with a custom session-resume workflow, /clear starts a new conversation internally — but the new conversation ID is not exposed anywhere. This makes it impossible to update external session tracking after a clear.
Context: tmux session resume pattern
A common pattern for persistent Claude Code sessions in tmux looks like this:
- On first launch, generate a UUID and start Claude with
--session-id <uuid>, save it to a file (e.g..claude-session-id) - On reattach, if the tmux session already exists — just attach
- If the tmux session is gone (reboot, crash) — read the saved ID and resume with
claude --resume <id>
This gives you persistent, resumable Claude sessions across terminal reconnects.
if [[ ! -f "$SESSION_ID_FILE" ]]; then
uuidgen > "$SESSION_ID_FILE"
CLAUDE_CMD="claude --session-id '$(cat "$SESSION_ID_FILE")'"
else
CLAUDE_CMD="claude --resume '$(cat "$SESSION_ID_FILE")'"
fi
The gap: /clear breaks the chain
When the user runs /clear inside Claude Code:
- A new conversation is started internally
- But the new conversation ID is not exposed anywhere (no env var, no hook event)
.claude-session-idstill contains the old ID- Next time the tmux session is gone and the user reconnects,
claude --resume <old-id>restores the pre-clear conversation
Why a hook workaround doesn't work
A UserPromptSubmit hook on /clear can detect the command, but:
- It can delete the file — so next launch gets a fresh session (acceptable)
- It cannot write the new ID — because the new conversation ID isn't available at hook time
Suggested fix
Either:
- Add a
ConversationClearhook event that exposes the new conversation ID (e.g. as$CLAUDE_SESSION_IDenv var), or - Write the new conversation ID to a known location after
/clearso external tooling can read it
This would allow users to keep their session tracking files in sync with Claude Code's internal state.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗