fix(cli): prevent root rejection when using canCallTool with bypassPermissions#180
Open
cruzanstx wants to merge 1 commit intotiann:mainfrom
Open
fix(cli): prevent root rejection when using canCallTool with bypassPermissions#180cruzanstx wants to merge 1 commit intotiann:mainfrom
cruzanstx wants to merge 1 commit intotiann:mainfrom
Conversation
…rmissions When running as root, Claude Code rejects --dangerously-skip-permissions (mapped from --permission-mode bypassPermissions). Since canCallTool already handles permission auto-approval via --permission-prompt-tool stdio, skip passing the redundant --permission-mode flag in that case. Also fixes abort error being overwritten by exit code error (else-if), captures stderr via logDebug for diagnostics, improves error logging in remote launcher, and falls back to first online machine in sync engine. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| if (hostMatch) return hostMatch | ||
| } | ||
| return null | ||
| return onlineMachines[0] |
There was a problem hiding this comment.
[MAJOR] [Correctness] Resume can target wrong machine
Why this is a problem: When metadata.machineId or metadata.host is set but no match is online, this now falls back to the first online machine. Resume then uses metadata.path on a different machine, risking wrong workspace or unintended session creation.
Suggested fix:
const targetMachine = (() => {
if (metadata.machineId) {
const exact = onlineMachines.find((machine) => machine.id === metadata.machineId)
if (exact) return exact
return null
}
if (metadata.host) {
const hostMatch = onlineMachines.find((machine) => machine.metadata?.host === metadata.host)
if (hostMatch) return hostMatch
return null
}
return onlineMachines[0]
})()
if (!targetMachine) {
return { type: 'error', message: 'No matching machine online', code: 'no_machine_online' }
}There was a problem hiding this comment.
Findings
- [Major] Resume can target wrong machine when
metadata.machineIdormetadata.hostmismatches; fallback to first online usesmetadata.pathon another machine. Evidencehub/src/sync/syncEngine.ts:353.
Suggested fix:const targetMachine = (() => { if (metadata.machineId) { const exact = onlineMachines.find((machine) => machine.id === metadata.machineId) if (exact) return exact return null } if (metadata.host) { const hostMatch = onlineMachines.find((machine) => machine.metadata?.host === metadata.host) if (hostMatch) return hostMatch return null } return onlineMachines[0] })() if (!targetMachine) { return { type: 'error', message: 'No matching machine online', code: 'no_machine_online' } }
Summary
- 1 issue. Resume safety risk on multi-machine namespaces.
Testing
- Not run (automation)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--dangerously-skip-permissions(mapped from--permission-mode bypassPermissions). SincecanCallToolalready handles permission auto-approval via--permission-prompt-tool stdio, skip passing the redundant--permission-modeflag in that case.if/iftoif/else ifin close handler to prevent exit code error from overwritingAbortErrorlogDebug()instead of only whenDEBUGenv is set — critical for diagnosing silent Claude process exits{}(Error objects don't JSON.stringify)Context
When hapi runs as root (common in containerized/server deployments), the
--yolo/bypassPermissionsmode causes Claude Code to immediately exit with code 1 and the message--dangerously-skip-permissions cannot be used with root/sudo privileges. The remote launcher catches this as an empty error{}and shows "Process exited unexpectedly" to the user.The fix recognizes that
canCallTool+--permission-prompt-tool stdioalready achieves the same effect asbypassPermissions— permissions are auto-approved app-side — so the redundant CLI flag can be safely omitted.Test plan
--yolomode and verify Claude sessions start successfully🤖 Generated with Claude Code