Allow configuring protected directories in bypass permissions mode
Problem
When using bypassPermissions mode (or --dangerously-skip-permissions), writes to .claude/, .git/, .vscode/, and .idea/ directories still prompt for confirmation. While the intent is safety, this creates friction in two scenarios:
1. Autonomous agent workflows (NightShift / Ralph loops)
Workers running in bypass mode need to write review/communication files to .claude/nightshift/. Every write triggers a permission prompt, breaking autonomous execution. The current exemptions (.claude/commands/, .claude/agents/, .claude/skills/) don't cover this.
2. Power user sessions with heavy .claude/rules/ editing
Users who frequently edit .claude/CLAUDE.md or .claude/rules/*.md get prompted repeatedly despite explicitly opting into bypass mode. The user already accepted the risk by enabling bypass — re-prompting for every .claude/ write undermines that choice.
Proposed Solution
Add a configurable setting to extend the exemption list:
{
"permissions": {
"defaultMode": "bypassPermissions",
"bypassProtectedPaths": [
".claude/"
]
}
}
Or alternatively, a broader toggle:
{
"skipProtectedDirectoryPrompts": true
}
Alternatives considered
- Moving files out of
.claude/— works but forces architectural compromises to work around a CLI limitation - Using option 2 ("allow all edits in dir") — only lasts per-session, resets on restart, and doesn't help headless/autonomous workers
skipDangerousModePermissionPrompt: true— already set, but this only skips the initial bypass mode confirmation, not the per-directory protections
Context
- Claude Code v2.1.81
- Platform: Windows 11 (Git Bash)
- Use case: Monorepo with extensive
.claude/configuration (rules, skills, nightshift state, hooks) - The
.claude/skills/exemption already proves this is safe to configure — extending it to other.claude/subdirs follows the same pattern
Who benefits
- Anyone using
bypassPermissionsmode who edits.claude/files frequently - Autonomous agent frameworks (NightShift, Ralph loops, CI pipelines) that need to write state files
- Teams with custom
.claude/directory structures beyond commands/agents/skills
🤖 Generated with Claude Code
11 Comments
A PreToolUse hook can selectively unlock specific protected directories while keeping others locked:
\
\\bash\INPUT=\$(cat)
TOOL=\$(echo "\$INPUT" | jq -r '.tool_name // empty' 2>/dev/null)
FILE=\$(echo "\$INPUT" | jq -r '.tool_input.file_path // empty' 2>/dev/null)
[[ "\$TOOL" != "Edit" && "\$TOOL" != "Write" ]] && exit 0
[[ -z "\$FILE" ]] && exit 0
UNLOCKED=(
".claude/commands"
".claude/skills"
".claude/agents"
".claude/rules"
".claude/todo.md"
)
for pattern in "\${UNLOCKED[@]}"; do
if [[ "\$FILE" == *"\$pattern"* ]]; then
jq -n '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"allow","permissionDecisionReason":"unlocked protected directory"}}'
exit 0
fi
done
exit 0
\
\This gives you per-path control: unlock \
.claude/commands/\for agent workflows while keeping \.claude/hooks/\and \.claude/settings.json\locked.For \
.git/\— you almost never want to unlock that. For \.vscode/\/\.idea/\— those are safer to unlock entirely since they're IDE config, not security-critical.Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
It doesn't seem to work.
Same.
I tried to implement the solution but it still prompts for permission
Update: PreToolUse hook does NOT work — PermissionRequest hook does
After implementing the PreToolUse hook suggested above, I can confirm it does not suppress the protected directory prompts. @lightrow reported the same.
The reason (clarified by @yurukusa in #37496): PreToolUse runs _before_ the built-in protected-directory checks, so its
permissionDecision: "allow"gets overridden downstream. PermissionRequest runs _after_ those checks, which is why it sticks.Working workaround (confirmed across #36044, #36282, #37496):
bypassPermissionsat user level (~/.claude/settings.json)~/.claude/hooks/allow-protected-dirs.sh:This is scoped — only auto-approves the 4 protected directories, plan approvals and other prompts still work normally.
Related issues with the same problem: #35942, #36044, #36282, #37496
The core ask remains: Anthropic should add a
skipProtectedDirectoryPromptssetting so users don't need hook workarounds for behavior they already opted into viabypassPermissions.Just shipped a PermissionRequest example hook for this exact scenario in cc-safe-setup v28.6.0:
@floraldo's analysis was spot on — the execution order is:
So
permissionDecision: "allow"in PreToolUse gets overridden by step 2. PermissionRequest is the correct hook type for bypassing protected directory prompts.Added this to our Troubleshooting docs as well.
Yes please. I run extensive hook scripts and agent workflows that frequently touch .claude/hooks/ and .claude/skills/. The blanket protected directory block with no override is incredibly frustrating — I chose bypass mode for a reason. At minimum, let us configure which subdirectories under .claude/ should be exempt. This would solve 90% of the pain.
You can auto-approve writes to specific
.claude/subdirectories with a hook:Same for Edit:
This gives your NightShift workers write access to
.claude/nightshift/without prompts, while.git/and other protected directories remain gated.Update: Windows backslash fix for the PermissionRequest hook
The
PermissionRequesthook approach from my earlier comment has been working reliably — but we hit a subtle issue on Windows where it would auto-approve some.claude/paths but not others.Root cause: On Windows, Claude sends
file_pathwith backslashes (kinsai\clients\ideawise\.claude\skills\...), but the bash hook checks for forward-slash patterns (.claude/). Paths directly under the repo root (.claude/settings.json) matched because the path still contained/.claude/from the repo prefix, but deeply nested.claude/directories (we have 30+ across our monorepo) failed the match.Fix — normalize backslashes before matching:
One-line diff from the original:
NORMALIZED="${FILE_PATH//\//}"+ match against$NORMALIZEDinstead of$FILE_PATH.Relevant for anyone running Claude Code on Windows (Git Bash / MSYS2). macOS/Linux users are unaffected since paths already use forward slashes.
The core ask still stands — a native
skipProtectedDirectoryPromptssetting would eliminate this entire class of cross-platform edge cases.Closing for now — inactive for too long. Please open a new issue if this is still relevant.
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.