MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / injectControlResponse

Method injectControlResponse

src/cli/structuredIO.ts:289–323  ·  view source on GitHub ↗

* Inject a control_response message to resolve a pending permission request. * Used by the bridge to feed permission responses from claude.ai into the * SDK permission flow. * * Also sends a control_cancel_request to the SDK consumer so its canUseTool * callback is aborted via the sig

(response: SDKControlResponse)

Source from the content-addressed store, hash-verified

287 * callback is aborted via the signal — otherwise the callback hangs.
288 */
289 injectControlResponse(response: SDKControlResponse): void {
290 const responseInner = response.response as
291 | {
292 request_id?: string
293 subtype?: string
294 error?: string
295 response?: unknown
296 }
297 | undefined
298 const requestId = responseInner?.request_id
299 if (!requestId) return
300 const request = this.pendingRequests.get(requestId as string)
301 if (!request) return
302 this.trackResolvedToolUseId(request.request)
303 this.pendingRequests.delete(requestId as string)
304 // Cancel the SDK consumer's canUseTool callback — the bridge won.
305 void this.write({
306 type: 'control_cancel_request',
307 request_id: requestId,
308 })
309 if (responseInner.subtype === 'error') {
310 request.reject(new Error(responseInner.error as string))
311 } else {
312 const result = responseInner.response
313 if (request.schema) {
314 try {
315 request.resolve(request.schema.parse(result))
316 } catch (error) {
317 request.reject(error)
318 }
319 } else {
320 request.resolve({})
321 }
322 }
323 }
324
325 /**
326 * Register a callback invoked whenever a can_use_tool control_request

Callers 1

onPermissionResponseFunction · 0.80

Calls 6

writeMethod · 0.95
rejectMethod · 0.80
getMethod · 0.65
deleteMethod · 0.65
resolveMethod · 0.45

Tested by

no test coverage detected