Automatically fork your current Claude Code session into a new Ghostty split pane with a single command.
Two Raycast commands:
- Fork Claude Right - Split horizontally (right)
- Fork Claude Down - Split vertically (down)
Each command will:
- Split the Ghostty terminal in the chosen direction
- Automatically fork the exact Claude session running in the current pane
- Both panes now have independent sessions that can diverge
- macOS
- Ghostty terminal
- Raycast - macOS launcher
- jq - JSON parser
- Claude Code CLI
brew install jqCreate ~/.claude/hooks/capture-session.sh:
#!/bin/bash
session_data=$(cat)
session_id=$(echo "$session_data" | jq -r '.session_id')
cwd=$(echo "$session_data" | jq -r '.cwd')
cwd_hash=$(echo -n "$cwd" | md5)
echo "$session_id" > "/tmp/claude_session_${cwd_hash}"
exit 0Make it executable:
chmod +x ~/.claude/hooks/capture-session.shAdd to ~/.claude/settings.json:
{
"hooks": {
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "~/.claude/hooks/capture-session.sh"
}
]
}
]
}
}Create two scripts in ~/.config/raycast/scripts/:
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Fork Claude Right
# @raycast.mode silent
# Optional parameters:
# @raycast.icon π΄
# @raycast.packageName Claude Code
# @raycast.needsConfirmation false
# Documentation:
# @raycast.description Split Ghostty and fork current Claude session
# @raycast.author hamadayouta
# Prevent multiple executions
LOCK_FILE="/tmp/fork-claude-session.lock"
if [ -f "$LOCK_FILE" ]; then
exit 0
fi
touch "$LOCK_FILE"
trap "rm -f $LOCK_FILE" EXIT
# Get session ID if Claude is running
session_id=""
if pgrep -x claude > /dev/null; then
cwd=$(lsof -p $(pgrep -n claude) 2>/dev/null | grep cwd | awk '{print $NF}')
if [ -n "$cwd" ]; then
cwd_hash=$(echo -n "$cwd" | md5)
session_file="/tmp/claude_session_${cwd_hash}"
if [ -f "$session_file" ]; then
session_id=$(cat "$session_file")
fi
fi
fi
# Build the fork command
if [ -n "$session_id" ]; then
fork_cmd="claude --resume ${session_id} --fork-session"
else
fork_cmd="claude --continue --fork-session"
fi
# Run everything in one AppleScript
osascript <<EOF
tell application "Ghostty" to activate
delay 0.3
tell application "System Events"
tell process "Ghostty"
click menu item "Split Right" of menu "File" of menu bar 1
end tell
delay 0.5
-- Type the fork command
keystroke "${fork_cmd}"
delay 0.1
key code 36 -- Return key
end tell
EOF
echo "Done"Same as above, but change:
# @raycast.title Fork Claude Down# @raycast.description Split Ghostty down and fork current Claude sessionclick menu item "Split Down" of menu "File" of menu bar 1
Make both executable:
chmod +x ~/.config/raycast/scripts/fork-claude-right.sh
chmod +x ~/.config/raycast/scripts/fork-claude-down.sh- Open Raycast (
Cmd+Space) - Press
Cmd+,to open Preferences - Go to Extensions tab
- Click + button at bottom left
- Select "Add Script Directory"
- Navigate to
~/.config/raycast/scriptsand add it - Both commands will now appear: "Fork Claude Right" and "Fork Claude Down"
- In Raycast Preferences β Extensions
- Find each command and set hotkeys:
- Fork Claude Right:
Cmd+Shift+D - Fork Claude Down:
Cmd+Shift+Opt+D
- Fork Claude Right:
- Start Claude Code in Ghostty:
claude - Work on your session
- Fork your session:
Cmd+Shift+Dβ Split rightCmd+Shift+Opt+Dβ Split down
- Both panes now have independent session branches!
- When Claude starts, a SessionStart hook captures the session ID
- Session ID is stored in
/tmp/claude_session_<cwd_hash> - When you run a Raycast command:
- Ghostty is focused
- A split pane is created via File β Split Right/Down
- The stored session ID is read
- Runs
claude --resume <session_id> --fork-session
Fork not working?
- Check Raycast has Accessibility permissions (System Preferences β Privacy & Security β Accessibility)
- Verify Claude is running in the terminal
- Check
/tmp/claude_session_*files exist
Wrong session forked?
- Ensure you're forking from the pane where Claude is running
- The hook captures session per working directory
Split not happening?
- Make sure Ghostty is the active window
- Check Raycast has permission to control your Mac