Skip to content

Conversation

@martydill
Copy link
Owner

No description provided.

This commit comprehensively fixes all identified bugs and compatibility gaps in the hooks implementation while maintaining the .flexorama directory naming.

Bugs Fixed:
- Fixed string-based "hooks" detection bug in parse_hook_config (removed content.contains check)
- Added executable validation for hook scripts in directories (Unix: chmod check, Windows: extension check)
- Improved Windows shell detection with PowerShell Core (pwsh) support, fallback to powershell/cmd
- Fixed unused hook responses for post-hooks by implementing proper response handling
- Fixed hook alias duplication issue by tracking unique hooks with HashSet
- Added overall 30-second timeout for hook execution per event

Claude Code Compatibility Added:
- All Claude Code event names supported: UserPromptSubmit, PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, PreCompact, Notification, PermissionRequest
- Claude Code settings.json format fully supported (.flexorama/settings.json)
- Claude Code JSON response format supported (decision, reason, continue, stopReason, suppressOutput)
- Claude Code payload structures implemented (session_id, timestamp, tool_name, tool_input/output)
- Legacy Flexorama event names maintained as aliases for backward compatibility
- Both response formats work (Claude Code and Flexorama legacy)

New Features:
- Added run_session_start() and run_subagent_stop() hook methods
- Smart shell detection: pwsh > powershell > cmd (Windows), bash > sh (Unix)
- Hook deduplication prevents same hook from running multiple times via aliases
- Comprehensive test coverage (13 tests covering all new features)

Tests Added:
- Claude Code event name compatibility
- Claude Code response format (decision/block, continue/false)
- Hook alias deduplication
- Claude settings.json parsing
- Shell detection validation
- Individual and overall timeout enforcement
- continue_on_error behavior
- All hook events enumeration

Documentation:
- Complete rewrite of CLAUDE_HOOKS.md
- Comprehensive migration guide from Claude Code
- Examples for all hook events
- Troubleshooting guide
- Best practices
- Feature comparison table

All tests pass (13/13). Code compiles successfully with only minor warnings.
Handle race condition where child process exits before stdin write completes.
This fixes test failures in run_pre_message_updates_message and run_pre_tool_aborts_on_action.

Changes:
- Explicitly drop stdin after writing to ensure pipe is closed
- Ignore BrokenPipe errors (child may exit quickly without reading stdin)
- This is safe because fast-executing hooks may not need stdin input

All 13 tests now pass successfully.
@martydill martydill merged commit e5852e5 into codex/implement-claude-code-style-hooks Jan 26, 2026
2 checks passed
@martydill martydill deleted the claude/analyze-hooks-bugs-o7OFP branch January 26, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants