MCPcopy Index your code
hub / github.com/codeaashu/claude-code / CancelRequestHandler

Function CancelRequestHandler

src/hooks/useCancelRequest.ts:63–276  ·  view source on GitHub ↗
(props: CancelRequestHandlerProps)

Source from the content-addressed store, hash-verified

61 * Renders null but registers the 'chat:cancel' keybinding handler.
62 */
63export function CancelRequestHandler(props: CancelRequestHandlerProps): null {
64 const {
65 setToolUseConfirmQueue,
66 onCancel,
67 onAgentsKilled,
68 isMessageSelectorVisible,
69 screen,
70 abortSignal,
71 popCommandFromQueue,
72 vimMode,
73 isLocalJSXCommand,
74 isSearchingHistory,
75 isHelpOpen,
76 inputMode,
77 inputValue,
78 streamMode,
79 } = props
80 const store = useAppStateStore()
81 const setAppState = useSetAppState()
82 const queuedCommandsLength = useCommandQueue().length
83 const { addNotification, removeNotification } = useNotifications()
84 const lastKillAgentsPressRef = useRef<number>(0)
85 const viewSelectionMode = useAppState(s => s.viewSelectionMode)
86
87 const handleCancel = useCallback(() => {
88 const cancelProps = {
89 source:
90 'escape' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
91 streamMode:
92 streamMode as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
93 }
94
95 // Priority 1: If there's an active task running, cancel it first
96 // This takes precedence over queue management so users can always interrupt Claude
97 if (abortSignal !== undefined && !abortSignal.aborted) {
98 logEvent('tengu_cancel', cancelProps)
99 setToolUseConfirmQueue(() => [])
100 onCancel()
101 return
102 }
103
104 // Priority 2: Pop queue when Claude is idle (no running task to cancel)
105 if (hasCommandsInQueue()) {
106 if (popCommandFromQueue) {
107 popCommandFromQueue()
108 return
109 }
110 }
111
112 // Fallback: nothing to cancel or pop (shouldn't reach here if isActive is correct)
113 logEvent('tengu_cancel', cancelProps)
114 setToolUseConfirmQueue(() => [])
115 onCancel()
116 }, [
117 abortSignal,
118 popCommandFromQueue,
119 setToolUseConfirmQueue,
120 onCancel,

Callers

nothing calls this directly

Calls 15

useAppStateStoreFunction · 0.85
useSetAppStateFunction · 0.85
useCommandQueueFunction · 0.85
useAppStateFunction · 0.85
logEventFunction · 0.85
hasCommandsInQueueFunction · 0.85
useIsOverlayActiveFunction · 0.85
isVimModeEnabledFunction · 0.85
useKeybindingFunction · 0.85
killAllRunningAgentTasksFunction · 0.85
markAgentsNotifiedFunction · 0.85
emitTaskTerminatedSdkFunction · 0.85

Tested by

no test coverage detected