Skip to content

Instantly share code, notes, and snippets.

@Crunchyman-ralph
Created April 12, 2026 20:39
Show Gist options
  • Select an option

  • Save Crunchyman-ralph/568c465a0ea633ce1a2c85ea453b93b8 to your computer and use it in GitHub Desktop.

Select an option

Save Crunchyman-ralph/568c465a0ea633ce1a2c85ea453b93b8 to your computer and use it in GitHub Desktop.
Auto Resume Claude Code Sessions (Multi-Pane: Superset, iTerm, tmux)

Auto Resume Claude Code Sessions (Multi-Pane)

Resume Claude Code sessions automatically, with per-pane isolation for Superset, iTerm, and tmux.

1. SessionEnd Hook (~/.claude/settings.json)

Add this to your hooks object:

"SessionEnd": [
  {
    "matcher": "",
    "hooks": [
      {
        "type": "command",
        "command": "jq -r '\"mkdir -p \" + .cwd + \"/.claude_sessions && echo \\\"claude --dangerously-skip-permissions --resume \" + .session_id + \"\\\" > \" + .cwd + \"/.claude_sessions/${SUPERSET_PANE_ID:-${ITERM_SESSION_ID:-${TMUX_PANE:-default}}}\"' | sh"
      }
    ]
  }
]

2. Shell Function (add to ~/.zshrc or ~/.bashrc)

c() {
  local key="${SUPERSET_PANE_ID:-${ITERM_SESSION_ID:-${TMUX_PANE:-default}}}"
  local session_file=".claude_sessions/$key"
  if [ -f "$session_file" ]; then
    local cmd
    cmd=$(cat "$session_file")
    rm -f "$session_file"
    rmdir .claude_sessions 2>/dev/null
    eval "$cmd"
  else
    claude "$@"
  fi
}

3. Gitignore

echo '.claude_sessions/' >> ~/.gitignore_global

How It Works

  • Exit Claude Code -> the hook saves the session ID to .claude_sessions/<pane-id>
  • Run c from the same pane -> resumes right where you left off
  • Run c again (or with arguments) -> starts a fresh session (file was consumed)
  • Multiple panes in the same directory = no conflicts

Pane ID Fallback Chain

Terminal Environment Variable
Superset SUPERSET_PANE_ID
iTerm ITERM_SESSION_ID
tmux TMUX_PANE
Other default

Requirements

  • jq must be installed
  • Claude Code with hooks support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment