NAME

Claude::Agent::Hook - Hook system for Claude Agent SDK

SYNOPSIS

use Claude::Agent::Hook;
use Claude::Agent::Options;

my $options = Claude::Agent::Options->new(
    hooks => {
        PreToolUse => [
            Claude::Agent::Hook::Matcher->new(
                matcher => 'Bash',
                hooks   => [sub {
                    my ($input, $tool_use_id, $context) = @_;
                    my $command = $input->{tool_input}{command};
                    if ($command =~ /rm -rf/) {
                        return {
                            decision => 'deny',
                            reason   => 'Dangerous command blocked',
                        };
                    }
                    return { decision => 'continue' };
                }],
            ),
        ],
    },
);

DESCRIPTION

This module provides the hook system for intercepting and modifying tool calls in the Claude Agent SDK.

HOOK EVENTS

  • PreToolUse - Before a tool is executed

  • PostToolUse - After a tool completes successfully

  • PostToolUseFailure - After a tool fails

  • UserPromptSubmit - When a user prompt is submitted

  • Stop - When the agent stops

  • SubagentStart - When a subagent starts

  • SubagentStop - When a subagent stops

  • PreCompact - Before conversation compaction

  • PermissionRequest - When permission is needed

  • SessionStart - When a session starts

  • SessionEnd - When a session ends

  • Notification - For notifications

HOOK CLASSES

AUTHOR

LNATION, <email at lnation.org>

LICENSE

This software is Copyright (c) 2026 by LNATION.

This is free software, licensed under The Artistic License 2.0 (GPL Compatible).