agent-instructions
Use when writing project instructions for a coding agent (CLAUDE.md, AGENTS.md, or equivalent). Covers what belongs in them, what does not, structure, and…
Use when automating agent behavior with lifecycle hooks. Covers hook events, deterministic enforcement of rules the model should not be trusted to remember, and avoiding hooks that make an agent unusable.
$ npx -y skills add nimadorostkar/Claude-Skills-collection --skill hooks --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/hooksContext preview
The summary Claude sees to decide when to auto-load this skill.
Use when automating agent behavior with lifecycle hooks. Covers hook events, deterministic enforcement of rules the model should not be trusted to remember, and avoiding hooks that make an agent unusable.
name: hooks description: Use when automating agent behavior with lifecycle hooks. Covers hook events, deterministic enforcement of rules the model should not be trusted to remember, and avoiding hooks that make an agent unusable. metadata: category: agent-tooling version: 1.0.0 tags: [hooks, automation, lifecycle, enforcement]
Enforce a rule deterministically rather than asking the model to remember it. A hook runs every time, regardless of the model's attention, its context, or its mood — which is exactly what a rule requires.
1. **Identify the rule that keeps being broken** — If an instruction is in the instruction file and is still violated, it is a hook, not an instruction. Instructions are guidance; hooks are enforcement. 2. **Choose the event** — Before a tool call to block or validate; after one to format or verify; on session start to inject context. 3. **Make it fast** — A hook runs on every matching event. Two seconds on every file edit is a hostile environment. Under 500ms, or run it asynchronously. 4. **Fail informatively** — A hook that blocks must say why and what to do instead. A silent block is maddening and the model cannot recover from it. 5. **Prefer fixing over blocking** — A hook that formats the file is better than one that rejects the edit and demands the model format it. 6. **Test the hook itself** — A broken hook blocks everything, and the failure mode is confusing.
**Format on write — the highest-value hook:**
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "if echo \"$CLAUDE_FILE_PATHS\" | grep -qE '\\.(ts|tsx)$'; then pnpm prettier --write $CLAUDE_FILE_PATHS 2>/dev/null; fi"
}
]
}
]
}
}Every file the agent writes is formatted. The model never has to think about it, the diff is always clean, and the lint step never fails on formatting.
**Blocking a destructive command, with an explanation the model can act on:**
#!/usr/bin/env bash # PreToolUse hook on Bash. Exit 2 blocks the call; stderr is shown to the model. set -euo pipefail command=$(jq -r '.tool_input.command' <<<"$(cat)") if [[ "$command" =~ (^|[[:space:]])rm[[:space:]]+(-[a-zA-Z]*f[a-zA-Z]*[[:space:]]+)*/ ]]; then echo "Blocked: 'rm -rf' targeting an absolute path is not permitted." >&2 echo "If you need to remove build artifacts, use 'pnpm clean'." >&2 exit 2 fi if [[ "$command" =~ git[[:space:]]+push.*--force([[:space:]]|$) ]]; then echo "Blocked: force-push is not permitted on this repository." >&2 echo "Use 'git push --force-with-lease' if you must rewrite a branch you own." >&2 exit 2 fi exit 0
The model receives the message, understands why it was blocked, and uses the suggested alternative — rather than retrying the same command.
A curated library of 137 production-grade skills for Claude and other AI coding agents. Every skill follows one structure, speaks with one voice, and earns its place by changing what the agent does.
Repo: nimadorostkar/Claude-Skills-collection
Use when writing project instructions for a coding agent (CLAUDE.md, AGENTS.md, or equivalent). Covers what belongs in them, what does not, structure, and…
Use when an agent needs state that survives a session or a context compaction. Covers what to persist, file-based memory, structuring notes for retrieval, and…
Use when packaging skills, commands, hooks, and MCP servers into a distributable plugin. Covers manifest structure, bundling, versioning, testing, and…
Use when writing a new skill for an AI agent. Covers scoping, description writing for reliable triggering, progressive disclosure, and the difference between a…
Use when reviewing or improving an existing agent skill. Covers triggering accuracy, content quality, redundancy with the base model, and measuring whether the…
Use when creating reusable slash commands for an agent. Covers when a command beats a skill, argument handling, composing tool calls, and writing commands that…