spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / hook-selection-bug-issue.md
64 lines · 2.9 KBPreviewCodeRaw
1# Bug Report: /hooks command always selects PreToolUse on first attempt
2
3## Summary
4
5When 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.
6
7## Steps to Reproduce
8
91. Open Claude Code
102. Type `/hooks` to open the hooks management interface
113. Navigate to create a new hook
124. 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`)
135. Press Enter to confirm selection
146. **Bug:** `PreToolUse` is selected instead of the highlighted option
15
16## Workaround
17
181. Press Escape to cancel the selection
192. Re-enter the hook type selector
203. Scroll to desired hook type
214. Press Enter
225. **Result:** Correct hook type is now selected
23
24## Expected Behavior
25
26The hook type selector should select the option that is visually highlighted when the user presses Enter, on both first and subsequent attempts.
27
28## Root Cause Analysis
29
30This appears to be a **state synchronization issue** where:
31
321. On first render of the hook type selector, the internal selected index is initialized to `0` (PreToolUse is the first item)
332. The visual highlight updates correctly when scrolling with arrow keys (the user sees a different item highlighted)
343. However, when pressing Enter, the handler reads from the internal state (which may still be `0`) rather than the current highlighted position
354. After pressing Escape and re-opening the selector, the state is properly synchronized
36
37### Potential Code Areas
38
39Based on similar issues and the CHANGELOG history, the fix likely involves one of these patterns:
40
411. **Initial state not synced**: The selection state may need to be initialized differently, or there's a race condition between render and state initialization
42
432. **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
44
453. **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
46
47### Similar Fixed Issues
48
49- **CHANGELOG v2.0.35**: "Fixed menu navigation getting stuck on items with empty string or other falsy values (e.g., in the `/hooks` menu)"
50- **CHANGELOG v0.2.69**: "Fixed UI glitches with improved Select component behavior"
51- **Issue #6674**: Hook Navigation Infinite Loop on Duplicate Entries (related Select component issue)
52
53## Environment
54
55- Reported on: Multiple environments
56- Claude Code Version: Current latest
57
58## Slack Thread Reference
59
60https://anthropic.slack.com/archives/C07VBSHV7EV/p1766159670734839?thread_ts=1766158844.979909&cid=C07VBSHV7EV
61
62## Labels
63
64`bug`, `hooks`, `ui`, `select-component`