Hooks Automation logo

Hooks Automation

Community
frankxai
hooks-automation

Configure and automate Claude Code hooks in .claude/settings.json (PreToolUse, PostToolUse, UserPromptSubmit, Stop, SubagentStop, SessionEnd). Use when setting up Claude Code hooks to auto-format files after edits, run pre-commit or safety checks before Bash commands, guard secrets or protected files, save session state on Stop or SessionEnd, or wire optional external CLI and MCP hook runners.

Overview

Publisherfrankxai
Repositoryclaude-skills-library
Skill namehooks-automation
Stars
47
Forks
6
Bundled files
5
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 5 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by frankxai on GitHub. Read the source before you install it.

Installation

Install the Hooks Automation AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/frankxai/claude-skills-library/tree/main/free-skills/hooks-automation
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/frankxai/claude-skills-library.git /tmp/claude-skills-library
mkdir -p .claude/skills
cp -r /tmp/claude-skills-library/free-skills/hooks-automation .claude/skills/hooks-automation
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Hooks Automation in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Hooks Automation on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Hooks Automation is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Claude Code Hooks Automation

Configure deterministic lifecycle hooks in .claude/settings.json (project) or ~/.claude/settings.json (user) so Claude Code automatically formats edited files, gates risky shell or Git commands before execution, blocks secret leaks or protected-file writes, and persists session state on completion.

Trigger Boundaries

  • Activate when: Setting up or debugging .claude/settings.json or ~/.claude/settings.json "hooks", writing PreToolUse / PostToolUse / UserPromptSubmit / Stop / SubagentStop / SessionEnd scripts, enforcing exit 2 blocking gates, or returning structured JSON decisions on stdout.
  • Do NOT activate when: Writing React hooks (useState, useEffect), Git-only .git/hooks/ without Claude Code lifecycle integration, or generic webhook endpoints (Stripe/Polar/GitHub HTTP webhooks).

Native Claude Code Hooks (settings.json)

Claude Code executes shell commands registered under the "hooks" key in .claude/settings.json at specific lifecycle events. Every hook receives a JSON payload on stdin and communicates back via exit codes and stdout/stderr.

Hook Lifecycle Events

EventWhen It FiresCommon Use Cases
PreToolUseBefore a tool call executes (matches tool_name via regex matcher)Block unsafe Bash commands, run pre-commit checks before git commit, guard secrets and protected files
PostToolUseAfter a tool call completes successfullyAuto-format files after Write, Edit, or MultiEdit; run targeted tests
UserPromptSubmitWhen the user submits a prompt, before Claude processes itInject repository context, validate prompt constraints
StopWhen the main Claude Code agent finishes respondingSave session state, log trajectory metrics, verify completion checks
SubagentStopWhen a spawned subagent (Task) finishes respondingAggregate subagent outputs, verify handoff receipts
SessionEndWhen a Claude Code session closes or terminatesPersist final session state, export metrics, clean up temporary artifacts

Exit Code, Stdin & JSON Stdout Decision Contract

  • Stdin JSON payload: Every hook command receives JSON on stdin containing session_id, transcript_path, cwd, hook_event_name, and (for tool hooks) tool_name, tool_input, and tool_response.
  • Exit code 0 (Allow): Operation proceeds normally. When exiting 0, a hook may also print structured JSON to stdout for fine-grained decision control:
    json
    {
      "hookSpecificOutput": {
        "hookEventName": "PreToolUse",
        "permissionDecision": "allow",
        "permissionDecisionReason": "Verified safe read-only command"
      }
    }
    (Supported permissionDecision values for PreToolUse: "allow", "deny", "ask"; for Stop / SubagentStop: {"decision": "block", "reason": "Run test suite before stopping"}.)
  • Exit code 2 (Block): Immediately blocks the action (for PreToolUse, prevents the tool call; for Stop, prevents stopping) and feeds stderr directly back to Claude so it can self-correct.
  • Any other non-zero exit code: Non-blocking warning; logged to debug output while execution continues.

Primary Recipes (.claude/settings.json)

Recipe 1: Auto-Format After Every Edit + Pre-Commit Check + Secret/File Guard

Place this configuration in .claude/settings.json to:

  1. Guard against secret leaks and protected file edits (PreToolUse on Write|Edit|MultiEdit),
  2. Run a pre-commit check before git commit (PreToolUse on Bash), and
  3. Run Prettier automatically after every file edit (PostToolUse on Write|Edit|MultiEdit):
