// 20 tips tagged "hooks"
Hooks let you attach shell commands that fire automatically when Claude uses a tool — run linters after every file edit, log tool usage, block dangerous commands, or enforce project standards without relying on prompts alone.
Configure hooks in your Claude Code settings so commands run automatically when Claude uses specific tools — lint after every file edit, run tests after code changes, or log every bash command, all without asking Claude to do it.
A PostToolUse hook fires after every tool execution — use it to write an audit log of every command Claude runs, every file it edits, and every search it performs, giving your team full visibility into what happened during a session.
Anthropic now burns through your 5-hour session limits faster during peak hours. Here's how to restructure your Claude Code workflow to get the most out of every token.
Pair a UserPromptSubmit hook with a skill-rules.json config to reliably trigger the right skill on every prompt instead of relying on Claude's 50/50 automatic detection.
Type /hooks in Claude Code to open a read-only view of every registered hook, its matcher, source file, and configuration — essential for debugging why a hook isn't firing.
PreToolUse hooks can do more than block — return updatedInput to silently rewrite commands, file paths, or URLs before Claude executes them.
The UserPromptSubmit hook fires before every prompt — use it to silently inject git context, project info, or enforce guardrails without changing your workflow.
Use the CwdChanged and FileChanged hooks with CLAUDE_ENV_FILE to automatically reload your direnv environment whenever Claude switches project directories.
The SessionStart hook fires when any session begins or resumes, making it ideal for loading environment variables and running one-time setup scripts.
A PreToolUse hook can intercept test runner commands and filter output to show only failures, cutting thousands of tokens from Claude's context.
Send POST requests to external services on every tool call using HTTP hooks, with header authentication and the ability to block actions from a remote endpoint.