원클릭으로
hooks-test
Test skill demonstrating hooks functionality. Shows PreToolUse, PostToolUse, and Stop hooks in action.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Test skill demonstrating hooks functionality. Shows PreToolUse, PostToolUse, and Stop hooks in action.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Automated API testing assistant for REST and GraphQL endpoints
Backend development expert specializing in API design, microservices, database architecture, and system performance. Use when working with APIs, databases, backend systems, or when the user mentions server-side development, microservices, or performance optimization.
Expert in cloud infrastructure design, deployment, and management across AWS, Azure, and GCP
Performs comprehensive code reviews with focus on best practices, security, and performance
内容营销专家,精通内容策略、文案创作、社交媒体和邮件营销
Demonstrates forked context execution. This skill runs in an isolated sub-agent context with its own conversation history and tool access.
| name | hooks-test |
| description | Test skill demonstrating hooks functionality. Shows PreToolUse, PostToolUse, and Stop hooks in action. |
| version | 1.0.0 |
| author | SDK Team <sdk@example.com> |
| tags | ["testing","hooks","development"] |
| dependencies | [] |
| allowed_tools | ["Read","Write","Bash","Grep"] |
| hooks | {"pre_tool_use":[{"matcher":"Bash","command":"echo '🔍 PreToolUse: About to execute Bash tool'","type":"command","once":false},{"matcher":"Write","command":"echo '📝 PreToolUse: About to write file - $TOOL_NAME'","type":"command","once":false},{"matcher":"*","command":"echo '⚡ PreToolUse: Tool $TOOL_NAME is about to be used'","type":"command","once":true}],"post_tool_use":[{"matcher":"Bash","command":"echo '✅ PostToolUse: Bash tool executed successfully'","type":"command","once":false},{"matcher":"Write","command":"echo '💾 PostToolUse: File written successfully'","type":"command","once":false}],"stop":[{"matcher":"*","command":"echo '🛑 Stop hook: Cleaning up resources...'","type":"command","once":false}]} |
Demonstrates the complete hooks functionality in Claude Agent SDK. This skill showcases how PreToolUse, PostToolUse, and Stop hooks work together to provide event-driven automation.
Hooks are event-driven commands that run at specific points during skill execution:
Each hook has:
When you ask me to run a Bash command:
Please run: echo "Hello World"
Expected Output:
🔍 PreToolUse: About to execute Bash tool
[Bash command executes]
✅ PostToolUse: Bash tool executed successfully
When you ask me to write a file:
Create a file named test.txt with content "Hello"
Expected Output:
📝 PreToolUse: About to write file - Write
[File is written]
💾 PostToolUse: File written successfully
The * matcher with once: true will run only once for the first tool used:
Run any command
Expected Output:
⚡ PreToolUse: Tool <tool_name> is about to be used
[This message appears only once per session]
When this skill finishes execution:
Expected Output:
🛑 Stop hook: Cleaning up resources...
* matcher applies to all toolsonce: true ensures hook runs only once per sessionYou can use patterns in the matcher field:
hooks:
PreToolUse:
# Match specific tool
- matcher: "Bash"
hooks:
- type: command
command: "echo 'Bash tool detected'"
# Match multiple tools with wildcard
- matcher: "Bash*"
hooks:
- type: command
command: "echo 'Any Bash-related tool'"
# Match all tools
- matcher: "*"
hooks:
- type: command
command: "echo 'Any tool'"
Hooks can access environment variables:
hooks:
PreToolUse:
- matcher: "*"
hooks:
- type: command
command: "echo 'Tool: $TOOL_NAME, Input: $TOOL_INPUT'"
Instead of inline commands, use scripts:
hooks:
PreToolUse:
- matcher: "Write"
hooks:
- type: script
command: "scripts/validate_write.sh"
With scripts/validate_write.sh:
#!/bin/bash
echo "Validating write operation..."
echo "Tool: $TOOL_NAME"
echo "Input: $TOOL_INPUT"
# Add validation logic here
hooks:
PreToolUse:
- matcher: "Bash"
hooks:
- type: script
command: "scripts/security_check.sh"
hooks:
PostToolUse:
- matcher: "*"
hooks:
- type: command
command: "echo '$(date): Tool $TOOL_NAME used' >> audit.log"
hooks:
Stop:
- matcher: "*"
hooks:
- type: script
command: "scripts/cleanup.sh"
hooks:
PreToolUse:
- matcher: "*"
hooks:
- type: command
command: "echo $(date +%s%N) > /tmp/start_time"
PostToolUse:
- matcher: "*"
hooks:
- type: command
command: |
START=$(cat /tmp/start_time)
END=$(date +%s%N)
echo "Tool execution time: $((($END - $START) / 1000000))ms"
Test each hook type:
once: true prevents repeat executionProblem: Hook command doesn't execute
Solutions:
Problem: Hook with once: true keeps running
Solution: The once flag applies per session. Restart the session to test.
Problem: Hook errors not visible
Solution: Add error handling:
hooks:
PreToolUse:
- matcher: "*"
hooks:
- type: command
command: "python scripts/hook.py 2>&1 || echo 'Hook failed'"
This skill demonstrates:
Try the tests above to see hooks in action!
Version: 1.0.0 Last Updated: 2026-01-10 Maintainer: SDK Team