json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Write|Edit|MultiEdit",
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/file-and-secret-guard.sh"
          }
        ]
      },
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/pre-commit-check.sh"
          }
        ]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "Write|Edit|MultiEdit",
        "hooks": [
          {
            "type": "command",
            "command": "jq -r '.tool_input.file_path // empty' | xargs -r npx prettier --write"
          }
        ]
      }
    ]
  }
}
Blocking Pre-Commit Gate (.claude/hooks/pre-commit-check.sh)
bash
#!/usr/bin/env bash
set -euo pipefail
PAYLOAD="$(cat)"
CMD="$(printf '%s' "$PAYLOAD" | jq -r '.tool_input.command // empty')"

if [[ "$CMD" =~ git[[:space:]]+commit ]]; then
  if ! npm run lint --silent || ! npm test --silent; then
    echo "Pre-commit check failed: fix lint/test errors before committing." >&2
    exit 2
  fi
fi
exit 0
Blocking Secret & Protected-File Guard (.claude/hooks/file-and-secret-guard.sh)
bash
#!/usr/bin/env bash
set -euo pipefail
PAYLOAD="$(cat)"
FILE_PATH="$(printf '%s' "$PAYLOAD" | jq -r '.tool_input.file_path // empty')"
CONTENT="$(printf '%s' "$PAYLOAD" | jq -r '(.tool_input.content // .tool_input.new_string // empty)')"

if [[ "$FILE_PATH" =~ (^|/)(\.env|CANON_LOCKED\.md)$ ]]; then
  echo "Blocked write to protected file: $FILE_PATH" >&2
  exit 2
fi

if printf '%s' "$CONTENT" | grep -Eq '(sk-[A-Za-z0-9_-]{20,}|ghp_[A-Za-z0-9]{20,}|AKIA[0-9A-Z]{16})'; then
  echo "Blocked write: detected hardcoded secret token in $FILE_PATH" >&2
  exit 2
fi

exit 0

Recipe 2: Save Session State When a Session Ends (Stop / SessionEnd)

Use Stop (end of turn/task) and SessionEnd (when the session closes) in .claude/settings.json to persist session state and transcript metadata:

json
{
  "hooks": {
    "Stop": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/save-session-state.sh"
          }
        ]
      }
    ],
    "SessionEnd": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/save-session-state.sh"
          }
        ]
      }
    ]
  }
}

Example .claude/hooks/save-session-state.sh:

bash
#!/usr/bin/env bash
set -euo pipefail
mkdir -p .claude/state
PAYLOAD="$(cat)"
SESSION_ID="$(printf '%s' "$PAYLOAD" | jq -r '.session_id // "unknown"')"
printf '%s\n' "$PAYLOAD" > ".claude/state/session-${SESSION_ID}.json"
exit 0

Optional Integration: External CLI & Swarm Hook Runners

When running multi-agent swarms or external memory coordination alongside native .claude/settings.json hooks, you can wire optional CLI runners such as claude-flow inside the command field of a native hook:

bash
# Optional: pre-task and post-edit swarm memory hooks invoked from a command script
npx claude-flow hook pre-task --description "Implement authentication"
npx claude-flow hook post-edit --file "src/auth.js" --memory-key "auth/login"
npx claude-flow hook session-end --session-id "dev-session" --export-metrics

Reference

Detailed catalogs and extended patterns live in references/ and load on demand:

Verification Checklist

  1. Valid JSON: Verify .claude/settings.json parses cleanly with jq empty .claude/settings.json.
  2. Stdin Payload Test: Pipe a synthetic payload (echo '{"tool_name":"Bash","tool_input":{"command":"git commit -m test"}}' | .claude/hooks/pre-commit-check.sh) and verify exit code 0 vs 2.
  3. Fast Execution: Keep synchronous PreToolUse and PostToolUse hooks under 100ms or scope matcher tightly (Write|Edit|MultiEdit, Bash).
  4. Fail Closed with Exit Code 2: Always write the blocking reason to stderr (>&2) before exit 2 so Claude receives actionable feedback.

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Hooks Automation AI skill do?

Configure and automate Claude Code hooks in .claude/settings.json (PreToolUse, PostToolUse, UserPromptSubmit, Stop, SubagentStop, SessionEnd). Use when setting up Claude Code hooks to auto-format files after edits, run pre-commit or safety checks before Bash commands, guard secrets or protected files, save session state on Stop or SessionEnd, or wire optional external CLI and MCP hook runners.

Why use Hooks Automation on TypingMind?

Because you install it once and use it with any model. Hooks Automation is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Hooks Automation in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/frankxai/claude-skills-library/tree/main/free-skills/hooks-automation. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Hooks Automation?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Hooks Automation?

As many as you like. As long as a model supports skills, you can use Hooks Automation with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Hooks Automation AI skill free?

Yes. It is published on GitHub by frankxai under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