claude often ask me (too often) for bash command. How to prevent that behavior
Assistant
The behavior you're describing comes from Claude Code's permission system — by default it asks before running Bash commands that aren't on an allowlist. There are a few ways to reduce that, from quick to thorough:
1. Use the /fewer-permission-prompts skill (best first step)
This is built for exactly your problem. It scans your past transcripts for the read-only Bash commands you keep approving, then writes a tailored allowlist into your project's .claude/settings.json. Just type:
code
/fewer-permission-prompts
2. Add allow rules yourself
Permissions live in settings.json. You can pre-approve commands with patterns:
The pattern Bash(git diff:*) means "any git diff … invocation is auto-allowed." Note your global CLAUDE.md already mentions you have Bash(Rscript:*) allowlisted — that's this mechanism.
Tip: when Claude asks for a command, the approval dialog offers "Yes, and don't ask again for commands like this" — picking that adds the rule for you automatically.
3. Change the permission mode
/permissions — opens an interactive editor for allow/deny/ask rules.
--dangerously-skip-permissions (aka "yolo mode") — skips all prompts. Powerful but removes the safety net; only use in a sandbox/throwaway environment.
Plan mode (Shift+Tab) does the opposite — more cautious — so avoid that if prompts annoy you.
A couple of decisions are yours to make. Do you want me to set this up?
Where to write the allowlist:
Project (.claude/settings.json, checked into git) — shared with collaborators, scoped to this repo.
Project-local (.claude/settings.local.json, gitignored) — just you, this repo.
I'll scan your recent transcripts to find the read-only commands you keep approving, then build an allowlist. Let me start.
Assistant
Now let me extract and count the Bash command tokens from the 50 most-recent transcripts.
Assistant
Zero results — let me inspect the transcript structure first.
Assistant
The zsh quirk — unquoted $files isn't word-split. Let me use an array instead.
Assistant
6605 commands. Now let me parse leading command + subcommand tokens, stripping prefixes and handling pipes.
Assistant
The multiline R/bash scripts got split across lines, creating noise (if, for, }, etc.). Let me re-extract treating each command as one record and taking only its leading token.
Assistant
Let me check the rtk wrapper angle — the user's hooks rewrite commands to rtk <cmd>, which could defeat Claude Code's built-in auto-allow (since the leading token becomes rtk, not git/ls/rg).
Assistant
rtk wraps 71 commands and likely defeats the built-in auto-allow (the leading token becomes rtk, not git/rg). Let me see which subcommands flow through it.
Assistant
Clear picture now. Let me check the existing project settings and global allowlist to dedupe before writing.
Assistant
I have enough to decide, but I'm about to deviate from the skill's "skip auto-allowed commands" rule — and that deviation rests on a key piece of evidence. Let me sanity-check the reasoning before writing.
Assistant
Good catches. Let me properly dedupe against the full global allowlist before claiming anything.
Assistant
Important correction from that check: rg, cat, echo, and fdfind are already in your global allowlist — so my earlier "rg is the biggest win" was wrong. After deduping against global + local, only these read-only, frequently-used commands are genuinely uncovered:
#
Pattern
Count
Read-only?
Notes
1
Bash(cd:*)
364
✓
directory changes (often blocks compound cmds)
2
Bash(tail:*)
52
✓
file/log tailing
3
Bash(head:*)
26
✓
file previews
4
Bash(ps:*)
16
✓
process listing (bare; only was allowlisted)
Assistant
Done. Valid JSON, hooks and permissions.deny preserved.
What I added
Six read-only patterns to MiscMetabar/.claude/settings.json (permissions.allow):
I scanned your 50 most-recent transcripts (1,730 Bash invocations across all projects).
User
/permissions
permissions
User
/exit
exit
~/.claude/settings.json
If you tell me which scope you prefer and roughly what commands you're tired of approving (git, Rscript, file reads, etc.), I can run /fewer-permission-prompts or edit the settings file directly. Want me to go ahead?
Fewer Permission Prompts
Look through my transcripts' MCP and bash tool calls, and based on those, make a prioritized list of patterns that I should add to my permission allowlist to reduce permission prompts. Focus on read-only commands.
The format for permissions is: Bash(foo*), Bash(foo), Bash(foo bar *), mcp__slack__slack_read_thread, etc.
Then, add these to the project .claude/settings.json under permissions.allow.
Steps
Locate transcripts. Session transcripts live at ~/.claude/projects/<sanitized-cwd>/*.jsonl. Each line is a JSON object. Tool calls appear as assistant messages with message.content[] entries of type: "tool_use". The name field identifies the tool (e.g. "Bash", "mcp__slack__slack_read_thread"); for Bash, input.command is the shell string.
Scan the recent transcripts across the user's projects dir — not just the current project — so the allowlist reflects their actual usage. Cap the scan at a reasonable number of recent sessions (e.g. 50 most-recently-modified JSONL files) so this stays fast.
Extract tool-call frequencies.
For Bash calls: parse input.command, take the leading command token (handling sudo, timeout, pipes, &&, env-var prefixes). Record the command + first subcommand pair (e.g. git status, gh pr view, ls, cat).
For MCP calls: record the full tool name (e.g. mcp__slack__slack_read_thread).
Count occurrences across the scanned transcripts.
Filter to read-only. Keep only commands that don't mutate state. Examples of read-only: ls, cat, pwd, git status, git log, git diff, git show, git branch, rg, grep, find, head, tail, wc, file, which, echo, date, gh pr view, gh pr list, gh pr diff, gh issue view, gh issue list, gh run list, gh run view, gh api (GET), bun run typecheck, bun run lint, bun run test (for tests that don't mutate), docker ps, docker logs, kubectl get, kubectl describe, ps, top, df, du, env, printenv, any MCP tool with read/get/list/search/view in its name.
Drop anything that writes, deletes, renames, pushes, merges, installs, or runs a build/test that has side effects. When in doubt, leave it out.
Never allowlist a pattern that grants arbitrary code execution. A wildcard rule for any of these (e.g. Bash(python3:*)) is equivalent to allowing arbitrary code execution. This list is not exhaustive — apply the same rule to anything in the same category:
Interpreters: python/python3, node, bun, deno, ruby, perl, php, lua, etc.
Shells: bash, sh, zsh, fish, eval, exec, ssh, etc.
Package runners: npx, bunx, uvx, uv run, etc.
Task-runner wildcards: npm run *, yarn run *, pnpm run *, bun run *, make *, just *, cargo run *, go run *, etc. — an exact Bash(bun run typecheck) is fine, Bash(bun run *) is not
gh api *, docker run/exec, kubectl exec, sudo, and similar
Drop commands Claude Code already auto-allows. These don't need an allowlist entry — they never prompt. If you see any of these in the transcripts, skip them; don't suggest them to the user.
Pick the pattern form. Use the narrowest pattern that still covers the observed usage:
If the user runs many variants (git log, git log --oneline, git log main..HEAD): use Bash(git log *) — note the space before *, which is required for prefix matching to work correctly.
If a single exact invocation is common: use Bash(foo) with no wildcard.
For MCP: use the full tool name verbatim (no wildcard needed; they're already specific).
Never widen a pattern to the point that it conflicts with the rules above (no arbitrary code execution, no mutation/side effects).
Prioritize. Rank by count descending. Drop anything that appeared fewer than ~3 times — not worth the allowlist entry. Cap the list at the top ~20 so the user can skim it.
Present the prioritized list to the user as a markdown table with columns: rank, pattern, count, one-line description. Example:
#
Pattern
Count
Notes
1
Bash(git status *)
142
repo status checks
2
Bash(gh pr view *)
87
PR inspection
3
mcp__slack__slack_read_thread
54
Slack thread reads
Merge into .claude/settings.json in the current project (not ~/.claude/settings.json, not .claude/settings.local.json). Create the file if it doesn't exist. Preserve existing keys and existing entries in permissions.allow; de-duplicate against what's already there; don't remove anything; don't reorder unrelated fields.
Report back. Tell the user what you added (count + a few examples), what was already in the allowlist, and what you skipped and why (e.g. "dropped rm and git push — not read-only; dropped cat/ls/git status — already auto-allowed, no rule needed").
Do not add anything to permissions.deny or permissions.ask. Do not touch any other settings field.
rtk ps
5
Bash(rtk rg:*)
—
✓
rg via the mandated rtk wrapper — your dominant search tool, but only rtk grep was covered
6
Bash(which:*)
3
✓
binary lookup
Everything else you run frequently is already covered (auto-allow + your global Bash(rg:*)/cat/grep/Rscript/R/cargo… + your local rtk * wrappers). I'm dropping: Rscript/python3/bash/awk (interpreters → arbitrary execution, and Rscript/python3/bash are already in your local allowlist anyway), mkdir/chmod/git add/air format (mutating), gh api/curl (can't safely wildcard).
Let me write these to the project .claude/settings.json, preserving the existing hooks and permissions.deny.
What was already covered (so I skipped it)
Global allowlist (~/.claude/settings.json) already has rg, cat, echo, fdfind, grep, ls, Rscript, R, cargo, air, sed, and the read-only git/gh subcommands. My first instinct was "add rg — 271 uses," but it's already there.
Your local allowlist (settings.local.json) already has all the rtk wrappers (rtk grep/ls/git/read/ps/find/wc/curl/proxy), plus python3, bash, air format, etc.
What I deliberately dropped
Rscript, python3, bash, awk — interpreters = arbitrary code execution (and the first three are already allowlisted anyway).
mkdir, chmod, git add, air format — mutating.
gh api, curl — can't be safely wildcarded.
Two honesty notes
This won't fix most of your prompts. Your own config reveals the real culprits, and an allowlist of bare commands can't reach them:
Env-var prefixes — NOT_CRAN=true Rscript … and R_LIBS_USER=… Rscript … don't match Bash(Rscript:*) because the leading token isn't Rscript.
Redirections — your CLAUDE.md already notes 2>&1 breaks matching.
Compound chains — a && b needs every segment allowlisted.
These are structural; the genuinely effective lever for them is /permissions tuning or running in a sandboxed/yolo mode for trusted sessions.
Location divergence. The skill writes to the checked-in settings.json, but every other permission you have lives in the gitignored settings.local.json. So these six entries will be committed and shared with collaborators, unlike your existing prefs. If you'd rather keep them personal/local, say so and I'll move them to settings.local.json.
Source of truth: src/tools/BashTool/readOnlyValidation.ts (READONLY_COMMANDS, READONLY_NOARGS, READONLY_EXACT, COMMAND_ALLOWLIST) and src/utils/shell/readOnlyCommandValidation.ts (GIT_READ_ONLY_COMMANDS, GH_READ_ONLY_COMMANDS, DOCKER_READ_ONLY_COMMANDS, RIPGREP_READ_ONLY_COMMANDS, PYRIGHT_READ_ONLY_COMMANDS). If the user is in this repo and you're unsure whether a command is covered, grep these files rather than guessing.