MCPcopy
hub / github.com/codeaashu/claude-code / handleSetPermissionMode

Function handleSetPermissionMode

src/cli/print.ts:4568–4642  ·  view source on GitHub ↗
(
  request: { mode: InternalPermissionMode },
  requestId: string,
  toolPermissionContext: ToolPermissionContext,
  output: Stream<StdoutMessage>,
)

Source from the content-addressed store, hash-verified

4566}
4567
4568function handleSetPermissionMode(
4569 request: { mode: InternalPermissionMode },
4570 requestId: string,
4571 toolPermissionContext: ToolPermissionContext,
4572 output: Stream<StdoutMessage>,
4573): ToolPermissionContext {
4574 // Check if trying to switch to bypassPermissions mode
4575 if (request.mode === 'bypassPermissions') {
4576 if (isBypassPermissionsModeDisabled()) {
4577 output.enqueue({
4578 type: 'control_response',
4579 response: {
4580 subtype: 'error',
4581 request_id: requestId,
4582 error:
4583 'Cannot set permission mode to bypassPermissions because it is disabled by settings or configuration',
4584 },
4585 })
4586 return toolPermissionContext
4587 }
4588 if (!toolPermissionContext.isBypassPermissionsModeAvailable) {
4589 output.enqueue({
4590 type: 'control_response',
4591 response: {
4592 subtype: 'error',
4593 request_id: requestId,
4594 error:
4595 'Cannot set permission mode to bypassPermissions because the session was not launched with --dangerously-skip-permissions',
4596 },
4597 })
4598 return toolPermissionContext
4599 }
4600 }
4601
4602 // Check if trying to switch to auto mode without the classifier gate
4603 if (
4604 feature('TRANSCRIPT_CLASSIFIER') &&
4605 request.mode === 'auto' &&
4606 !isAutoModeGateEnabled()
4607 ) {
4608 const reason = getAutoModeUnavailableReason()
4609 output.enqueue({
4610 type: 'control_response',
4611 response: {
4612 subtype: 'error',
4613 request_id: requestId,
4614 error: reason
4615 ? `Cannot set permission mode to auto: ${getAutoModeUnavailableNotification(reason)}`
4616 : 'Cannot set permission mode to auto',
4617 },
4618 })
4619 return toolPermissionContext
4620 }
4621
4622 // Allow the mode switch
4623 output.enqueue({
4624 type: 'control_response',
4625 response: {

Callers 1

runHeadlessStreamingFunction · 0.85

Calls 7

featureFunction · 0.85
isAutoModeGateEnabledFunction · 0.85
transitionPermissionModeFunction · 0.85
enqueueMethod · 0.45

Tested by

no test coverage detected