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

Function deletePermissionRule

src/utils/permissions/permissions.ts:1329–1370  ·  view source on GitHub ↗
({
  rule,
  initialContext,
  setToolPermissionContext,
}: EditPermissionRuleArgs & { rule: PermissionRule })

Source from the content-addressed store, hash-verified

1327 * Delete a permission rule from the appropriate destination
1328 */
1329export async function deletePermissionRule({
1330 rule,
1331 initialContext,
1332 setToolPermissionContext,
1333}: EditPermissionRuleArgs & { rule: PermissionRule }): Promise<void> {
1334 if (
1335 rule.source === 'policySettings' ||
1336 rule.source === 'flagSettings' ||
1337 rule.source === 'command'
1338 ) {
1339 throw new Error('Cannot delete permission rules from read-only settings')
1340 }
1341
1342 const updatedContext = applyPermissionUpdate(initialContext, {
1343 type: 'removeRules',
1344 rules: [rule.ruleValue],
1345 behavior: rule.ruleBehavior,
1346 destination: rule.source as PermissionUpdateDestination,
1347 })
1348
1349 // Per-destination logic to delete the rule from settings
1350 const destination = rule.source
1351 switch (destination) {
1352 case 'localSettings':
1353 case 'userSettings':
1354 case 'projectSettings': {
1355 // Note: Typescript doesn't know that rule conforms to `PermissionRuleFromEditableSettings` even when we switch on `rule.source`
1356 deletePermissionRuleFromSettings(
1357 rule as PermissionRuleFromEditableSettings,
1358 )
1359 break
1360 }
1361 case 'cliArg':
1362 case 'session': {
1363 // No action needed for in-memory sources - not persisted to disk
1364 break
1365 }
1366 }
1367
1368 // Update React state with updated context
1369 setToolPermissionContext(updatedContext)
1370}
1371
1372/**
1373 * Helper to convert PermissionRule array to PermissionUpdate array

Callers 1

PermissionRuleListFunction · 0.85

Calls 3

applyPermissionUpdateFunction · 0.85
setToolPermissionContextFunction · 0.85

Tested by

no test coverage detected