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

Method injectControlResponse

src/cli/structuredIO.ts:283–309  ·  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

281 * callback is aborted via the signal — otherwise the callback hangs.
282 */
283 injectControlResponse(response: SDKControlResponse): void {
284 const requestId = response.response?.request_id
285 if (!requestId) return
286 const request = this.pendingRequests.get(requestId)
287 if (!request) return
288 this.trackResolvedToolUseId(request.request)
289 this.pendingRequests.delete(requestId)
290 // Cancel the SDK consumer's canUseTool callback — the bridge won.
291 void this.write({
292 type: 'control_cancel_request',
293 request_id: requestId,
294 })
295 if (response.response.subtype === 'error') {
296 request.reject(new Error(response.response.error))
297 } else {
298 const result = response.response.response
299 if (request.schema) {
300 try {
301 request.resolve(request.schema.parse(result))
302 } catch (error) {
303 request.reject(error)
304 }
305 } else {
306 request.resolve({})
307 }
308 }
309 }
310
311 /**
312 * Register a callback invoked whenever a can_use_tool control_request

Callers 1

onPermissionResponseFunction · 0.80

Calls 7

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

Tested by

no test coverage detected