claude-code - 💡(How to fix) Fix [FEATURE] UserInputChange hook — real-time input buffer events for live prompt tooling [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#48294Fetched 2026-04-16 07:03:50
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
labeled ×3

Error Message

Warn in real time when a prompt is likely too vague, missing file context, or doesn't match expected patterns (e.g. "you may want to @-mention a file"). Reduces the round-trip of submitting an underspecified prompt. Power custom autocomplete UIs — ticket IDs from Linear/Jira, function names from the current file, recent error strings from logs — surfaced as the user types.

Code Example

{
  "hook_event_name": "UserInputChange",
  "session_id": "abc123",
  "input": "how do I refcator this functon",
  "cursor_position": 30,
  "change_type": "insert"
}

---

{
  "suggestion": "how do I refactor this function",
  "annotation": "Did you mean: refactor, function?",
  "block": false
}

---

"UserInputChange": {
  "command": "~/.claude/hooks/input-watch.sh",
  "debounce_ms": 500
}

---

"UserInputChange": {
  "command": "~/.claude/hooks/input-watch.sh",
  "trigger": "word"
}

---

"UserInputChange": {
  "command": "~/.claude/hooks/input-watch.sh",
  "trigger": "debounce",
  "debounce_ms": 300
}
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • This is a single feature request (not multiple features)

Problem Statement

Claude Code's hook system covers the full session lifecycle — but there is a gap between session start and prompt submission: the moment the user is actively composing a prompt.

The existing UserPromptSubmit hook fires only after the user presses Enter. There is no hook that fires while the user is typing. This gap prevents an entire class of real-time input tooling that would otherwise be straightforward to implement.

Related prior request #11550 (closed) was scoped to pre-transmission preprocessing for privacy/sanitization. This request is distinct: it targets real-time, in-session input feedback while the prompt is being composed.

Proposed Feature

A new hook event: UserInputChange

Fires while the user is composing a prompt in the TUI input field, delivering the current input buffer contents to a user-defined handler.

Payload (stdin JSON)

{
  "hook_event_name": "UserInputChange",
  "session_id": "abc123",
  "input": "how do I refcator this functon",
  "cursor_position": 30,
  "change_type": "insert"
}

Handler output (stdout)

The hook can return structured JSON to influence the TUI:

{
  "suggestion": "how do I refactor this function",
  "annotation": "Did you mean: refactor, function?",
  "block": false
}

Implementation Options

Three delivery modes — pick one or make it configurable:

Option A — Debounced (recommended)

Fire after N milliseconds of typing inactivity. Default: 500ms, configurable.

"UserInputChange": {
  "command": "~/.claude/hooks/input-watch.sh",
  "debounce_ms": 500
}

Tradeoffs: Low overhead, feels natural, adequate for most use cases. Won't fire mid-word.


Option B — Per-word

Fire on each whitespace/punctuation boundary.

"UserInputChange": {
  "command": "~/.claude/hooks/input-watch.sh",
  "trigger": "word"
}

Tradeoffs: Natural breakpoints for NLP-based tools. More frequent than debounce but bounded by word rate.


Option C — Configurable (most flexible)

Expose trigger: "debounce" | "word" | "keystroke" and let users choose. Default to debounce to avoid performance issues.

"UserInputChange": {
  "command": "~/.claude/hooks/input-watch.sh",
  "trigger": "debounce",
  "debounce_ms": 300
}

Tradeoffs: Maximum flexibility. keystroke mode should be opt-in with a performance warning in docs.


Use Cases

1. Autocorrect / spell correction

Catch and suggest fixes for typos before submit. Technical terms and code identifiers can be allowlisted. The UserPromptSubmit hook can handle it post-submit, but real-time feedback is significantly better UX.

2. Live token / character counting

Display a running token estimate in an annotation as the user types. Helps users who are cost-conscious or working near context limits craft appropriately-sized prompts.

3. Sensitive data detection

Flag API keys, passwords, PII, or internal hostnames as they're typed — before they ever reach the network. Earlier than UserPromptSubmit and without requiring the user to submit first.

4. Prompt template expansion

Detect shorthand triggers (!debug, !pr, !explain) and expand them to full prompt templates inline, similar to text expanders — but context-aware and project-specific.

5. Live prompt quality feedback

Warn in real time when a prompt is likely too vague, missing file context, or doesn't match expected patterns (e.g. "you may want to @-mention a file"). Reduces the round-trip of submitting an underspecified prompt.

6. Dynamic autocomplete beyond / and @

Power custom autocomplete UIs — ticket IDs from Linear/Jira, function names from the current file, recent error strings from logs — surfaced as the user types.

7. Input history and fuzzy search

Build richer prompt history UX: fuzzy-search previous prompts as the user types, surface similar past prompts as suggestions.

8. Accessibility / input assistance

Assistive tools for users who benefit from real-time rewriting, word prediction, or input normalization.


Why this fits the existing hook architecture

  • UserPromptSubmit already establishes that hooks can intercept user-generated content
  • This is the natural earlier-in-lifecycle companion to that event
  • It follows the same stdin JSON / stdout JSON pattern
  • Debounced delivery means it doesn't require changes to the per-keystroke render path
  • Handlers are user-supplied scripts — Anthropic doesn't need to ship any autocorrect logic itself

Priority

Medium — enables a class of tooling that currently has no viable native path.

Feature Category

Hooks / developer extensibility

extent analysis

TL;DR

Implement a new UserInputChange hook that fires while the user is composing a prompt, delivering the current input buffer contents to a user-defined handler, with options for debounced, per-word, or configurable delivery modes.

Guidance

  • To address the gap in the session lifecycle, introduce a new hook event UserInputChange that captures user input in real-time.
  • Define the payload structure for the UserInputChange event, including session_id, input, cursor_position, and change_type.
  • Determine the optimal delivery mode (debounced, per-word, or configurable) based on performance and use case requirements.
  • Develop a user-defined handler that can process the UserInputChange event and return structured JSON to influence the TUI.

Example

{
  "hook_event_name": "UserInputChange",
  "session_id": "abc123",
  "input": "how do I refcator this functon",
  "cursor_position": 30,
  "change_type": "insert"
}

Notes

The implementation of the UserInputChange hook should consider performance implications, particularly when choosing the delivery mode. The debounced mode is recommended as it provides a balance between responsiveness and performance.

Recommendation

Apply the UserInputChange hook with a debounced delivery mode (default 500ms) to enable real-time input feedback while minimizing performance overhead. This approach allows for a flexible and efficient solution that can be adapted to various use cases.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [FEATURE] UserInputChange hook — real-time input buffer events for live prompt tooling [1 participants]