-
Notifications
You must be signed in to change notification settings - Fork 539
Add missing hook output fields to match TypeScript SDK #226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
bd31bc0 to
3cf6b56
Compare
bcherny
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @szwang for the stamp
szwang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! left a few minor questions and nonblocking ideas
src/claude_agent_sdk/types.py
Outdated
| stopReason: NotRequired[str] | ||
|
|
||
| # Decision fields | ||
| decision: NotRequired[Literal["approve", "block"]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this used for every hook specific output? It feels more intuitive to me as something pre-tool use but not sure of how it gets used beyond that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will stick with this since it's mirroring TS types, but we should revisit
| $job = Start-Job { python examples/hooks.py DecisionFields } | ||
| Wait-Job $job -Timeout 120 | Out-Null | ||
| Stop-Job $job | ||
| Receive-Job $job |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we actually running on Windows for test-examples? Since runs-on: ubuntu-latest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good catch
| "systemMessage": "⚠️ Command blocked by hook", | ||
| "hookSpecificOutput": { | ||
| "hookEventName": "PreToolUse", | ||
| "permissionDecision": "deny", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would love to better understand the difference between decision and permissionDecision
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decision and reason are actually deprecated, so it's a little confusing right now
Closes the gap between Python and TypeScript SDK hook output types by adding: - `reason` field for explaining decisions - `continue_` field for controlling execution flow - `suppressOutput` field for hiding stdout - `stopReason` field for stop explanations - `decision` now supports both "approve" and "block" (not just "block") - `AsyncHookJSONOutput` type for deferred hook execution - Proper typing for `hookSpecificOutput` with discriminated unions Also adds comprehensive examples and tests: - New examples in hooks.py demonstrating all new fields - Unit tests in test_tool_callbacks.py for new output types - E2E tests in e2e-tests/test_hooks.py with real API calls - CI integration in .github/workflows/test.yml 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Remove deprecated `decision: "approve"` in favor of `permissionDecision: "allow"` - Update `decision` type to only allow "block" (approve is deprecated) - Replace string assertions with JSON parsing in unit tests for robustness - Add HookJSONOutput type annotations to test hook functions - Rename test to match actual behavior (permission decision vs generic decision) - Update examples and documentation to use new permissionDecision API 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
d360a2b to
6d1c0d9
Compare
Closes the gap between Python and TypeScript SDK hook output types by adding:
reasonfield for explaining decisionscontinue_field for controlling execution flowsuppressOutputfield for hiding stdoutstopReasonfield for stop explanationsdecisionnow supports both "approve" and "block" (not just "block")AsyncHookJSONOutputtype for deferred hook executionhookSpecificOutputwith discriminated unionsAlso adds comprehensive examples and tests:
🤖 Generated with Claude Code