mirror of
https://github.com/anthropics/claude-code.git
synced 2026-02-19 04:27:33 -08:00
Compare commits
2 Commits
73eddfd640
...
claude/sla
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
93effadd31 | ||
|
|
fee53699c3 |
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: Hook Development
|
||||
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.
|
||||
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.
|
||||
version: 0.1.0
|
||||
---
|
||||
|
||||
@@ -239,7 +239,12 @@ Execute when user submits a prompt. Use to add context, validate, or block promp
|
||||
|
||||
Execute when Claude Code session begins. Use to load context and set environment.
|
||||
|
||||
**Example:**
|
||||
**Matchers for SessionStart:**
|
||||
- `*` - All session starts
|
||||
- `teleport` - Only when session started via teleport (web → CLI)
|
||||
- `fresh` - Only for fresh sessions (not teleported)
|
||||
|
||||
**Example (general context loading):**
|
||||
```json
|
||||
{
|
||||
"SessionStart": [
|
||||
@@ -256,12 +261,58 @@ Execute when Claude Code session begins. Use to load context and set environment
|
||||
}
|
||||
```
|
||||
|
||||
**Example (teleport-specific setup):**
|
||||
```json
|
||||
{
|
||||
"SessionStart": [
|
||||
{
|
||||
"matcher": "teleport",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/post-teleport.sh"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**Example script (post-teleport.sh):**
|
||||
```bash
|
||||
#!/bin/bash
|
||||
cd "$CLAUDE_PROJECT_DIR" || exit 0
|
||||
|
||||
# Pull latest changes from the teleported branch
|
||||
if [ -d ".git" ]; then
|
||||
echo "🔄 Pulling latest changes..."
|
||||
git pull origin "$(git branch --show-current)" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Install dependencies if needed
|
||||
if [ -f "package.json" ]; then
|
||||
echo "📦 Installing dependencies..."
|
||||
npm install --silent
|
||||
fi
|
||||
|
||||
# Start dev server (example for common workflow)
|
||||
if [ -f "package.json" ] && grep -q '"dev"' package.json; then
|
||||
echo "🚀 Starting dev server..."
|
||||
npm run dev &
|
||||
fi
|
||||
```
|
||||
|
||||
**Special capability:** Persist environment variables using `$CLAUDE_ENV_FILE`:
|
||||
```bash
|
||||
echo "export PROJECT_TYPE=nodejs" >> "$CLAUDE_ENV_FILE"
|
||||
```
|
||||
|
||||
See `examples/load-context.sh` for complete example.
|
||||
**Teleport-specific input fields:**
|
||||
- `is_teleport`: Boolean indicating if this session started via teleport
|
||||
- `source`: Where the session came from ("web" or "cli") - only present for teleports
|
||||
- `branch`: The git branch that was teleported - only present for teleports
|
||||
|
||||
See `examples/load-context.sh` and `examples/post-teleport.sh` for complete examples.
|
||||
|
||||
### SessionEnd
|
||||
|
||||
@@ -638,7 +689,7 @@ echo "$output" | jq .
|
||||
| UserPromptSubmit | User input | Context, validation |
|
||||
| Stop | Agent stopping | Completeness check |
|
||||
| SubagentStop | Subagent done | Task validation |
|
||||
| SessionStart | Session begins | Context loading |
|
||||
| SessionStart | Session begins | Context loading (use `teleport` matcher for teleport-specific setup) |
|
||||
| SessionEnd | Session ends | Cleanup, logging |
|
||||
| PreCompact | Before compact | Preserve context |
|
||||
| Notification | User notified | Logging, reactions |
|
||||
@@ -679,6 +730,7 @@ Working examples in `examples/`:
|
||||
- **`validate-write.sh`** - File write validation example
|
||||
- **`validate-bash.sh`** - Bash command validation example
|
||||
- **`load-context.sh`** - SessionStart context loading example
|
||||
- **`post-teleport.sh`** - SessionStart teleport matcher setup example
|
||||
|
||||
### Utility Scripts
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#!/bin/bash
|
||||
# Example SessionStart hook with "teleport" matcher for setting up environment
|
||||
# after teleporting from web to CLI. This script pulls changes, installs
|
||||
# dependencies, and starts the 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)"
|
||||
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
|
||||
@@ -344,3 +344,64 @@ fi
|
||||
- Per-project settings
|
||||
- Team-specific rules
|
||||
- Dynamic validation criteria
|
||||
|
||||
## Pattern 11: Teleport Workflow Automation
|
||||
|
||||
Automate setup when teleporting sessions from web to CLI using the `teleport` matcher:
|
||||
|
||||
**SessionStart hook with teleport matcher:**
|
||||
```json
|
||||
{
|
||||
"SessionStart": [
|
||||
{
|
||||
"matcher": "teleport",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/post-teleport.sh"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**post-teleport.sh:**
|
||||
```bash
|
||||
#!/bin/bash
|
||||
cd "$CLAUDE_PROJECT_DIR" || exit 0
|
||||
|
||||
# Pull latest changes
|
||||
if [ -d ".git" ]; then
|
||||
echo "🔄 Pulling latest changes..."
|
||||
git pull origin "$(git branch --show-current)" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Install dependencies
|
||||
if [ -f "package.json" ]; then
|
||||
echo "📦 Installing dependencies..."
|
||||
npm install --silent
|
||||
fi
|
||||
|
||||
# Start dev server
|
||||
if [ -f "package.json" ] && grep -q '"dev:staging"' package.json; then
|
||||
echo "🚀 Starting staging dev server..."
|
||||
npm run dev:staging &
|
||||
elif [ -f "package.json" ] && grep -q '"dev"' package.json; then
|
||||
echo "🚀 Starting dev server..."
|
||||
npm run dev &
|
||||
fi
|
||||
|
||||
echo "✅ Teleport complete! Environment ready."
|
||||
```
|
||||
|
||||
**Available matchers for SessionStart:**
|
||||
- `*` - All session starts (both fresh and teleported)
|
||||
- `teleport` - Only teleported sessions (web → CLI)
|
||||
- `fresh` - Only fresh sessions (not teleported)
|
||||
|
||||
**Use for:**
|
||||
- Seamless web-to-CLI workflow transitions
|
||||
- Automatic dev server startup after teleporting
|
||||
- Pulling latest changes and installing dependencies
|
||||
- Running project-specific setup scripts
|
||||
|
||||
Reference in New Issue
Block a user