Skip to Content
InternalsReact HooksReact Hooks

React Hooks

Source: src/hooks/ (87+ hooks)

Overview

Claude Code uses 87+ custom React hooks to encapsulate business logic, UI state, and side effects. Hooks are organized by function.

Input & History

HookPurpose
useArrowKeyHistoryNavigate input history with arrow keys
useInputBufferManage text input buffer
useHistorySearchSearch through command history

Tool Interaction

HookPurpose
useCanUseToolCheck tool permission status
useCancelRequestCancel in-flight AI requests

UI & Navigation

HookPurpose
useGlobalKeybindingsRegister global keyboard shortcuts
useCommandKeybindingsCommand-specific shortcuts
useDiffInIDEOpen diffs in external IDE
useIdeIntegrationIDE connection management

Session & Lifecycle

HookPurpose
useExitOnCtrlCDHandle Ctrl+C/D exit sequences

Notifications (hooks/notifs/)

18 notification hooks for different event types:

  • Tool execution notifications
  • Error notifications
  • Background task completion
  • Permission request notifications

Tool Permissions (hooks/toolPermission/)

Permission management hooks:

  • Permission state tracking
  • User approval prompts
  • Permission caching
  • Policy enforcement

Ink-specific Hooks (ink/hooks/)

10 hooks specific to the terminal UI:

  • Focus management
  • Stdin/stdout access
  • Cursor tracking
  • Component lifecycle

Deep Dive

  • Input Hooks — useInputBuffer, useArrowKeyHistory, useHistorySearch internals and keystroke processing
  • Permission Hooks — useCanUseTool, useToolPermission, and permission state management
  • Notification Hooks — 18 notification hooks, event type routing, and display lifecycle
Last updated on