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

refactor: Use SessionStart teleport matcher instead of separate hooksBrowse files
Change approach from separate PreTeleport/PostTeleport hook events to
using SessionStart with a `teleport` matcher. This is cleaner since
teleporting to CLI starts a new session anyway.

SessionStart matchers:
- `*` - All session starts
- `teleport` - Only teleported sessions (web → CLI)
- `fresh` - Only fresh sessions (not teleported)

Removes pre-teleport.sh example since there's no pre-teleport hook.
Claude authored on Dec 15, 2025 parent fee5369 · commit 93effadd3127
4 changed files+48 -173compared with fee5369
Mplugins/plugin-dev/skills/hook-development/SKILL.md
Mplugins/plugin-dev/skills/hook-development/examples/post-teleport.sh
Dplugins/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, PreTeleport, PostTeleport). 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", "teleport hook", 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.
44 version: 0.1.0
55 ---
66
@@ -239,7 +239,12 @@
239239
240240 Execute when Claude Code session begins. Use to load context and set environment.
241241
242-**Example:**
242+**Matchers for SessionStart:**
243+- `*` - All session starts
244+- `teleport` - Only when session started via teleport (web → CLI)
245+- `fresh` - Only for fresh sessions (not teleported)
246+
247+**Example (general context loading):**
243248 ```json
244249 {
245250 "SessionStart": [
@@ -256,82 +261,15 @@
256261 }
257262 ```
258263
259-**Special capability:** Persist environment variables using `$CLAUDE_ENV_FILE`:
260-```bash
261-echo "export PROJECT_TYPE=nodejs" >> "$CLAUDE_ENV_FILE"
262-```
263-
264-See `examples/load-context.sh` for complete example.
265-
266-### SessionEnd
267-
268-Execute when session ends. Use for cleanup, logging, and state preservation.
269-
270-### PreCompact
271-
272-Execute before context compaction. Use to add critical information to preserve.
273-
274-### Notification
275-
276-Execute when Claude sends notifications. Use to react to user notifications.
277-
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:**
264+**Example (teleport-specific setup):**
283265 ```json
284266 {
285- "PreTeleport": [
267+ "SessionStart": [
286268 {
287- "matcher": "*",
269+ "matcher": "teleport",
288270 "hooks": [
289271 {
290272 "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",
335273 "command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/post-teleport.sh"
336274 }
337275 ]
@@ -364,19 +302,30 @@
364302 fi
365303 ```
366304
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
305+**Special capability:** Persist environment variables using `$CLAUDE_ENV_FILE`:
306+```bash
307+echo "export PROJECT_TYPE=nodejs" >> "$CLAUDE_ENV_FILE"
308+```
372309
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
310+**Teleport-specific input fields:**
311+- `is_teleport`: Boolean indicating if this session started via teleport
312+- `source`: Where the session came from ("web" or "cli") - only present for teleports
313+- `branch`: The git branch that was teleported - only present for teleports
379314
315+See `examples/load-context.sh` and `examples/post-teleport.sh` for complete examples.
316+
317+### SessionEnd
318+
319+Execute when session ends. Use for cleanup, logging, and state preservation.
320+
321+### PreCompact
322+
323+Execute before context compaction. Use to add critical information to preserve.
324+
325+### Notification
326+
327+Execute when Claude sends notifications. Use to react to user notifications.
328+
380329 ## Hook Output Format
381330
382331 ### Standard Output (All Hooks)
@@ -740,12 +689,10 @@
740689 | UserPromptSubmit | User input | Context, validation |
741690 | Stop | Agent stopping | Completeness check |
742691 | SubagentStop | Subagent done | Task validation |
743-| SessionStart | Session begins | Context loading |
692+| SessionStart | Session begins | Context loading (use `teleport` matcher for teleport-specific setup) |
744693 | SessionEnd | Session ends | Cleanup, logging |
745694 | PreCompact | Before compact | Preserve context |
746695 | Notification | User notified | Logging, reactions |
747-| PreTeleport | Before teleport | Stash work, sync state |
748-| PostTeleport | After teleport | Setup env, start servers |
749696
750697 ### Best Practices
751698
@@ -783,8 +730,7 @@
783730 - **`validate-write.sh`** - File write validation example
784731 - **`validate-bash.sh`** - Bash command validation example
785732 - **`load-context.sh`** - SessionStart context loading example
786-- **`pre-teleport.sh`** - PreTeleport state preservation example
787-- **`post-teleport.sh`** - PostTeleport environment setup example
733+- **`post-teleport.sh`** - SessionStart teleport matcher setup example
788734
789735 ### Utility Scripts
790736
@@ -1,6 +1,7 @@
11 #!/bin/bash
2-# Example PostTeleport hook for setting up environment after teleporting
3-# This script pulls changes, installs dependencies, and starts dev server
2+# Example SessionStart hook with "teleport" matcher for setting up environment
3+# after teleporting from web to CLI. This script pulls changes, installs
4+# dependencies, and starts the dev server.
45
56 set -euo pipefail
67
@@ -14,12 +15,6 @@
1415 current_branch=$(git branch --show-current)
1516 echo "🔄 Pulling latest changes for branch: $current_branch"
1617 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
2318 fi
2419
2520 # Install dependencies based on project type
Dplugins/plugin-dev/skills/hook-development/examples/pre-teleport.sh+0 -33
@@ -1,33 +1,0 @@
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
@@ -347,49 +347,17 @@
347347
348348 ## Pattern 11: Teleport Workflow Automation
349349
350-Automate setup when teleporting sessions between web and CLI:
350+Automate setup when teleporting sessions from web to CLI using the `teleport` matcher:
351351
352-**Pre-teleport hook (prepare for transfer):**
352+**SessionStart hook with teleport matcher:**
353353 ```json
354354 {
355- "PreTeleport": [
355+ "SessionStart": [
356356 {
357- "matcher": "*",
357+ "matcher": "teleport",
358358 "hooks": [
359359 {
360360 "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",
393361 "command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/post-teleport.sh"
394362 }
395363 ]
@@ -407,12 +375,6 @@
407375 if [ -d ".git" ]; then
408376 echo "🔄 Pulling latest changes..."
409377 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
416378 fi
417379
418380 # Install dependencies
@@ -433,8 +395,13 @@
433395 echo "✅ Teleport complete! Environment ready."
434396 ```
435397
398+**Available matchers for SessionStart:**
399+- `*` - All session starts (both fresh and teleported)
400+- `teleport` - Only teleported sessions (web → CLI)
401+- `fresh` - Only fresh sessions (not teleported)
402+
436403 **Use for:**
437404 - Seamless web-to-CLI workflow transitions
438405 - Automatic dev server startup after teleporting
439-- Preserving uncommitted work across teleports
440-- Environment setup automation
406+- Pulling latest changes and installing dependencies
407+- Running project-specific setup scripts