MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / CancelRequestHandler

Function CancelRequestHandler

source code/hooks/useCancelRequest.ts:65–278  ·  view source on GitHub ↗
(props: CancelRequestHandlerProps)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

useAppStateStoreFunction · 0.85
useSetAppStateFunction · 0.85
useCommandQueueFunction · 0.85
useNotificationsFunction · 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

Tested by

no test coverage detected