/clear should expose new conversation ID (e.g. via hook or env var)

Status Fixed / completed
Maintainer reply None cached
Activity 3 comments · opened Jun 28, 2026 · 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:

  1. On first launch, generate a UUID and start Claude with --session-id <uuid>, save it to a file (e.g. .claude-session-id)
  2. On reattach, if the tmux session already exists — just attach
  3. 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-id still 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 ConversationClear hook event that exposes the new conversation ID (e.g. as $CLAUDE_SESSION_ID env var), or
  • Write the new conversation ID to a known location after /clear so external tooling can read it

This would allow users to keep their session tracking files in sync with Claude Code's internal state.

View original on GitHub ↗

3 Comments

github-actions[bot] · 3 months ago

Found 1 possible duplicate issue:

  1. https://github.com/anthropics/claude-code/issues/70606

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

lexuzieel · 3 months ago

Closing as duplicate of #70606.

github-actions[bot] · 1 month ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.