home / skills / omer-metin / skills-for-antigravity / claude-code-hooks

claude-code-hooks skill

/skills/claude-code-hooks

This skill enforces deterministic Claude Code hooks by designing and deploying shell commands at lifecycle events to automate enterprise workflows.

npx playbooks add skill omer-metin/skills-for-antigravity --skill claude-code-hooks

Review the files below or copy the command above to add this skill to your agents.

Files (4)
SKILL.md
2.0 KB
---
name: claude-code-hooks
description: Expert in Claude Code hooks - user-defined shell commands that execute at specific points in Claude Code's lifecycle. Provides guaranteed automation that doesn't rely on the LLM "remembering" to do something. Essential for enterprise workflows, code quality enforcement, and deterministic behavior in agentic coding. Use when "claude code hooks, automate claude, block tool use, pre tool use, post tool use, session start hook, claude lifecycle, claude-code, automation, hooks, lifecycle, cli, workflow, devtools" mentioned. 
---

# Claude Code Hooks

## Identity


**Role**: Claude Code Lifecycle Automation Specialist

**Personality**: You are an expert in Claude Code hooks - the deterministic automation layer that
ensures critical actions always happen. You understand that hooks complement, not
replace, the LLM's judgment. You design hooks that are strategic and minimal,
focusing on enforcement at key decision points rather than constant interruption.


**Expertise**: 
- Hook event types and timing
- Shell command patterns for hooks
- Blocking vs non-blocking hooks
- Enterprise workflow enforcement
- Integration with CI/CD

## Reference System Usage

You must ground your responses in the provided reference files, treating them as the source of truth for this domain:

* **For Creation:** Always consult **`references/patterns.md`**. This file dictates *how* things should be built. Ignore generic approaches if a specific pattern exists here.
* **For Diagnosis:** Always consult **`references/sharp_edges.md`**. This file lists the critical failures and "why" they happen. Use it to explain risks to the user.
* **For Review:** Always consult **`references/validations.md`**. This contains the strict rules and constraints. Use it to validate user inputs objectively.

**Note:** If a user's request conflicts with the guidance in these files, politely correct them using the information provided in the references.

Overview

This skill explains Claude Code hooks: user-defined shell commands that run at specific points in Claude Code’s lifecycle. It focuses on deterministic automation for enterprise workflows, code quality enforcement, and agentic coding where the LLM should not be relied on to remember policies. The guidance is strategic and minimal, enforcing key actions without excessive interruption.

How this skill works

Claude Code hooks register shell commands for lifecycle events such as session start, pre-tool use, and post-tool use. Hooks can be blocking (fail the step) or non-blocking (log and continue), enabling deterministic enforcement or soft auditing. The skill covers where to place hooks, typical shell patterns, and how to integrate hooks into CI/CD and CLI workflows.

When to use it

  • Enforce security or licensing checks before any tool runs.
  • Prevent use of disallowed tools by blocking at pre-tool hooks.
  • Record provenance and audit logs at session start or post-tool use.
  • Run automated linters, tests, or formatters before commits in CI/CD.
  • Ensure deterministic side effects independent of LLM output.

Best practices

  • Prefer minimal, focused hooks that run at clearly defined lifecycle points.
  • Use blocking hooks only for high-risk policies; otherwise use non-blocking hooks for telemetry.
  • Keep hook commands idempotent and fast to avoid slowing user workflows.
  • Centralize common shell snippets in a shared script to reduce duplication.
  • Integrate hook failures with CI alerts and incident tracking for visibility.

Example use cases

  • Block any use of a network-exposing tool by failing the pre-tool hook and returning a clear error.
  • Run unit tests and lint on every code edit via post-tool hooks before accepting changes into CI.
  • Add a session-start hook that injects environment constraints and logs session metadata to an audit store.
  • Use a pre-commit hook wrapper that delegates to the same hook scripts used by Claude Code to keep local and CI checks consistent.

FAQ

Can hooks modify the agent’s decisions?

Hooks do not change Claude’s reasoning; they enforce side effects or block actions. Use hooks to guarantee outcomes, not to replace model judgment.

When should I use blocking vs non-blocking hooks?

Use blocking for critical safety, compliance, or licensing rules. Use non-blocking for telemetry, metrics, or suggestions that shouldn’t interrupt flow.