[BUG] --allowedTools no working reliably
Environment
- Platform (select one):
- [x] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [ ] Other: <!-- specify -->
- Claude CLI version: 0.2.49
- Operating System: Windows (Windows Server 2022 Datacenter)
- Terminal: WSL2
Bug Description
I am trying to run Claude Code from a script using a command like claude -p "test the application and fix any errors you encounter" --allowedTools "Bash(dotnet:*)" Edit.
Claude Code will always reply that it needs permissions for the Edit tool, when it encounters an error. When prompting Claude Code to simply edit a file with the same --allowedTools specification it can edit files.
Steps to Reproduce
- Open WSL terminal in a .NET project
- Prompt it something like
claude -p "test the application and fix any errors you encounter" --allowedTools "Bash(dotnet:*)" Edit - It runs the tests and then you get a reply that it needs permissions to edit files (if it encounters errors)
- Prompt something like
claude -p "Check which files you have access to and give me list of the files' names. Then write 'test' at the end of README.md. If you require permissions stop your task and reply with a message explaining what permissions you need." --allowedTools Edit - Result: Claude Code can execute Bash (ls) and edit the file.
Expected Behavior
I would expect Claude Code to work the same in interactive mode and non-interactive mode, i.e. either use the allowedTools as defined in the project's claude config or correctly apply the --allowedTools flag with its parameters.
When using --allowedTools I expect Claude Code to use all tools defined with the command.
Actual Behavior
Claude Code cannot use all tools that were defined with --allowedTools
Additional Context
I'm running Claude Code in WSL on a virtual machine.
I played around with different prompts and different --allowedTools configurations. I could not find an explanation as to why this happens. When giving Claude Code a task like claude -p "Write 'hello' to README.md" --allowedTools Edit it worked. The same when I used a prompt that required it to run a bash command like "ls" and then edit a file.
I also added more allowed tools to the prompt and it still worked. Somehow, it failed once the prompt got a bit more complex, i.e. run "dotnet test" and then, if there are error during the build, editing files.
19 Comments
Can repro this as well, and can also confirm that
claude -p "Write 'hello' to README.md" --allowedTools EditDOES seem to work.Reproing on a Mac talking to Bedrock.
0.2.49 (Claude Code)Maybe it has nothing to do with the prompt, but more that
--allowedToolsis not accepting a list properly? Or it's not working with--printmode specifically?I tried providing the arguments a few different ways like
--allowedTools X --allowedTools Yand still didn't work.Ok I figured it out. The docs are wrong.
https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview#automate-ci-and-infra-workflows
but actually if you look at
claude --helpyou can see the correct format is:--allowedTools <tools> Comma-separated list of tool names to allow (e.g. "Bash(git*),Edit,Replace")e.g.
claude -p "update the README with the latest changes" --allowedTools "Bash(git diff:*),Bash(git log:*),Edit"Fix incoming
@maschwenk You are right. I tested my workflow with
--allowedTools "Bash(dotnet:*),[...some other tools...],Edit"and it worked fine. Thanks for your help!@bcherny Thanks for your quick response!
@bcherny Awesome! Just also noting using
--printmode in CI makes it super hard to understand when permissions are failing. It'll say "I had permissions issues doing X" but it doesn't really call out what command it ran so it's really hard to build the--allowedToolslist. I've tried adding things likeor
but never works
Fixed in the latest!
@maschwenk mind commenting on https://github.com/anthropics/claude-code/issues/365?
@bcherny For sure. Can you clarify exactly what you changed here though? Did you update the docs to match the code? Or change the code to match the docs?
@bcherny This is still an issue in 0.2.53. Still getting permission issues when I run Claude Code with the following. It seems to work most of the time, but about 20% of the time it will say it doesn't have access to write or commit/push.
Seems like doing "--allowedTools Bash Edit Replace" and not specifying the bash command works
Really confused, because people are throwing around
Edit, andWrite, but if you look at the list of tools, it's these:!Image
Sorry to hijack this, but is it possible to grant permission to use MCPs this way?
Yes, you can add MCPs to the allowedTools. However, you have to provide the whole MCP function name in this format:
mcp__{your-MCP-server-name}__{MCP-function-name}, e.g.mcp__perplexity__search.your-MCP-server-namewould be the name provided to Claude Code when you added the MCP server.Note: From my experience, you have to add each MCP function separately.
mcp_perplexity:*ormcp_perplexity__:*or similar variations did not work for me.@bcherny this seems to be still an issue on
0.2.90 (Claude Code)And I'd like to echo the confusion from @Connoropolous. The tool name isn't what's written there but without "Tool" suffix. So how to read that?
I've tried
--allowedTools "AgentTool" "BatchTool",--allowedTools AgentTool,BatchTool,--allowedTools "AgentTool,BatchTool",--allowedTools "AgentTool BatchTool", and--allowedTools AgentTool BatchTooland none of them are working.I can confirm they aren't doing anything by using
--output-format stream-jsonbecause theinitmessage prints out the list of tools and no matter what I do the list of initialized tools is unchanged.(Note that AgentTool and BatchTool are just placeholder examples. I've also tried removing them and replacing with
mcp__alpaca__get_account_infowhich I know works because I can use the tool when I run Claude Code in interactive mode)From @TomDigitalDavid
your-MCP-server-name would be the name provided to Claude Code when you added the MCP server.
Note: From my experience, you have to add each MCP function separately. mcp_perplexity: or mcp_perplexity__: or similar variations did not work for me.
Would it be possible to update claude code to allow to configure all the functions of an mcp server at once in allowed tools? For example by just specifying:
mcp__{your-MCP-server-name}?I have some experience. Take a look at the following:
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.