claude-agent-sdk-python icon indicating copy to clipboard operation
claude-agent-sdk-python copied to clipboard

Permission tool

Open kevincraft-toast opened this issue 1 year ago • 6 comments

Hello! I'm building my own workflows on top of Claude Code using this SDK. Some of these workflows require a human in the loop. Everything works Ok except for permission checks! I built an MCP server to handle permission checks. It pops up a prompt for a human to approve/deny. It works great, except the MCP tool call times out after 5 minutes. I can't always expect a human to respond within 5 minutes. It would be nice to either (A) configure the timeout for this particular tool (and possibly set it to infinite?), or (B) support permission handling another way, like via a new message type. I'd very much prefer the latter since it would support indefinite timelines and it seems like it would fit naturally into the conversation flow.

kevincraft-toast avatar Jul 28 '25 20:07 kevincraft-toast

+1 this is pretty critical to building a production system

raghavchandra123 avatar Oct 27 '25 14:10 raghavchandra123

Yep, we should be able to configure the permission mCP timeout as well as hook timeouts (I'm looking at you, PreToolUse)

Nthalk avatar Jan 06 '26 23:01 Nthalk

But now that it's 2026, I have low expectations of this being fixed. I have made my auto processes have a timeout for killing Claude code if we think a timeout is going to happen. Very annoying.

Nthalk avatar Jan 06 '26 23:01 Nthalk

+1 i encountered the same problem.

ychost avatar Jan 27 '26 12:01 ychost

+1 same problem in production

leegisang avatar Jan 27 '26 13:01 leegisang

This has been resolved with the addition of the can_use_tool callback on ClaudeAgentOptions (added in v0.1.29+). This is an async callback that gives you full programmatic control over permission decisions without the MCP tool timeout limitation:

async def my_permission_handler(tool_name: str, input: dict, context: ToolPermissionContext) -> PermissionResult:
    # Wait indefinitely for human approval - no 5-minute timeout
    approved = await get_human_approval(tool_name, input)
    if approved:
        return PermissionResultAllow()
    return PermissionResultDeny(reason="User denied")

options = ClaudeAgentOptions(
    can_use_tool=my_permission_handler,
    # ...
)

Additionally, PermissionRequest hook events provide another mechanism for permission handling with configurable timeouts.

Both approaches (A) and (B) from the original request are now addressed.


Generated by Claude Code

qing-ant avatar Apr 02 '26 14:04 qing-ant