feat: Add PreTeleport and PostTeleport hook events

Add documentation and examples for new teleport hooks that allow users
to automate workflows when sessions transfer between web and CLI:

- PreTeleport: Runs before teleporting (stash work, sync state)
- PostTeleport: Runs after teleporting (pull changes, start dev servers)

This addresses the common workflow where users teleport from web to CLI
and need to run setup commands like `yarn dev:staging`.

Slack thread: https://anthropic.slack.com/archives/C096H3HP75G/p1765833639134099?thread_ts=1765833353.488839&cid=C096H3HP75G
This commit is contained in:
Claude
2025-12-15 21:25:55 +00:00
parent eb87245010
commit fee53699c3
4 changed files with 291 additions and 1 deletions

View File

@@ -0,0 +1,57 @@
#!/bin/bash
# Example PostTeleport hook for setting up environment after teleporting
# This script pulls changes, installs dependencies, and starts dev server
set -euo pipefail
# Navigate to project directory
cd "$CLAUDE_PROJECT_DIR" || exit 0
echo "Setting up environment after teleport..."
# Pull latest changes if in a git repository
if [ -d ".git" ]; then
current_branch=$(git branch --show-current)
echo "🔄 Pulling latest changes for branch: $current_branch"
git pull origin "$current_branch" 2>/dev/null || echo "Could not pull (may be offline or no upstream)"
# Check for stashed changes from pre-teleport
if git stash list | grep -q "pre-teleport-stash"; then
echo "📦 Restoring stashed changes from pre-teleport..."
git stash pop || echo "Could not restore stash (may have conflicts)"
fi
fi
# Install dependencies based on project type
if [ -f "package.json" ]; then
echo "📦 Installing Node.js dependencies..."
npm install --silent 2>/dev/null || npm install
fi
if [ -f "requirements.txt" ]; then
echo "🐍 Installing Python dependencies..."
pip install -r requirements.txt --quiet 2>/dev/null || pip install -r requirements.txt
fi
if [ -f "Cargo.toml" ]; then
echo "🦀 Building Rust project..."
cargo build 2>/dev/null || true
fi
# Start development server if available
if [ -f "package.json" ]; then
# Check for common dev server scripts
if grep -q '"dev:staging"' package.json; then
echo "🚀 Starting staging dev server..."
npm run dev:staging &
elif grep -q '"dev"' package.json; then
echo "🚀 Starting dev server..."
npm run dev &
elif grep -q '"start"' package.json; then
echo "🚀 Starting server..."
npm start &
fi
fi
echo "✅ Teleport complete! Environment ready."
exit 0

View File

@@ -0,0 +1,33 @@
#!/bin/bash
# Example PreTeleport hook for preparing environment before teleporting
# This script stashes uncommitted changes and saves state for restoration
set -euo pipefail
# Navigate to project directory
cd "$CLAUDE_PROJECT_DIR" || exit 0
echo "Preparing for teleport..."
# Check if we're in a git repository
if [ ! -d ".git" ]; then
echo "Not a git repository, skipping pre-teleport preparation"
exit 0
fi
# Stash uncommitted changes before teleporting
if [ -n "$(git status --porcelain)" ]; then
echo "📦 Stashing uncommitted changes before teleport..."
git stash push -m "pre-teleport-stash-$(date +%s)"
echo "Changes stashed successfully"
else
echo "No uncommitted changes to stash"
fi
# Save current branch state for post-teleport restoration
mkdir -p .claude
echo "$(git branch --show-current)" > .claude/.teleport-state
echo "Current branch saved: $(cat .claude/.teleport-state)"
echo "Pre-teleport preparation complete"
exit 0