Skip to content

feat: expose agent_type on ToolPermissionContext for can_use_tool#1131

Open
sridhar-3009 wants to merge 1 commit into
anthropics:mainfrom
sridhar-3009:feat/permission-context-agent-type-275
Open

feat: expose agent_type on ToolPermissionContext for can_use_tool#1131
sridhar-3009 wants to merge 1 commit into
anthropics:mainfrom
sridhar-3009:feat/permission-context-agent-type-275

Conversation

@sridhar-3009

Copy link
Copy Markdown

Summary

Addresses the permission-callback half of #275 ("Expose subagent type to hooks and permission callbacks").

The hooks half of this request is already handled: PreToolUseHookInput, PostToolUseHookInput, PostToolUseFailureHookInput, and PermissionRequestHookInput all carry agent_type alongside agent_id via _SubagentContextMixin (see the comment at types.py around BaseHookInput/_SubagentContextMixin — "agent_id/agent_type are present on BaseHookInput in the CLI's schema").

The can_use_tool permission-callback path never got the same treatment:

  • SDKControlPermissionRequest (the wire-protocol TypedDict for this control request) only declared agent_id, not agent_type.
  • query.py's _handle_control_request only read agent_id off the request into ToolPermissionContext, dropping agent_type even though it travels alongside agent_id everywhere else in this schema.
  • ToolPermissionContext (the dataclass callers of can_use_tool actually receive) had no agent_type field at all.

This PR adds agent_type in all three places, mirroring the exact agent_id plumbing already in place, so can_use_tool callbacks can attribute a permission decision to the correct sub-agent type (e.g. "code-reviewer" vs "general-purpose") the same way hook callbacks already can.

Test plan

  • Added test_permission_callback_receives_agent_type and test_permission_callback_missing_agent_type in tests/test_tool_callbacks.py, mirroring the existing test_permission_callback_receives_tool_use_id / test_permission_callback_missing_agent_id tests for agent_id.
  • pytest (1241 passed, 5 pre-existing skips, no new failures)
  • mypy src/ (strict mode, clean)
  • ruff check / ruff format --check (clean)

🤖 Generated with Claude Code

PreToolUse/PostToolUse/PermissionRequest hook inputs already carry
agent_type alongside agent_id (via _SubagentContextMixin) so hook
callbacks can tell which sub-agent a tool call came from. The
can_use_tool permission-callback path never got the same treatment:
SDKControlPermissionRequest only declared agent_id, and query.py's
ToolPermissionContext construction only read agent_id off the wire
payload, silently leaving agent_type on the table.

This adds agent_type to SDKControlPermissionRequest and
ToolPermissionContext, and forwards it in the can_use_tool control
request handler, matching the existing agent_id plumbing.

Addresses the permission-callback half of anthropics#275 (the hooks half was
already covered by prior work on PreToolUse/PostToolUse/
PermissionRequest hook inputs).
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