Skip to content

Conversation

@phil65
Copy link

@phil65 phil65 commented Jan 6, 2026

Add tool_use_id and blocked_path fields to ToolPermissionContext to match the TypeScript SDK's CanUseTool callback signature.

This allows permission callbacks to know which specific tool call is being authorized, enabling proper tracking and UI correlation (e.g., for ACP permission dialogs that need to reference the tool call).

Changes:

  • Add tool_use_id (required) and blocked_path (optional) to ToolPermissionContext
  • Add tool_use_id to SDKControlPermissionRequest TypedDict
  • Update _handle_control_request to pass these fields to the callback

Add tool_use_id and blocked_path fields to ToolPermissionContext to match
the TypeScript SDK's CanUseTool callback signature.

This allows permission callbacks to know which specific tool call is being
authorized, enabling proper tracking and UI correlation (e.g., for ACP
permission dialogs that need to reference the tool call).

Changes:
- Add tool_use_id (required) and blocked_path (optional) to ToolPermissionContext
- Add tool_use_id to SDKControlPermissionRequest TypedDict
- Update _handle_control_request to pass these fields to the callback
Copilot AI review requested due to automatic review settings January 6, 2026 06:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds tool_use_id and blocked_path fields to the ToolPermissionContext to align with the TypeScript SDK's CanUseTool callback signature. This enhancement enables permission callbacks to identify specific tool calls for better tracking and UI correlation, particularly for features like ACP permission dialogs that need to reference individual tool calls.

Key changes:

  • Added tool_use_id (required) and blocked_path (optional) fields to ToolPermissionContext dataclass with comprehensive documentation
  • Updated SDKControlPermissionRequest TypedDict to include tool_use_id as a required field
  • Modified _handle_control_request to pass these new fields from the CLI request to the callback context

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/claude_agent_sdk/types.py Added tool_use_id (required) and blocked_path (optional) fields to ToolPermissionContext dataclass and SDKControlPermissionRequest TypedDict with detailed docstring documentation
src/claude_agent_sdk/_internal/query.py Updated _handle_control_request to extract and pass tool_use_id and blocked_path from permission requests to the ToolPermissionContext

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

raise Exception("canUseTool callback is not provided")

context = ToolPermissionContext(
tool_use_id=permission_request.get("tool_use_id", ""),
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tool_use_id field is marked as required (not optional) in the SDKControlPermissionRequest TypedDict, but here it's being accessed with .get() and defaulting to an empty string. This creates a mismatch: if the CLI fails to send tool_use_id, the code will silently use an empty string instead of failing fast with a clear error. Either:

  1. Change the TypedDict to make tool_use_id optional (tool_use_id: NotRequired[str]), or
  2. Access it directly without .get() since it's required: tool_use_id=permission_request["tool_use_id"]

Given that the PR description states this field is needed "to know which specific tool call is being authorized", option 2 (making it truly required) seems more appropriate.

Suggested change
tool_use_id=permission_request.get("tool_use_id", ""),
tool_use_id=permission_request["tool_use_id"],

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant