BlogSubmit

Search mods by name, tag, or keyword.

    Claude Code Hooks: Security and Examples

    Learn hook events, set up PreToolUse checks, and review command permissions before enabling a security hook.

    15 selected entries

    Browse all Claude plugins

    Ready-to-use hook examples

    Showing 15 entries

    Security Guidance — anthropics/claude-code

    Warn about risky code patterns when Claude edits files.

    hooksAnthropic repository152,765 repo starsRepo updated Oct 19, 2026

    Hookify — anthropics/claude-code

    Create behavior warnings with readable rule files instead of editing hook JSON.

    hooksAnthropic repository152,765 repo starsRepo updated Oct 19, 2026

    Explanatory Output Style — anthropics/claude-code

    Add educational implementation context at the start of a session.

    hooksAnthropic repository152,765 repo starsRepo updated Oct 19, 2026

    Dangerous Command Guard — karanb192/claude-code-hooks

    Check Bash calls against configurable patterns for destructive shell commands.

    hooksCommunity project545 repo starsRepo updated Oct 17, 2026

    Sensitive File Guard — karanb192/claude-code-hooks

    Check file access and shell requests against sensitive-path and secret-exposure patterns.

    hooksCommunity project545 repo starsRepo updated Oct 17, 2026

    Git Safety Hook — karanb192/claude-code-hooks

    Check protected-branch operations and destructive GitHub CLI requests before they run.

    hooksCommunity project545 repo starsRepo updated Oct 17, 2026

    Test Preservation Hook — karanb192/claude-code-hooks

    Flag attempts to remove or disable tests while Claude Code edits a project.

    hooksCommunity project545 repo starsRepo updated Oct 17, 2026

    Auto Stage Hook — karanb192/claude-code-hooks

    Stage files in Git immediately after Claude Code writes or edits them.

    hooksCommunity project545 repo starsRepo updated Oct 17, 2026

    Format Code Hook — karanb192/claude-code-hooks

    Run Ruff or Prettier after Claude Code changes a supported source file.

    hooksCommunity project545 repo starsRepo updated Oct 17, 2026

    Slack Permission Notifications — karanb192/claude-code-hooks

    Send a Slack alert when a Claude Code session needs permission or user input.

    hooksCommunity project545 repo starsRepo updated Oct 17, 2026

    Session Markdown Logger — karanb192/claude-code-hooks

    Keep local Markdown notes of session files, commands and repository context.

    hooksCommunity project545 repo starsRepo updated Oct 17, 2026

    Context Hogs — karanb192/claude-code-hooks

    Estimate which files contribute most to tool-result context and repeated reads.

    hooksCommunity project545 repo starsRepo updated Oct 17, 2026

    Standup Autopilot — karanb192/claude-code-hooks

    Build a daily work summary from local Claude Code session outcomes and blockers.

    hooksCommunity project545 repo starsRepo updated Oct 17, 2026

    Configuration Watch Hook — karanb192/claude-code-hooks

    Surface configuration changes during a session, with an optional blocking mode.

    hooksCommunity project545 repo starsRepo updated Oct 17, 2026

    Dead End Registry — karanb192/claude-code-hooks

    Record reverted approaches and surface reminders when a later task may repeat them.

    hooksCommunity project545 repo starsRepo updated Oct 17, 2026

    What are Claude Code hooks

    A Claude Code hook reacts to a lifecycle event such as a tool call, a prompt submission, or a session starting. Depending on its type, a hook can run a command, ask a model to check a condition, or provide context. That makes hooks powerful for repeatable checks, but also means their behavior must be visible and intentional.

    Use a hook for work that has a clear trigger: checking a pending tool request, adding a project reminder when a session begins, or supplying a follow-up instruction after a file edit. Write down the expected event and result first. If the requirement is simply reusable task advice, a skill or command may be easier to maintain.

    This page covers settings-based hooks. Native mods use function hooks inside Claude Code and have a different registration format. Do not paste a plugin’s JavaScript module into settings JSON. For the examples here, merge the hooks property into a settings file and keep unrelated preferences and existing event entries intact.

    Hook events explained

    PreToolUse fires before a matching tool runs and is suitable for a guard or approval check. PostToolUse fires after a tool call and can record or inspect its result. SessionStart prepares context, while UserPromptSubmit can react to an incoming prompt. Choose the narrowest event and matcher: a broad matcher makes a hook run more often and increases noise or risk.

    The four examples cover different moments in one session. PreToolUse can request confirmation before a matching call; PostToolUse observes a successful call after the change has happened. SessionStart adds initial context, and UserPromptSubmit adds a reminder before a submitted prompt is processed. These are event hooks, not a timer or background synchronization service.

    A matcher selects the event-specific value, not arbitrary text from the conversation. For tool events, Edit|Write selects those tool names. For SessionStart, startup selects a new session. UserPromptSubmit has no matcher support, so its example deliberately omits that field. Change the trigger only after you understand which input the event supplies.

    PreToolUse

    Before a Bash call executes, this example requests confirmation. It leaves a human decision in the workflow rather than guessing whether a command is safe. Every matching call can prompt, so try it in a small project before using it throughout your normal work. It is not a shell-command security scanner.

    PreToolUse · .claude/settings.json

    {
      "hooks": {
        "PreToolUse": [
          {
            "matcher": "Bash",
            "hooks": [
              {
                "type": "command",
                "command": "printf '%s\\n' '{\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"permissionDecision\":\"ask\",\"permissionDecisionReason\":\"Confirm this shell command before it runs.\"}}'"
              }
            ]
          }
        ]
      }
    }

    PostToolUse

    After Edit or Write succeeds, this example adds a reminder to select relevant checks. The file change has already happened. The hook neither rolls back the edit nor runs a test suite; it supplies context for the next step. Confirm the actual test result separately before treating the change as verified.

    PostToolUse · .claude/settings.json

    {
      "hooks": {
        "PostToolUse": [
          {
            "matcher": "Edit|Write",
            "hooks": [
              {
                "type": "command",
                "command": "printf '%s\\n' '{\"hookSpecificOutput\":{\"hookEventName\":\"PostToolUse\",\"additionalContext\":\"A file changed. Choose the relevant checks before reporting completion.\"}}'"
              }
            ]
          }
        ]
      }
    }

    SessionStart

    At a new session’s startup, this example supplies a short package-manager convention. Replace the pnpm instruction if your project uses another tool. It does not install dependencies or change configuration. The startup matcher deliberately excludes other SessionStart cases such as resuming a session, so choose that scope consciously.

    SessionStart · .claude/settings.json

    {
      "hooks": {
        "SessionStart": [
          {
            "matcher": "startup",
            "hooks": [
              {
                "type": "command",
                "command": "printf '%s\\n' 'Project convention: use pnpm and check package.json for available scripts.'"
              }
            ]
          }
        ]
      }
    }

    UserPromptSubmit

    Before a submitted prompt is processed, this example adds a concise reporting convention. There is no matcher field for this event. Repeated reminders consume context, so keep the message brief and avoid including private values. If the instruction belongs to one reusable task rather than every prompt, put it in that task’s skill instead.

    UserPromptSubmit · .claude/settings.json

    {
      "hooks": {
        "UserPromptSubmit": [
          {
            "hooks": [
              {
                "type": "command",
                "command": "printf '%s\\n' 'When describing a change, include its file path and verification result.'"
              }
            ]
          }
        ]
      }
    }

    Claude Code hooks security: permissions and limits

    For Claude Code hooks security, start with what a PreToolUse hook actually matches and whether it asks, denies, or only logs a tool request. Command hooks execute with your user permissions: a Bash check may read files, change a repository, or reach the network. Review the script, matcher, paths and environment variables before enabling it. A pattern-based guard cannot replace Claude Code permissions or sandbox controls.

    Treat event data as input, never as shell source. A filename or prompt may contain quotes, spaces, or command syntax. Parse JSON with a real parser, quote values passed to commands, and avoid eval. The examples here print fixed text or fixed JSON and do not interpolate user-supplied content into executable commands.

    A hook can also slow down an ordinary edit if it launches a network request or full test suite on every event. Begin with a narrow matcher and a short local action. If you later add a formatter, check that it receives the intended file and that repeated runs do not produce a loop or unrelated changes.

    Keep secrets out of emitted context and debug logs. Prefer a fixture project for initial trials, then review the settings diff before sharing it with a team. Removing the hook entry disables future invocations; it does not undo writes or requests that a previously enabled script has already performed.

    For a concrete PreToolUse guard and its detection limits, read Protect Secrets. Check its source and permissions before enabling any security hook.

    • Security Guidance

      Hooks can run commands and inspect code. Review the plugin before enabling it.

    • Hookify

      Rules inspect prompts or tool calls. Check their patterns before use.

    • Explanatory Output Style

      SessionStart hooks run automatically when a session begins.

    • Dangerous Command Guard

      Check this hook’s event and execution permissions before enabling it.

    • Sensitive File Guard

      Check this hook’s event and execution permissions before enabling it.

    • Git Safety Hook

      Check this hook’s event and execution permissions before enabling it.

    • Test Preservation Hook

      Check this hook’s event and execution permissions before enabling it.

    • Auto Stage Hook

      Check this hook’s event and execution permissions before enabling it.

    • Format Code Hook

      Check this hook’s event and execution permissions before enabling it.

    • Slack Permission Notifications

      Check this hook’s event and execution permissions before enabling it.

    • Session Markdown Logger

      Check this hook’s event and execution permissions before enabling it.

    • Context Hogs

      Check this hook’s event and execution permissions before enabling it.

    • Standup Autopilot

      Check this hook’s event and execution permissions before enabling it.

    • Configuration Watch Hook

      Check this hook’s event and execution permissions before enabling it.

    • Dead End Registry

      Check this hook’s event and execution permissions before enabling it.

    How to write your own

    Start from one event, one matcher, and a small action. Keep configuration in `.claude/settings.json` when it belongs to a project and document why the hook exists for teammates. Test what happens on success and failure, then add more events only if needed. A hook should help a workflow, not surprise someone who opens the repository.

    Choose one example above and merge its hooks object into .claude/settings.json. Do not replace the entire file if it already contains permissions or other hooks. The snippets use a POSIX shell, so Windows users need a compatible shell or a PowerShell adaptation. They intentionally avoid external packages and filesystem writes.

    Open /hooks to inspect the loaded settings, then trigger the matching event in a disposable project. The Bash example should request confirmation; the edit example should supply a follow-up instruction after a successful edit. A reminder does not run tests for you. Check the actual behavior, rather than assuming a configuration file being valid JSON means the workflow is complete.

    Test the non-matching case as well: a Read call should not trigger an Edit|Write hook. Keep any diagnostic output separate from machine-readable JSON on stdout. If behavior differs from expectations, reduce the configuration to one event and inspect Claude Code’s hook diagnostics before adding more logic.

    Claude Code documentation

    Frequently Asked Questions

    What counts as a Claude Code mod?

    A mod is a plugin with JavaScript or TypeScript function hooks running inside Claude Code. It can change the interface or how session events are handled. Skills and MCP servers are separate extension types.

    Are these projects official?

    This is an independent directory. Some entries link to Anthropic repositories; others come from community maintainers. Check the source of each entry before installing.

    Are mods safe to install?

    Extensions can read files, run commands, or connect to external services. Review the source and permissions, especially for hooks and MCP servers. A listing here is not a security guarantee.

    What do the stars and dates mean?

    They describe the linked GitHub repository. A plugin inside a repository does not have its own separate star count or update date.