claude-code-sdk-python/examples
kashyap murali 68f0d7aa7d
Some checks failed
Lint / lint (push) Has been cancelled
Test / test (3.10) (push) Has been cancelled
Test / test (3.11) (push) Has been cancelled
Test / test (3.12) (push) Has been cancelled
Test / test (3.13) (push) Has been cancelled
feat: Add tool permission and hook callbacks support (#143)
## Summary

Adds comprehensive support for tool permission callbacks and hook
callbacks to the Python SDK, enabling fine-grained control over tool
execution and custom event handling.

## Key Changes

- **Tool Permission Callbacks**: Control which tools Claude can use and
modify their inputs
  -  type with async support
  -  with suggestions from CLI
  -  for structured responses
  
- **Hook Callbacks**: React to events in the Claude workflow
  -  type for event handlers
  -  for conditional hook execution
  - Support for tool_use_start, tool_use_end events
  
- **Integration**: Full plumbing through ClaudeCodeOptions → Client →
Query
- **Examples**: Comprehensive example showing permission control
patterns
- **Tests**: Coverage for all callback scenarios

## Implementation Details

- Callbacks are registered during initialization phase
- Control protocol handles can_use_tool and hook_callback requests
- Backwards compatible with dict returns for tool permissions
- Proper error handling and type safety throughout

Builds on top of #139's control protocol implementation.

---------

Co-authored-by: Dickson Tsai <dickson@anthropic.com>
2025-09-03 10:16:11 -07:00
..
mcp_calculator.py feat: Add in-process SDK MCP server support (#142) 2025-09-03 08:29:32 -07:00
quick_start.py cost_usd -> total_cost_usd in example 2025-06-25 15:18:52 -04:00
streaming_mode.py Implement control protocol support for Python SDK (#139) 2025-09-01 23:04:22 -07:00
streaming_mode_ipython.py feat: Add in-process SDK MCP server support (#142) 2025-09-03 08:29:32 -07:00
streaming_mode_trio.py Make streaming implementation trio-compatible (#84) 2025-07-22 23:31:42 -07:00
tool_permission_callback.py feat: Add tool permission and hook callbacks support (#143) 2025-09-03 10:16:11 -07:00