spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic ยท github.com/anthropics

feat: Add PreTeleport and PostTeleport hook eventsBrowse files
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
Claude authored on Dec 15, 2025 parent eb87245 ยท commit fee53699c380
4 changed files+291 -1compared with eb87245
Mplugins/plugin-dev/skills/hook-development/SKILL.md
Aplugins/plugin-dev/skills/hook-development/examples/post-teleport.sh
Aplugins/plugin-dev/skills/hook-development/examples/pre-teleport.sh
Mplugins/plugin-dev/skills/hook-development/references/patterns.md
@@ -1,6 +1,6 @@
11 ---
22 name: Hook Development
3-description: This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.
3+description: This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification, PreTeleport, PostTeleport). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.
44 version: 0.1.0
55 ---
66
@@ -275,6 +275,108 @@
275275
276276 Execute when Claude sends notifications. Use to react to user notifications.
277277
278+### PreTeleport
279+
280+Execute before a session teleports (transfers from web to CLI or vice versa). Use to prepare the environment, sync state, or validate teleport conditions.
281+
282+**Example:**
283+```json
284+{
285+ "PreTeleport": [
286+ {
287+ "matcher": "*",
288+ "hooks": [
289+ {
290+ "type": "command",
291+ "command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/pre-teleport.sh"
292+ }
293+ ]
294+ }
295+ ]
296+}
297+```
298+
299+**Example script (pre-teleport.sh):**
300+```bash
301+#!/bin/bash
302+# Stash any uncommitted changes before teleporting
303+cd "$CLAUDE_PROJECT_DIR" || exit 0
304+
305+if [ -d ".git" ] && [ -n "$(git status --porcelain)" ]; then
306+ echo "๐Ÿ“ฆ Stashing uncommitted changes before teleport..."
307+ git stash push -m "pre-teleport-stash-$(date +%s)"
308+fi
309+```
310+
311+**Input fields:**
312+- `source`: The origin of the teleport ("web" or "cli")
313+- `destination`: Where the session is going ("web" or "cli")
314+- `branch`: The git branch being teleported (if applicable)
315+
316+**Use for:**
317+- Stashing uncommitted work before teleporting
318+- Syncing local state with remote
319+- Validating prerequisites before teleport
320+- Cleaning up temporary files
321+
322+### PostTeleport
323+
324+Execute after a session successfully teleports. Use to set up the environment in the new context, run dev servers, or restore state.
325+
326+**Example:**
327+```json
328+{
329+ "PostTeleport": [
330+ {
331+ "matcher": "*",
332+ "hooks": [
333+ {
334+ "type": "command",
335+ "command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/post-teleport.sh"
336+ }
337+ ]
338+ }
339+ ]
340+}
341+```
342+
343+**Example script (post-teleport.sh):**
344+```bash
345+#!/bin/bash
346+cd "$CLAUDE_PROJECT_DIR" || exit 0
347+
348+# Pull latest changes from the teleported branch
349+if [ -d ".git" ]; then
350+ echo "๐Ÿ”„ Pulling latest changes..."
351+ git pull origin "$(git branch --show-current)" 2>/dev/null || true
352+fi
353+
354+# Install dependencies if needed
355+if [ -f "package.json" ]; then
356+ echo "๐Ÿ“ฆ Installing dependencies..."
357+ npm install --silent
358+fi
359+
360+# Start dev server (example for common workflow)
361+if [ -f "package.json" ] && grep -q '"dev"' package.json; then
362+ echo "๐Ÿš€ Starting dev server..."
363+ npm run dev &
364+fi
365+```
366+
367+**Input fields:**
368+- `source`: Where the session came from ("web" or "cli")
369+- `destination`: The current context ("web" or "cli")
370+- `branch`: The git branch that was teleported
371+- `teleport_success`: Boolean indicating if teleport completed successfully
372+
373+**Use for:**
374+- Pulling latest changes after teleporting
375+- Installing/updating dependencies
376+- Starting development servers
377+- Restoring stashed work
378+- Running project-specific setup scripts
379+
278380 ## Hook Output Format
279381
280382 ### Standard Output (All Hooks)
@@ -642,6 +744,8 @@
642744 | SessionEnd | Session ends | Cleanup, logging |
643745 | PreCompact | Before compact | Preserve context |
644746 | Notification | User notified | Logging, reactions |
747+| PreTeleport | Before teleport | Stash work, sync state |
748+| PostTeleport | After teleport | Setup env, start servers |
645749
646750 ### Best Practices
647751
@@ -679,6 +783,8 @@
679783 - **`validate-write.sh`** - File write validation example
680784 - **`validate-bash.sh`** - Bash command validation example
681785 - **`load-context.sh`** - SessionStart context loading example
786+- **`pre-teleport.sh`** - PreTeleport state preservation example
787+- **`post-teleport.sh`** - PostTeleport environment setup example
682788
683789 ### Utility Scripts
684790
@@ -1,0 +1,57 @@
1+#!/bin/bash
2+# Example PostTeleport hook for setting up environment after teleporting
3+# This script pulls changes, installs dependencies, and starts dev server
4+
5+set -euo pipefail
6+
7+# Navigate to project directory
8+cd "$CLAUDE_PROJECT_DIR" || exit 0
9+
10+echo "Setting up environment after teleport..."
11+
12+# Pull latest changes if in a git repository
13+if [ -d ".git" ]; then
14+ current_branch=$(git branch --show-current)
15+ echo "๐Ÿ”„ Pulling latest changes for branch: $current_branch"
16+ git pull origin "$current_branch" 2>/dev/null || echo "Could not pull (may be offline or no upstream)"
17+
18+ # Check for stashed changes from pre-teleport
19+ if git stash list | grep -q "pre-teleport-stash"; then
20+ echo "๐Ÿ“ฆ Restoring stashed changes from pre-teleport..."
21+ git stash pop || echo "Could not restore stash (may have conflicts)"
22+ fi
23+fi
24+
25+# Install dependencies based on project type
26+if [ -f "package.json" ]; then
27+ echo "๐Ÿ“ฆ Installing Node.js dependencies..."
28+ npm install --silent 2>/dev/null || npm install
29+fi
30+
31+if [ -f "requirements.txt" ]; then
32+ echo "๐Ÿ Installing Python dependencies..."
33+ pip install -r requirements.txt --quiet 2>/dev/null || pip install -r requirements.txt
34+fi
35+
36+if [ -f "Cargo.toml" ]; then
37+ echo "๐Ÿฆ€ Building Rust project..."
38+ cargo build 2>/dev/null || true
39+fi
40+
41+# Start development server if available
42+if [ -f "package.json" ]; then
43+ # Check for common dev server scripts
44+ if grep -q '"dev:staging"' package.json; then
45+ echo "๐Ÿš€ Starting staging dev server..."
46+ npm run dev:staging &
47+ elif grep -q '"dev"' package.json; then
48+ echo "๐Ÿš€ Starting dev server..."
49+ npm run dev &
50+ elif grep -q '"start"' package.json; then
51+ echo "๐Ÿš€ Starting server..."
52+ npm start &
53+ fi
54+fi
55+
56+echo "โœ… Teleport complete! Environment ready."
57+exit 0
@@ -1,0 +1,33 @@
1+#!/bin/bash
2+# Example PreTeleport hook for preparing environment before teleporting
3+# This script stashes uncommitted changes and saves state for restoration
4+
5+set -euo pipefail
6+
7+# Navigate to project directory
8+cd "$CLAUDE_PROJECT_DIR" || exit 0
9+
10+echo "Preparing for teleport..."
11+
12+# Check if we're in a git repository
13+if [ ! -d ".git" ]; then
14+ echo "Not a git repository, skipping pre-teleport preparation"
15+ exit 0
16+fi
17+
18+# Stash uncommitted changes before teleporting
19+if [ -n "$(git status --porcelain)" ]; then
20+ echo "๐Ÿ“ฆ Stashing uncommitted changes before teleport..."
21+ git stash push -m "pre-teleport-stash-$(date +%s)"
22+ echo "Changes stashed successfully"
23+else
24+ echo "No uncommitted changes to stash"
25+fi
26+
27+# Save current branch state for post-teleport restoration
28+mkdir -p .claude
29+echo "$(git branch --show-current)" > .claude/.teleport-state
30+echo "Current branch saved: $(cat .claude/.teleport-state)"
31+
32+echo "Pre-teleport preparation complete"
33+exit 0
@@ -344,3 +344,97 @@
344344 - Per-project settings
345345 - Team-specific rules
346346 - Dynamic validation criteria
347+
348+## Pattern 11: Teleport Workflow Automation
349+
350+Automate setup when teleporting sessions between web and CLI:
351+
352+**Pre-teleport hook (prepare for transfer):**
353+```json
354+{
355+ "PreTeleport": [
356+ {
357+ "matcher": "*",
358+ "hooks": [
359+ {
360+ "type": "command",
361+ "command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/pre-teleport.sh"
362+ }
363+ ]
364+ }
365+ ]
366+}
367+```
368+
369+**pre-teleport.sh:**
370+```bash
371+#!/bin/bash
372+cd "$CLAUDE_PROJECT_DIR" || exit 0
373+
374+# Stash uncommitted changes before teleporting
375+if [ -d ".git" ] && [ -n "$(git status --porcelain)" ]; then
376+ echo "๐Ÿ“ฆ Stashing uncommitted changes..."
377+ git stash push -m "pre-teleport-$(date +%s)"
378+fi
379+
380+# Save current state for restoration
381+echo "$(git branch --show-current)" > .claude/.teleport-state
382+```
383+
384+**Post-teleport hook (set up after transfer):**
385+```json
386+{
387+ "PostTeleport": [
388+ {
389+ "matcher": "*",
390+ "hooks": [
391+ {
392+ "type": "command",
393+ "command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/post-teleport.sh"
394+ }
395+ ]
396+ }
397+ ]
398+}
399+```
400+
401+**post-teleport.sh:**
402+```bash
403+#!/bin/bash
404+cd "$CLAUDE_PROJECT_DIR" || exit 0
405+
406+# Pull latest changes
407+if [ -d ".git" ]; then
408+ echo "๐Ÿ”„ Pulling latest changes..."
409+ git pull origin "$(git branch --show-current)" 2>/dev/null || true
410+
411+ # Restore stashed changes if any
412+ if git stash list | grep -q "pre-teleport"; then
413+ echo "๐Ÿ“ฆ Restoring stashed changes..."
414+ git stash pop
415+ fi
416+fi
417+
418+# Install dependencies
419+if [ -f "package.json" ]; then
420+ echo "๐Ÿ“ฆ Installing dependencies..."
421+ npm install --silent
422+fi
423+
424+# Start dev server
425+if [ -f "package.json" ] && grep -q '"dev:staging"' package.json; then
426+ echo "๐Ÿš€ Starting staging dev server..."
427+ npm run dev:staging &
428+elif [ -f "package.json" ] && grep -q '"dev"' package.json; then
429+ echo "๐Ÿš€ Starting dev server..."
430+ npm run dev &
431+fi
432+
433+echo "โœ… Teleport complete! Environment ready."
434+```
435+
436+**Use for:**
437+- Seamless web-to-CLI workflow transitions
438+- Automatic dev server startup after teleporting
439+- Preserving uncommitted work across teleports
440+- Environment setup automation