pre-post-hooks

pre-post-hooks is a skill for Claude Code, Codex from VersoXBT/claude-initial-setup. It costs 60 tokens per session (1,269 once invoked), scanned B, original, MIT.

A guide to Claude Code hooks: shell commands that run automatically before or after tool calls, or when a session ends. Hooks can check, format, or block work.

In plain words
What is it for?
Use it to configure PreToolUse, PostToolUse, and Stop hooks in settings.json for formatting, linting, validation, cleanup, or guardrails.
Why use it?
It removes the need to remember routine checks after every change. It also lets you stop unsafe or invalid actions before they run.

Skill for Claude CodeCodex

Part of the claude-initial-setup plugin — 75 skills, 15 commands, 14 agents, 2 hooks shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/versoxbt/claude-initial-setup/pre-post-hooks
Any agent
npx skills add VersoXBT/claude-initial-setup --skill pre-post-hooks
Clone the repo
git clone --depth 1 https://github.com/VersoXBT/claude-initial-setup

Made for: Claude Code, Codex.

Or install claude-initial-setup, the plugin that ships this one along with the rest of its 75 skills, 15 commands, 14 agents, 2 hooks.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for pre-post-hooks

README.md
[![agentmods](https://agentmods.dev/badge/skills/versoxbt/claude-initial-setup/pre-post-hooks.svg)](https://agentmods.dev/skills/versoxbt/claude-initial-setup/pre-post-hooks)
Your own site
<a href="https://agentmods.dev/skills/versoxbt/claude-initial-setup/pre-post-hooks"><img src="https://agentmods.dev/badge/skills/versoxbt/claude-initial-setup/pre-post-hooks.svg" alt="Measured on agentmods" height="20"></a>
Per session 60 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,269 The whole file, excluding the scripts and references it only reads on demand.
Security scan B 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00060 $0.01269
Opus 5 $0.00030 $0.00634
Sonnet 5 $0.00012 $0.00254
Haiku 4.5 $0.00006 $0.00127

Measured yesterday against content hash 745ed4594396, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade B, and why

pre-post-hooks scanned grade B with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Reads agent configuration directoriesmediumAgent snooping

.claude/, .codex/, .gemini/ hold keys, settings and other credentials a mod has no legitimate need for.

Hooks live in `~/.claude/settings.json` under the `hooks` key:
skills/hooks/pre-post-hooks/SKILL.md · 177 lines

How it starts

The opening of the file, as written. The whole thing — 177 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Pre/Post Hooks

Claude Code hooks are shell commands that execute automatically in response to tool events. They enable validation, formatting, and guardrails without manual intervention.

When to Use

  • User wants to run a command before or after a tool executes
  • User asks about PreToolUse, PostToolUse, or Stop hooks
  • User wants to add validation gates or blockers
  • User needs to configure hooks in settings.json
  • User mentions auto-running commands on file edit, git push, or session end

Core Patterns

Hook Types and Lifecycle

PreToolUse  --> Tool Executes --> PostToolUse
                                       |
                                  (session ends)
                                       |
                                     Stop
  • PreToolUse: Runs before a tool call. Can block execution by returning a non-zero exit code.
  • PostToolUse: Runs after a tool call completes. Used for side effects like formatting or checks.
  • Stop: Runs when the agent session ends. Used for final audits or cleanup.

Hook Configuration in settings.json

Hooks live in ~/.claude/settings.json under the hooks key:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Write|Edit",
        "command": "echo 'About to write a file'",
        "description": "Log before file writes"
      }
    ],
    "PostToolUse": [
      {
        "matcher": "Edit",
        "command": "npx prettier --write \"$CLAUDE_FILE_PATH\"",
        "description": "Auto-format after editing JS/TS files"
      }
    ],
    "Stop": [
      {
        "command": "echo 'Session ended'",
        "description": "Log session end"
      }
    ]
  }
}

Matcher Patterns

The matcher field filters which tool triggers the hook. It matches against tool names:

{
  "matcher": "Edit",
  "command": "..."
}

Common tool names to match:

  • Write — file creation
  • Edit — file modification
  • Bash — shell command execution
  • Read — file reading
  • Glob — file search
  • Grep — content search

Read the full file on GitHub · 177 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 177 lines · 60 tokens per session scan B 745ed4594396

Subscribe to this mod's changes

pre-post-hooks is a skill published in the GitHub repository VersoXBT/claude-initial-setup (4 stars, last pushed 3mo ago), licensed MIT. It adds 60 tokens to every session and 1,269 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it B with 1 finding (reads agent configuration directories). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.