Commit dcd51c9
authored
#227
Fixes zod issues returned by cli subprocess transport - example now runs
correctly to completion:
```
============================================================
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
============================================================
📝 Sending query to Claude...
📨 Receiving response...
💬 Claude: I'll help you with these tasks. Let me execute them in sequence.
💬 Claude: Now I'll create a simple Python hello world script:
🔧 Tool Permission Request: Write
Input: {
"file_path": "/Users/vimota/code/claude-agent-sdk-python/hello.py",
"content": "#!/usr/bin/env python3\n\nprint(\"Hello, World!\")\n"
}
⚠️ Redirecting write from /Users/vimota/code/claude-agent-sdk-python/hello.py to ./safe_output/hello.py
💬 Claude: Now let's run the script:
🔧 Tool Permission Request: Bash
Input: {
"command": "python hello.py",
"description": "Run hello.py script"
}
✅ Allowing bash command: python hello.py
💬 Claude: Let me check where the file was created:
💬 Claude: I see the file was created in the `safe_output` directory. Let me run it from there:
🔧 Tool Permission Request: Bash
Input: {
"command": "python ./safe_output/hello.py",
"description": "Run hello.py from safe_output"
}
✅ Allowing bash command: python ./safe_output/hello.py
💬 Claude: Perfect! All tasks completed successfully:
1. **Listed files** - The directory contains a Python SDK project with source code in `src/`, tests, examples, and configuration files.
2. **Created hello.py** - A simple Python script was created at `./safe_output/hello.py` with a basic "Hello, World!" print statement.
3. **Ran the script** - The script executed successfully and printed "Hello, World!" to the console.
Note: The file was created in the `safe_output/` subdirectory rather than the root directory.
✅ Task completed!
Duration: 31158ms
Cost: $0.0736
Messages processed: 18
============================================================
Tool Usage Summary
============================================================
1. Tool: Write
Input: {
"file_path": "/Users/vimota/code/claude-agent-sdk-python/hello.py",
"content": "#!/usr/bin/env python3\n\nprint(\"Hello, World!\")\n"
}
Suggestions: [{'type': 'setMode', 'mode': 'acceptEdits', 'destination': 'session'}]
2. Tool: Bash
Input: {
"command": "python hello.py",
"description": "Run hello.py script"
}
Suggestions: [{'type': 'addRules', 'rules': [{'toolName': 'Bash', 'ruleContent': 'python:*'}], 'behavior': 'allow', 'destination': 'localSettings'}]
3. Tool: Bash
Input: {
"command": "python ./safe_output/hello.py",
"description": "Run hello.py from safe_output"
}
Suggestions: [{'type': 'addRules', 'rules': [{'toolName': 'Bash', 'ruleContent': 'python:*'}], 'behavior': 'allow', 'destination': 'localSettings'}]
```
1 parent 71a85ac commit dcd51c9
1 file changed
+9
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
| 198 | + | |
198 | 199 | | |
199 | 200 | | |
200 | 201 | | |
| |||
213 | 214 | | |
214 | 215 | | |
215 | 216 | | |
216 | | - | |
217 | | - | |
218 | | - | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
219 | 225 | | |
220 | 226 | | |
221 | 227 | | |
| |||
0 commit comments