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

Document hook type selection bug in /hooks commandBrowse files
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
Claude authored on Dec 19, 2025 parent 5211559 · commit 82ede6858cef
1 changed file+64 -0compared with 5211559
Ahook-selection-bug-issue.md
@@ -1,0 +1,64 @@
1+# Bug Report: /hooks command always selects PreToolUse on first attempt
2+
3+## Summary
4+
5+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.
6+
7+## Steps to Reproduce
8+
9+1. Open Claude Code
10+2. Type `/hooks` to open the hooks management interface
11+3. Navigate to create a new hook
12+4. 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`)
13+5. Press Enter to confirm selection
14+6. **Bug:** `PreToolUse` is selected instead of the highlighted option
15+
16+## Workaround
17+
18+1. Press Escape to cancel the selection
19+2. Re-enter the hook type selector
20+3. Scroll to desired hook type
21+4. Press Enter
22+5. **Result:** Correct hook type is now selected
23+
24+## Expected Behavior
25+
26+The 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+
30+This appears to be a **state synchronization issue** where:
31+
32+1. On first render of the hook type selector, the internal selected index is initialized to `0` (PreToolUse is the first item)
33+2. The visual highlight updates correctly when scrolling with arrow keys (the user sees a different item highlighted)
34+3. However, when pressing Enter, the handler reads from the internal state (which may still be `0`) rather than the current highlighted position
35+4. After pressing Escape and re-opening the selector, the state is properly synchronized
36+
37+### Potential Code Areas
38+
39+Based on similar issues and the CHANGELOG history, the fix likely involves one of these patterns:
40+
41+1. **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+
43+2. **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+
45+3. **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+
60+https://anthropic.slack.com/archives/C07VBSHV7EV/p1766159670734839?thread_ts=1766158844.979909&cid=C07VBSHV7EV
61+
62+## Labels
63+
64+`bug`, `hooks`, `ui`, `select-component`