Skip to content

Fixed diff panel appearing despite bypassPermissions/acceptEdits when Claude cd'd into subdir - #140

Merged
oleg68 merged 1 commit into
nbplugins:mainfrom
oleg68:bugfix/bypass-permissions-subdir
May 24, 2026
Merged

oleg68 merged 1 commit into
nbplugins:mainfrom
oleg68:bugfix/bypass-permissions-subdir

Conversation

@oleg68

@oleg68 oleg68 commented May 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • getEditModeForCwd() used an exact key match against EDIT_MODE_REGISTRY, but the hook's cwd is Claude's current working directory — which may be a subdirectory of the session root if Claude cd'd during the session
  • Exact match missed → fell back to EditMode.DEFAULT → diff panel shown even in bypassPermissions / acceptEdits modes
  • Fix: falls back to a longest-prefix match (Path.startsWith) when the exact key is not found
  • Added getSessionRootForCwd() with the same logic so the acceptEdits directory boundary check uses the session root, not Claude's current subdirectory cwd

Test plan

  • Added two regression tests in NetBeansMCPHandlerHookTest: registry key = session root, hook cwd = subdirectory — both bypassPermissions and acceptEdits now auto-allow correctly
  • All 860 existing tests pass
  • Manual: start Claude in bypassPermissions mode, ask it to edit a file in a subdirectory → diff panel does not appear

🤖 Generated with Claude Code

… Claude cd'd into subdir

When Claude's working directory at edit time is a subdirectory of the
session root (e.g. session started at /proj, Claude cd'd into
/proj/submodules/Kotlin), the EDIT_MODE_REGISTRY lookup by exact key
missed and fell back to EditMode.DEFAULT, causing the diff panel to
appear even in bypassPermissions and acceptEdits modes.

Fix: getEditModeForCwd() now falls back to a longest-prefix match when
the exact key is not found. Added getSessionRootForCwd() using the same
logic so the acceptEdits directory boundary check uses the session root
rather than Claude's current cwd.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@oleg68
oleg68 merged commit 50f159a into nbplugins:main May 24, 2026
3 checks passed
@oleg68
oleg68 deleted the bugfix/bypass-permissions-subdir branch May 24, 2026 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant