Bug: When using /hooks to create a new hook, selecting a hook type (PreToolUse, PostToolUse, etc.) always selects PreToolUse on the first attempt, regardless of which option is visually highlighted. The selection works correctly after pressing Escape and trying again. This appears to be a state synchronization issue where the internal selection index is not properly synced with the visual highlight on first render. Includes: - Detailed reproduction steps - Root cause analysis - Related issues and CHANGELOG entries - Slack thread reference Slack: https://anthropic.slack.com/archives/C07VBSHV7EV/p1766159670734839?thread_ts=1766158844.979909&cid=C07VBSHV7EV
2.9 KiB
Bug Report: /hooks command always selects PreToolUse on first attempt
Summary
When using the /hooks command to create a new hook, the hook type selector always selects PreToolUse on the first attempt, regardless of which option the user scrolls to and selects with Enter. The selection works correctly on subsequent attempts after pressing Escape.
Steps to Reproduce
- Open Claude Code
- Type
/hooksto open the hooks management interface - Navigate to create a new hook
- When the hook type selector appears (showing PreToolUse, PostToolUse, Stop, UserPromptSubmit, etc.), scroll down using arrow keys to select a different hook type (e.g.,
PostToolUse) - Press Enter to confirm selection
- Bug:
PreToolUseis selected instead of the highlighted option
Workaround
- Press Escape to cancel the selection
- Re-enter the hook type selector
- Scroll to desired hook type
- Press Enter
- Result: Correct hook type is now selected
Expected Behavior
The hook type selector should select the option that is visually highlighted when the user presses Enter, on both first and subsequent attempts.
Root Cause Analysis
This appears to be a state synchronization issue where:
- On first render of the hook type selector, the internal selected index is initialized to
0(PreToolUse is the first item) - The visual highlight updates correctly when scrolling with arrow keys (the user sees a different item highlighted)
- However, when pressing Enter, the handler reads from the internal state (which may still be
0) rather than the current highlighted position - After pressing Escape and re-opening the selector, the state is properly synchronized
Potential Code Areas
Based on similar issues and the CHANGELOG history, the fix likely involves one of these patterns:
-
Initial state not synced: The selection state may need to be initialized differently, or there's a race condition between render and state initialization
-
Event handler reading stale state: The Enter key handler might be using a captured/stale reference to the selection index rather than the current value
-
Scroll handler not updating state: The arrow key navigation might only be updating the visual highlight without updating the underlying state that Enter reads from
Similar Fixed Issues
- CHANGELOG v2.0.35: "Fixed menu navigation getting stuck on items with empty string or other falsy values (e.g., in the
/hooksmenu)" - CHANGELOG v0.2.69: "Fixed UI glitches with improved Select component behavior"
- Issue #6674: Hook Navigation Infinite Loop on Duplicate Entries (related Select component issue)
Environment
- Reported on: Multiple environments
- Claude Code Version: Current latest
Slack Thread Reference
Labels
bug, hooks, ui, select-component