ClaudeSuperPower
P

PostToolUse (Edit|Write)

Hook

Fires on

PostToolUsematchingEdit|Write

Immediately after a tool returns, with its result available.

Where this sits in a session

  1. Session start
  2. Prompt submitted
  3. Prompt expansion
  4. Before tool use
  5. After tool use
  6. Notification
  7. Before compaction
  8. Subagent finished
  9. Turn finished
  10. Session end

Observes onlyEmits messages or context. It never returns a permission decision.

What it runs

Executed automatically when the event fires — no prompt, no confirmation.

command· timeout 120s
bash "${CLAUDE_PLUGIN_ROOT}/scripts/validate-template.sh"

Install it yourself

Paste into .claude/settings.json to run this hook without installing the whole plugin. Adjust the paths to point at your own copy of the scripts.

settings.json
{
  "hooks": {
    "PostToolUse": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/validate-template.sh\"",
            "timeout": 120
          }
        ],
        "matcher": "Edit|Write"
      }
    ]
  }
}

Source

Read this before installing — it runs on your machine with your permissions.

#!/bin/bash
# Validates SAM templates after editing template.yaml or template.yml.
# Runs as a PostToolUse hook on Edit/Write operations.

set -euo pipefail

# Skip if jq is not installed
if ! command -v jq &> /dev/null; then
  echo '{"systemMessage": "jq not found — SAM template validation skipped. Install jq for automatic validation."}'
  exit 0
fi

INPUT=$(cat)

FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty')

# Only validate SAM template files
case "$FILE_PATH" in
  *template.yaml|*template.yml) ;;
  *) exit 0 ;;
esac

# Skip if SAM CLI is not installed
if ! command -v sam &> /dev/null; then
  echo '{"systemMessage": "SAM CLI not found — template validation skipped. Install SAM CLI for automatic validation."}'
  exit 0
fi

# Skip if file doesn't exist (deleted)
if [ ! -f "$FILE_PATH" ]; then
  exit 0
fi

OUTPUT=$(sam validate --template "$FILE_PATH" --lint 2>&1) && STATUS=0 || STATUS=$?

if [ $STATUS -eq 0 ]; then
  echo '{"systemMessage": "SAM template validation and linting passed."}'
else
  FORMATTED=$(echo "$OUTPUT" | jq -Rs '{systemMessage: ("SAM template validation/linting failed:\n" + .)}' 2>/dev/null) || \
    FORMATTED="{\"systemMessage\": \"SAM template validation/linting failed:\\n$OUTPUT\"}"
  echo "$FORMATTED"
fi

exit 0

Shipped by 1 plugin

Installing any of these installs this hook.

Reviews

Log in to leave a review.

No reviews yet — be the first.

Explore related

Other things in this space — across every part of the ecosystem, not just hooks.