Skip to content

Can Use Tool is not workingΒ #227

@vimota

Description

@vimota

The example in tool_permission_callback.py doesn't seem to work on the latest version of Claude Agent SDK. You can see Claude continually say it's hitting permission issues.

Besides the example code, I'm running into the same issue when I try to use that functionality in a CLI.

============================================================
Tool Permission Callback Example
============================================================

This example demonstrates how to:
1. Allow/deny tools based on type
2. Modify tool inputs for safety
3. Log tool usage
4. Prompt for unknown tools
============================================================
Initializing SubprocessCLITransport with cli_path: None
Found Claude Code CLI binary at: /opt/homebrew/bin/claude

πŸ“ Sending query to Claude...

πŸ“¨ Receiving response...

πŸ’¬ Claude: I'll help you with these tasks. Let me create a todo list and then complete each step.

πŸ’¬ Claude: Great! I can see the current directory contains various Python files and project files. Now let me create the hello.py script.
Handling control request subtype: can_use_tool
Handling can_use_tool request

πŸ”§ Tool Permission Request: Write
   Input: {
  "file_path": "/Users/vimota/code/coplane/test/test-planar-app/hello.py",
  "content": "#!/usr/bin/env python3\n\nprint(\"Hello, World!\")\n"
}
   ⚠️  Redirecting write from /Users/vimota/code/coplane/test/test-planar-app/hello.py to ./safe_output/hello.py
Response: PermissionResultAllow(behavior='allow', updated_input={'file_path': './safe_output/hello.py', 'content': '#!/usr/bin/env python3\n\nprint("Hello, World!")\n'}, updated_permissions=None)

πŸ’¬ Claude: Let me check if the file already exists first:

πŸ’¬ Claude: The file doesn't exist. Let me try creating it again:
Handling control request subtype: can_use_tool
Handling can_use_tool request

πŸ”§ Tool Permission Request: Write
   Input: {
  "file_path": "/Users/vimota/code/coplane/test/test-planar-app/hello.py",
  "content": "#!/usr/bin/env python3\n\nprint(\"Hello, World!\")\n"
}
   ⚠️  Redirecting write from /Users/vimota/code/coplane/test/test-planar-app/hello.py to ./safe_output/hello.py
Response: PermissionResultAllow(behavior='allow', updated_input={'file_path': './safe_output/hello.py', 'content': '#!/usr/bin/env python3\n\nprint("Hello, World!")\n'}, updated_permissions=None)

πŸ’¬ Claude: It seems there's a race condition. Let me use bash to create the file instead:
Handling control request subtype: can_use_tool
Handling can_use_tool request

πŸ”§ Tool Permission Request: Bash
   Input: {
  "command": "cat > hello.py << 'EOF'\n#!/usr/bin/env python3\n\nprint(\"Hello, World!\")\nEOF",
  "description": "Create hello.py with Python hello world"
}
   βœ… Allowing bash command: cat > hello.py << 'EOF'
#!/usr/bin/env python3

print("Hello, World!")
EOF
Response: PermissionResultAllow(behavior='allow', updated_input=None, updated_permissions=None)

πŸ’¬ Claude: Let me try using the Write tool with a fresh approach. Let me first check the current timestamp:
Handling control request subtype: can_use_tool
Handling can_use_tool request

πŸ”§ Tool Permission Request: Bash
   Input: {
  "command": "touch hello.py && cat /dev/null > hello.py",
  "description": "Create empty hello.py file"
}
   βœ… Allowing bash command: touch hello.py && cat /dev/null > hello.py
Response: PermissionResultAllow(behavior='allow', updated_input=None, updated_permissions=None)

πŸ’¬ Claude: I'm encountering hook permission issues. Let me try a simpler approach with python directly:
Handling control request subtype: can_use_tool
Handling can_use_tool request

πŸ”§ Tool Permission Request: Bash
   Input: {
  "command": "python3 -c \"with open('hello.py', 'w') as f: f.write('#!/usr/bin/env python3\\n\\nprint(\\\"Hello, World!\\\")\\n')\"",
  "description": "Create hello.py using Python"
}
   βœ… Allowing bash command: python3 -c "with open('hello.py', 'w') as f: f.write('#!/usr/bin/env python3\n\nprint(\"Hello, World!\")\n')"
Response: PermissionResultAllow(behavior='allow', updated_input=None, updated_permissions=None)

πŸ’¬ Claude: I'm encountering hook permission issues when trying to create files. It appears your hooks configuration is blocking file creation operations. Could you please check your hooks configuration to allow file creation?

The hook seems to be configured incorrectly and is preventing me from creating the `hello.py` file. You may need to adjust your hooks settings to allow file write operations, or temporarily disable the hooks if they're not working as intended.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingduplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions