Skip to content

ToolPermissionContext

🛈 DocStrings

Context information for tool permission callbacks.

Source code in src/clawd_code_sdk/models/permissions.py
@dataclass
class ToolPermissionContext:
    """Context information for tool permission callbacks."""

    tool_use_id: str
    """Unique identifier for this specific tool call within the assistant message.

    Multiple tool calls in the same assistant message will have different tool_use_ids.
    """

    # signal: Any | None = None
    # """Reserved for future abort signal support. Currently always None."""

    agent_id: str | None = None
    """The agent that initiated the tool call, if in a multi-agent setup."""

    decision_reason: str | None = None
    """Why the CLI triggered the permission check."""

    suggestions: list[PermissionUpdate] = field(default_factory=list)
    """Permission suggestions from CLI for updating permissions.

    So the user won't be prompted again for this tool during this session.
    """

    blocked_path: str | None = None
    """The file path that triggered the permission request, if applicable.

    For example, when a Bash command tries to access a path outside allowed directories.
    """

    title: str | None = None
    """Full permission prompt sentence rendered by the bridge.

    E.g. "Claude wants to read foo.txt". Use this as the primary prompt
    text when present instead of reconstructing from toolName+input.
    """

    display_name: str | None = None
    """Short noun phrase for the tool action (e.g. "Read file").

    Suitable for button labels or compact UI.
    """

    description: str | None = None
    """Human-readable subtitle from the bridge.

    E.g. "Claude will have read and write access to files in ~/Downloads".
    """

    tool_name: str | None = None
    """The name of the tool that generated this permission request."""

    input: dict[str, Any] | None = None
    """The input to the tool that generated this permission request."""

    @classmethod
    def from_permission_request(cls, req: SDKControlPermissionRequest) -> Self:
        """Create a PermissionContext from a permission request."""
        return cls(
            tool_use_id=req.tool_use_id,
            agent_id=req.agent_id,
            decision_reason=req.decision_reason,
            suggestions=req.permission_suggestions or [],
            blocked_path=req.blocked_path,
            title=req.title,
            display_name=req.display_name,
            description=req.description,
            tool_name=req.tool_name,
            input=req.input,
        )

agent_id class-attribute instance-attribute

agent_id: str | None = None

The agent that initiated the tool call, if in a multi-agent setup.

blocked_path class-attribute instance-attribute

blocked_path: str | None = None

The file path that triggered the permission request, if applicable.

For example, when a Bash command tries to access a path outside allowed directories.

decision_reason class-attribute instance-attribute

decision_reason: str | None = None

Why the CLI triggered the permission check.

description class-attribute instance-attribute

description: str | None = None

Human-readable subtitle from the bridge.

E.g. "Claude will have read and write access to files in ~/Downloads".

display_name class-attribute instance-attribute

display_name: str | None = None

Short noun phrase for the tool action (e.g. "Read file").

Suitable for button labels or compact UI.

input class-attribute instance-attribute

input: dict[str, Any] | None = None

The input to the tool that generated this permission request.

suggestions class-attribute instance-attribute

suggestions: list[PermissionUpdate] = field(default_factory=list)

Permission suggestions from CLI for updating permissions.

So the user won't be prompted again for this tool during this session.

title class-attribute instance-attribute

title: str | None = None

Full permission prompt sentence rendered by the bridge.

E.g. "Claude wants to read foo.txt". Use this as the primary prompt text when present instead of reconstructing from toolName+input.

tool_name class-attribute instance-attribute

tool_name: str | None = None

The name of the tool that generated this permission request.

tool_use_id instance-attribute

tool_use_id: str

Unique identifier for this specific tool call within the assistant message.

Multiple tool calls in the same assistant message will have different tool_use_ids.

from_permission_request classmethod

from_permission_request(req: SDKControlPermissionRequest) -> Self

Create a PermissionContext from a permission request.

Source code in src/clawd_code_sdk/models/permissions.py
@classmethod
def from_permission_request(cls, req: SDKControlPermissionRequest) -> Self:
    """Create a PermissionContext from a permission request."""
    return cls(
        tool_use_id=req.tool_use_id,
        agent_id=req.agent_id,
        decision_reason=req.decision_reason,
        suggestions=req.permission_suggestions or [],
        blocked_path=req.blocked_path,
        title=req.title,
        display_name=req.display_name,
        description=req.description,
        tool_name=req.tool_name,
        input=req.input,
    )

:fa-brands-github: Show source on GitHub