NAME

Claude::Agent::Permission - Permission handling for Claude Agent SDK

SYNOPSIS

use Claude::Agent::Permission;

my $options = Claude::Agent::Options->new(
    can_use_tool => sub {
        my ($tool_name, $input, $context) = @_;
        if ($tool_name eq 'Bash' && $input->{command} =~ /rm/) {
            return Claude::Agent::Permission->deny(
                message => "Delete commands not allowed"
            );
        }
        return Claude::Agent::Permission->allow;
    },
);

DESCRIPTION

The CLI asks the can_use_tool callback whenever it would otherwise prompt a person for permission: a tool that no rule, mode or allowed_tools entry already allows. Hooks run first, so a PreToolUse hook that allows or denies the tool pre-empts the callback. This module provides the factories for the callback's answers and the constants for the permission modes.

PERMISSION MODES

  • default - Normal permission behavior

  • acceptEdits - Auto-accept file edits

  • bypassPermissions - Bypass all permission checks

  • dontAsk - Deny anything that would prompt

  • plan - Read-only planning

  • auto - Let the CLI's classifier decide

  • manual - Ask for everything

Exported on request as $MODE_DEFAULT, $MODE_ACCEPT_EDIT, $MODE_BYPASS, $MODE_DONT_ASK, $MODE_PLAN, $MODE_AUTO and $MODE_MANUAL. The same list is @Claude::Agent::Types::PERMISSION_MODES, which the permission_mode option is validated against.

PERMISSION CLASSES

CLASS METHODS

allow

my $result = Claude::Agent::Permission->allow(
    updated_input       => $input,
    updated_permissions => \@updates,
);

Create an allow result. Both arguments are optional; when updated_input is not given the tool runs with the input it asked about.

deny

my $result = Claude::Agent::Permission->deny(
    message   => "Not allowed",
    interrupt => 1,
);

Create a deny result. message is shown to the model; interrupt ends the turn. Both are optional.

coerce

my $result = Claude::Agent::Permission->coerce($thing);

Returns $thing when it is already a result object, builds one from a hashref with a behavior key of allow or deny (taking updated_input/updatedInput, updated_permissions/updatedPermissions, message and interrupt), and returns undef for anything else.

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).