Bug: Claude CLI non-interactive mode doesn't respect configured tool permissions

Status Fixed / completed
Maintainer reply ✓ Yes — rboyce-ant
Activity 13 comments · opened Mar 21, 2025 · closed Jun 20, 2025
💡 Likely answer: A maintainer (rboyce-ant, contributor) responded on this thread — see the highlighted reply below.

Bug: Claude CLI non-interactive mode doesn't respect configured tool permissions

Description

When using Claude CLI in non-interactive mode with the -p flag to run bash commands, Claude requests permission to use the Bash tool even though permissions are already configured. The same commands run without any permission issues in interactive mode.

Steps to Reproduce

  1. Configure Claude CLI with Bash tool permissions (already done, see config below)
  2. Run this command:

``
claude -p "npm run build and git commit and git push"
``

  1. Observe the error message: "I need permission to use the Bash tool to run these commands. Once granted, I'll build the project and commit the changes."

Expected Behavior

Claude should recognize the pre-configured Bash tool permissions and execute the commands without requesting additional permissions, just as it does in interactive mode.

Actual Behavior

Claude asks for permission to use the Bash tool despite the tool being listed in the allowed tools configuration.

Configuration

{
  "allowedTools": [
    "Bash",
    "Create",
    "Edit",
    "Read",
    "Write"
  ],
  "dontCrawlDirectory": false,
  "hasTrustDialogAccepted": "true",
  "hasCompletedProjectOnboarding": "true",
  "ignorePatterns": []
}

Additional Information

  • The exact same command sequence works perfectly when used in interactive mode
  • Command used: claude -p "npm run build and git commit and git push"
  • Claude CLI version: [Include your version here]
  • Operating System: [Include your OS here]
  • This issue started occurring after a recent update (within the last few updates)
  • The functionality used to work correctly in previous versions

Impact

This issue prevents using Claude CLI effectively in scripts or automated workflows where interactive mode isn't feasible.

View original on GitHub ↗

13 Comments

swellmkt · 1 year ago

$ claude -p "echo 'Hello World' > test.txt && cat test.txt"
I'll need permission to use the Bash tool to execute that command. Once granted, I'll create the test.txt file with "Hello World" and display its contents.

TomDigitalDavid · 1 year ago

I ran into the same issue a couple of days ago (see #563 )
As it turns out, Claude Code does not use the allowed tools as defined in the configs when running in non-interactive mode. You have to pass the allowed tools to the command with the --allowedTools flag followed by a comma separated list of your required tools - like so:
claude -p "npm run build and git commit and git push" --allowedTools "Bash(git:*),Edit"

swellmkt · 1 year ago

Legend @TomDigitalDavid that gets me going :) I always just did

claude config set hasCompletedProjectOnboarding true
claude config set hasTrustDialogAccepted true

claude config add allowedTools Bash
claude config add allowedTools Read
claude config add allowedTools Write
claude config add allowedTools Edit
claude config add allowedTools Create

GailElliott1990 · 1 year ago

I cannot get this to work. Trying to get a global config that will remove the endless interruptions.

rboyce-ant contributor · 1 year ago

Hi all, I've verified that permission rules .claude/settings.json are respected when running claude -p. Please ensure that your settings are configured properly: https://docs.anthropic.com/en/docs/claude-code/settings#settings-files

pyronaur · 1 year ago

@rboyce-ant This isn't working when not running in -p - claude keeps asking me for permission on every curl command it wants to run. I just want to let it cook!

majerr · 1 year ago

@rboyce-ant I'm still seeing this exactly as described by the OP. The issue is as described in https://github.com/anthropics/claude-code/issues/1188. Although .claude/settings.json is being read, permissions are ignored where patterns are used.

So this works:

{
  "permissions": {
    "allow": [
      "Bash"
    ]
  }
}

But this doesn't:

{
  "permissions": {
    "allow": [
      "Bash(*)"
    ]
  }
}
$ claude --version
1.0.40 (Claude Code)
craigdrayton · 1 year ago

@rboyce-ant I am finding similar results to the other reporters. Claude Code works fine for me in interactive mode, but in non-interactive mode:

 Bash(npm link)
  ⎿  Error: Claude requested permissions to use Bash, but you haven't granted it yet.
 Update(demos/hello/package.json)
  ⎿  Error: Claude requested permissions to use Edit, but you haven't granted it yet.
 Write(demos/hello/hello.md)
  ⎿  Error: Claude requested permissions to use Write, but you haven't granted it yet.
Update(demos/hello/package.json)
  ⎿  Error: Claude requested permissions to use MultiEdit, but you haven't granted it yet.

.claude\settings.local.json has:

{
  "permissions": {
    "allow": [
      "Read(*)",
      "Search(*)",
      "Edit(*)",
      "Write(*)",
      "MultiEdit(*)",
      ...
    ],
    "deny": []
  }
}
sidbharath · 1 year ago

I am still seeing the same issue as OP. In non-interactive mode:

This works
claude -p "create a file called add.py that adds two numbers" --output-format json --allowedTools Write

This doesn't work
claude -p "create a file called add.py that adds two numbers" --output-format json --allowedTools Write(/**)

craigdrayton · 1 year ago

@rboyce-ant can you please reopen this issue? There have been multiple independent reproductions of the issue since you closed it.

K3UL · 1 year ago
I am still seeing the same issue as OP. In non-interactive mode: This works claude -p "create a file called add.py that adds two numbers" --output-format json --allowedTools Write This doesn't work claude -p "create a file called add.py that adds two numbers" --output-format json --allowedTools Write(/**)

I am having the exact same issue, which prevents me from restricting where Claude Code can write. Just allowing Write seems a bit risky to me.

Definitely not fixed. But this specific case with path patterns is covered in #1188

DmacMcgreg · 1 year ago

MCP settings are also not respected. It picks up the global settings, but does not allow passing in mcpSettings.

github-actions[bot] · 1 year ago

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.