You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature Request] Implement Fine-Grained Tool Permissions for Agent Constraints #7514
Bug Description
I have a testing agent that is not supposed to modify the codebase. It has no Write permission, but it bypasses using Bash (sed, cat, ...) to make writes. I have told it in its description many times to not modify the codebase, but it often does so regardless. A suggestion to improve on it: can the agent be given finer-grade permissions via the tools, e.g. tools: Bash(go test:*) as opposed to just tools: Bash ?
Hey, this is a great point and a feature I'd also love to see implemented. I did some digging through the documentation provided, and it looks like you've found a gap between the main permission system and the subagent configuration.
Here's what I found:
The Current Situation
You're right that subagents seem to only accept whole tool names in their frontmatter. The en/docs/claude-code/sub-agents documentation shows examples like this:
It doesn't show the fine-grained syntax you're looking for.
However, the main permission system does support that exact syntax. In the en/docs/claude-code/iam documentation under "Tool-specific permission rules", it shows you can configure settings.json with rules like:
Bash(npm run test:*)
Bash(curl http://site.com/:*)
It seems the subagent tools: configuration just hasn't inherited this level of granularity yet.
Potential Workarounds
While we wait for this feature to be added, here are a couple of ideas that might help you lock down your testing agent.
1. Use Project-Level Permissions (settings.json)
Since subagents inherit permissions from the main session, you could define a restrictive deny list in your project's .claude/settings.json file. This would block the agent (and yourself, when using Claude) from running destructive commands.
For example, you could create a .claude/settings.json with:
The testing agent would be able to run go test, but if it tried to use sed or cat > file.txt, the main permission system would block it. The downside is this applies to the main agent too, not just the subagent.
2. Use a PreToolUse Hook (More Advanced)
A more powerful solution would be to use Claude Code hooks. You could create a PreToolUse hook that triggers on any Bash tool call. The hook script would receive the command Claude is trying to run and could decide whether to allow or block it.
Your .claude/settings.json would have something like this:
Then your validate_bash_command.py script could check the command. If it's a write command (sed, cat >, etc.), the script would sys.exit(2). According to the docs, exiting with code 2 blocks the tool call and feeds the stderr back to Claude as feedback. This would effectively teach it not to use those commands.
Ultimately, I think your suggestion is the best long-term solution. Having fine-grained permissions directly in the subagent definition makes the most sense for creating truly constrained, special-purpose agents.
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.
Activity
github-actions commentedon Sep 12, 2025
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
coygeek commentedon Sep 13, 2025
Hey, this is a great point and a feature I'd also love to see implemented. I did some digging through the documentation provided, and it looks like you've found a gap between the main permission system and the subagent configuration.
Here's what I found:
The Current Situation
You're right that subagents seem to only accept whole tool names in their frontmatter. The
en/docs/claude-code/sub-agentsdocumentation shows examples like this:It doesn't show the fine-grained syntax you're looking for.
However, the main permission system does support that exact syntax. In the
en/docs/claude-code/iamdocumentation under "Tool-specific permission rules", it shows you can configuresettings.jsonwith rules like:Bash(npm run test:*)Bash(curl http://site.com/:*)It seems the subagent
tools:configuration just hasn't inherited this level of granularity yet.Potential Workarounds
While we wait for this feature to be added, here are a couple of ideas that might help you lock down your testing agent.
1. Use Project-Level Permissions (
settings.json)Since subagents inherit permissions from the main session, you could define a restrictive
denylist in your project's.claude/settings.jsonfile. This would block the agent (and yourself, when using Claude) from running destructive commands.For example, you could create a
.claude/settings.jsonwith:{ "permissions": { "allow": [ "Bash(go test:*)", "Bash(ls:*)" ], "deny": [ "Bash(sed:*)", "Bash(awk:*)", "Bash(rm:*)", "Bash(cat:*)", "Write", "Edit" ] } }The testing agent would be able to run
go test, but if it tried to usesedorcat > file.txt, the main permission system would block it. The downside is this applies to the main agent too, not just the subagent.2. Use a
PreToolUseHook (More Advanced)A more powerful solution would be to use Claude Code hooks. You could create a
PreToolUsehook that triggers on anyBashtool call. The hook script would receive the command Claude is trying to run and could decide whether to allow or block it.Your
.claude/settings.jsonwould have something like this:{ "hooks": { "PreToolUse": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/validate_bash_command.py" } ] } ] } }Then your
validate_bash_command.pyscript could check the command. If it's a write command (sed,cat >, etc.), the script wouldsys.exit(2). According to the docs, exiting with code 2 blocks the tool call and feeds thestderrback to Claude as feedback. This would effectively teach it not to use those commands.Ultimately, I think your suggestion is the best long-term solution. Having fine-grained permissions directly in the subagent definition makes the most sense for creating truly constrained, special-purpose agents.
+1 for this feature request
github-actions commentedon Dec 8, 2025
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
github-actions commentedon Jan 8, 2026
This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.
github-actions commentedon Jan 15, 2026
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.