Analyze Permissions
Purpose
Analyze accumulated permissions in settings.local.json and suggest smart wildcard patterns to consolidate into shared configuration. Reduces permission sprawl by replacing specific entries with safe wildcard patterns.
Arguments (parsed from user input)
- action: What to do -
analyze (default), apply, or cleanup
Example invocations:
/ai-analyze-permissions → analyze and suggest patterns
/ai-analyze-permissions apply → apply suggested patterns to shared config
/ai-analyze-permissions cleanup → just run the cleanup script
Process
Step 1: Read Current Permissions
Read these files:
- Project-local:
<project-root>/.claude/settings.local.json - accumulated "Always allow" permissions (per-project)
- Global:
~/.claude/settings.json - shared/base permissions across all projects
Note: settings.local.json is project-specific. Each repo has its own at <repo>/.claude/settings.local.json. The global ~/.claude/settings.json is shared across all projects.
Step 2: Analyze Patterns
For each entry in settings.local.json:
Check if already covered - Is there a wildcard in settings.json that covers this?
Bash(git commit -m "Fix bug") is covered by Bash(git commit:*)
Bash(curl https://api.example.com) is covered by Bash(curl:*)
Identify pattern opportunities - Group similar commands:
- Multiple
kubectl commands → suggest Bash(kubectl:*)
- Multiple
docker commands → suggest Bash(docker:*)
- Multiple WebFetch for same domain → suggest
WebFetch(https://example.com/*)
Decide global vs local - Where should the pattern live?
- Global (
~/.claude/settings.json): General-purpose tools used across projects (npx, python, docker compose, etc.)
- Local (
settings.local.json): Project-specific commands, or write operations you only want for that project (e.g., git push for a personal repo)
Assess safety - Consider if the pattern is safe for auto-approval:
- Read-only commands: Generally safe
- Commands with side effects: Flag for review
- Overly broad patterns: Warn about security implications
Step 3: Present Analysis
Output a structured report:
## Permission Analysis
### Settings Overview
- settings.local.json: X entries
- settings.json: Y entries (Z wildcards)
### Already Covered (can be removed)
These entries in settings.local.json are redundant:
| Entry | Covered by |
|-------|------------|
| Bash(git commit -m "...") | Bash(git commit:*) |
### Suggested New Patterns
These patterns would consolidate multiple specific entries:
| Pattern | Covers | Scope | Safety |
|---------|--------|-------|--------|
| Bash(kubectl:*) | 4 entries | global | Safe (read-heavy) |
| Bash(docker exec:*) | 3 entries | local | Review (can modify) |
### Uncategorized
These entries don't fit a pattern (one-offs):
- Bash(some-specific-command)
Step 4: Handle Actions
Based on the action argument:
analyze (default):
- Present the report
- Ask if user wants to apply suggestions
apply:
- For each suggested pattern, ask for confirmation
- Add approved global patterns to
~/.claude/settings.json by editing the permissions.allow array
- Add approved local patterns to
<project-root>/.claude/settings.json (project-level, not local)
- Run the cleanup script to remove now-redundant entries from
settings.local.json
cleanup:
- Run
<project-root>/.claude/skills/ai-analyze-permissions/scripts/cleanup-settings-local.sh
Step 5: Apply Patterns (if applying)
When adding patterns:
- Read the target settings file (
~/.claude/settings.json for global, <project-root>/.claude/settings.json for project)
- Add new entries to the
permissions.allow JSON array
- Write the updated JSON back (preserving all other fields)
- Run cleanup to remove now-redundant entries:
<project-root>/.claude/skills/ai-analyze-permissions/scripts/cleanup-settings-local.sh
Important: Adding patterns to settings.json never removes existing entries. The cleanup script only cleans settings.local.json. To clean settings.json itself, manually remove redundant entries.
Pattern Safety Guidelines
Safe to auto-approve (commonly needed):
Bash(npx:*), Bash(node:*), Bash(npm:*), Bash(pnpm:*) - JS/Node tooling
Bash(python:*), Bash(python3:*), Bash(pip:*) - Python tooling
Bash(cargo :*), Bash(cd :* && cargo:*) - Rust tooling
Bash(docker compose:*), Bash(docker ps:*) - Docker
Bash(kubectl get:*), Bash(kubectl describe:*) - K8s read operations
Bash(git:*) subcommands (add, commit, log, diff, etc.)
Bash(gh:*) read operations (pr view, issue list, api, etc.)
Bash(chmod:*), Bash(ln:*), Bash(wc:*), Bash(which:*) - basic utilities
Bash(ssh:*), Bash(tmux:*), Bash(bash:*), Bash(zsh:*) - shell/system
WebFetch(domain:*), WebSearch - web access
Require review (side effects):
Bash(kubectl delete:*), Bash(kubectl apply:*)
Bash(docker rm:*), Bash(docker exec:*)
Bash(aws s3 rm:*)
Bash(rm:*), Bash(mv:*)
Bash(git push:*) - consider keeping per-project in local settings
Never auto-approve:
Bash(sudo:*)
Bash(chmod 777:*)
- Patterns that could leak secrets
$ARGUMENTS
1---2name: analyze-permissions3description: Use when Claude Code permissions have accumulated in settings.local.json and you want to audit, consolidate, or clean up tool permission patterns.4---5
6
7# Analyze Permissions
8
9## Purpose
10
11Analyze accumulated permissions in `settings.local.json` and suggest smart wildcard patterns to consolidate into shared configuration. Reduces permission sprawl by replacing specific entries with safe wildcard patterns.
12
13## Arguments (parsed from user input)
14
15- **action**: What to do - `analyze` (default), `apply`, or `cleanup`
16
17Example invocations:
18
19- `/ai-analyze-permissions` → analyze and suggest patterns
20- `/ai-analyze-permissions apply` → apply suggested patterns to shared config
21- `/ai-analyze-permissions cleanup` → just run the cleanup script
22
23## Process
24
25### Step 1: Read Current Permissions
26
27Read these files:
28
291. **Project-local**: `<project-root>/.claude/settings.local.json` - accumulated "Always allow" permissions (per-project)
302. **Global**: `~/.claude/settings.json` - shared/base permissions across all projects
31
32Note: `settings.local.json` is project-specific. Each repo has its own at `<repo>/.claude/settings.local.json`. The global `~/.claude/settings.json` is shared across all projects.
33
34### Step 2: Analyze Patterns
35
36For each entry in `settings.local.json`:
37
381. **Check if already covered** - Is there a wildcard in `settings.json` that covers this?
39 - `Bash(git commit -m "Fix bug")` is covered by `Bash(git commit:*)`
40 - `Bash(curl https://api.example.com)` is covered by `Bash(curl:*)`
41
422. **Identify pattern opportunities** - Group similar commands:
43 - Multiple `kubectl` commands → suggest `Bash(kubectl:*)`
44 - Multiple `docker` commands → suggest `Bash(docker:*)`
45 - Multiple WebFetch for same domain → suggest `WebFetch(https://example.com/*)`
46
473. **Decide global vs local** - Where should the pattern live?
48 - **Global (`~/.claude/settings.json`)**: General-purpose tools used across projects (`npx`, `python`, `docker compose`, etc.)
49 - **Local (`settings.local.json`)**: Project-specific commands, or write operations you only want for that project (e.g., `git push` for a personal repo)
50
514. **Assess safety** - Consider if the pattern is safe for auto-approval:
52 - Read-only commands: Generally safe
53 - Commands with side effects: Flag for review
54 - Overly broad patterns: Warn about security implications
55
56### Step 3: Present Analysis
57
58Output a structured report:
59
60```markdown
61## Permission Analysis
62
63### Settings Overview
64- settings.local.json: X entries
65- settings.json: Y entries (Z wildcards)
66
67### Already Covered (can be removed)
68These entries in settings.local.json are redundant:
69
70| Entry | Covered by |
71|-------|------------|
72| Bash(git commit -m "...") | Bash(git commit:*) |
73
74### Suggested New Patterns
75These patterns would consolidate multiple specific entries:
76
77| Pattern | Covers | Scope | Safety |
78|---------|--------|-------|--------|
79| Bash(kubectl:*) | 4 entries | global | Safe (read-heavy) |
80| Bash(docker exec:*) | 3 entries | local | Review (can modify) |
81
82### Uncategorized
83These entries don't fit a pattern (one-offs):
84
85- Bash(some-specific-command)
86```
87
88### Step 4: Handle Actions
89
90Based on the action argument:
91
92**analyze (default):**
93
94- Present the report
95- Ask if user wants to apply suggestions
96
97**apply:**
98
99- For each suggested pattern, ask for confirmation
100- Add approved global patterns to `~/.claude/settings.json` by editing the `permissions.allow` array
101- Add approved local patterns to `<project-root>/.claude/settings.json` (project-level, not local)
102- Run the cleanup script to remove now-redundant entries from `settings.local.json`
103
104**cleanup:**
105
106- Run `<project-root>/.claude/skills/ai-analyze-permissions/scripts/cleanup-settings-local.sh`
107
108### Step 5: Apply Patterns (if applying)
109
110When adding patterns:
111
1121. Read the target settings file (`~/.claude/settings.json` for global, `<project-root>/.claude/settings.json` for project)
1132. Add new entries to the `permissions.allow` JSON array
1143. Write the updated JSON back (preserving all other fields)
1154. Run cleanup to remove now-redundant entries: `<project-root>/.claude/skills/ai-analyze-permissions/scripts/cleanup-settings-local.sh`
116
117**Important**: Adding patterns to `settings.json` never removes existing entries. The cleanup script only cleans `settings.local.json`. To clean `settings.json` itself, manually remove redundant entries.
118
119## Pattern Safety Guidelines
120
121**Safe to auto-approve (commonly needed):**
122
123- `Bash(npx:*)`, `Bash(node:*)`, `Bash(npm:*)`, `Bash(pnpm:*)` - JS/Node tooling
124- `Bash(python:*)`, `Bash(python3:*)`, `Bash(pip:*)` - Python tooling
125- `Bash(cargo :*)`, `Bash(cd :* && cargo:*)` - Rust tooling
126- `Bash(docker compose:*)`, `Bash(docker ps:*)` - Docker
127- `Bash(kubectl get:*)`, `Bash(kubectl describe:*)` - K8s read operations
128- `Bash(git:*)` subcommands (add, commit, log, diff, etc.)
129- `Bash(gh:*)` read operations (pr view, issue list, api, etc.)
130- `Bash(chmod:*)`, `Bash(ln:*)`, `Bash(wc:*)`, `Bash(which:*)` - basic utilities
131- `Bash(ssh:*)`, `Bash(tmux:*)`, `Bash(bash:*)`, `Bash(zsh:*)` - shell/system
132- `WebFetch(domain:*)`, `WebSearch` - web access
133
134**Require review (side effects):**
135
136- `Bash(kubectl delete:*)`, `Bash(kubectl apply:*)`
137- `Bash(docker rm:*)`, `Bash(docker exec:*)`
138- `Bash(aws s3 rm:*)`
139- `Bash(rm:*)`, `Bash(mv:*)`
140- `Bash(git push:*)` - consider keeping per-project in local settings
141
142**Never auto-approve:**
143
144- `Bash(sudo:*)`
145- `Bash(chmod 777:*)`
146- Patterns that could leak secrets
147
148$ARGUMENTS