fix(cli): allow runtime permission mode escalation to bypassPermissions#130
fix(cli): allow runtime permission mode escalation to bypassPermissions#130lucharo wants to merge 1 commit intohappier-dev:devfrom
Conversation
…rmissions
When a session is started without bypassPermissions but the user later
switches to yolo mode from the phone, setPermissionMode('bypassPermissions')
throws because allowDangerouslySkipPermissions was not set at launch time.
Fix by always setting allowDangerouslySkipPermissions: true at session
creation. This does not change the initial permission mode — it only
removes the gate that prevents upgrading permissions at runtime via
setPermissionMode.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
WalkthroughA single-line modification in the Claude remote agent SDK replaces conditional permission-skipping logic with a hard-coded true value, causing explicit permission checks to be unconditionally bypassed regardless of the mapped permission mode configuration. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip You can make CodeRabbit's review stricter and more nitpicky using the `assertive` profile, if that's what you prefer.Change the |
Greptile SummaryThis PR fixes a bug where switching to
Confidence Score: 3/5
|
| Filename | Overview |
|---|---|
| apps/cli/src/backends/claude/remote/claudeRemoteAgentSdk.ts | Always sets allowDangerouslySkipPermissions: true to enable runtime permission escalation to bypassPermissions. The logic change is correct but breaks an existing test assertion. |
Sequence Diagram
sequenceDiagram
participant User as User (Phone)
participant Server as Happier Server
participant CLI as CLI Session
participant SDK as Agent SDK
User->>Server: Switch to yolo mode
Server->>CLI: nextMessage (mode: bypassPermissions)
CLI->>SDK: setPermissionMode('bypassPermissions')
alt Before this PR (allowDangerouslySkipPermissions=false at launch)
SDK-->>CLI: Error: session not launched with --dangerously-skip-permissions
CLI-->>Server: Failed to update runtime settings (non-fatal)
Note over CLI: Session stays on original mode
end
alt After this PR (allowDangerouslySkipPermissions=true at launch)
SDK-->>CLI: Success
CLI-->>Server: Mode updated
Note over CLI: Session now runs in bypassPermissions
end
Last reviewed commit: 0444a46
| settingSources, | ||
| permissionMode: mappedPermissionMode, | ||
| allowDangerouslySkipPermissions: mappedPermissionMode === 'bypassPermissions', | ||
| allowDangerouslySkipPermissions: true, |
There was a problem hiding this comment.
Existing test will now fail
The test in claudeRemoteAgentSdk.optionsAndHooks.test.ts:103 asserts:
expect((await runOnce('default'))?.allowDangerouslySkipPermissions).toBe(false);With this change, allowDangerouslySkipPermissions is now always true, so this assertion will fail. The test (line 55) and its description — "sets allowDangerouslySkipPermissions only when permissionMode is bypassPermissions" — need to be updated to reflect the new behavior (e.g., assert true for all modes and rename the test case).
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/cli/src/backends/claude/remote/claudeRemoteAgentSdk.ts (1)
553-553: Security consideration: Document intent in a comment.Hardcoding
allowDangerouslySkipPermissions: trueis intentional to enable runtime escalation tobypassPermissionsmode. While the actual permission enforcement still flows throughpermissionMode(line 552) and thecanUseTool/PermissionRequesthooks, a brief inline comment would clarify this is deliberate and not a security oversight.📝 Suggested clarifying comment
permissionMode: mappedPermissionMode, - allowDangerouslySkipPermissions: true, + // Always allow so runtime escalation to 'bypassPermissions' via setPermissionMode() succeeds. + // Initial enforcement is controlled by permissionMode above; hooks still validate tool calls. + allowDangerouslySkipPermissions: true,🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/cli/src/backends/claude/remote/claudeRemoteAgentSdk.ts` at line 553, Add a brief inline comment next to the allowDangerouslySkipPermissions: true setting to explain this is intentional to allow runtime escalation to bypassPermissions mode; reference that actual enforcement is handled by permissionMode, the canUseTool hook, and PermissionRequest flow so reviewers know this is not an accidental insecure default and that permission checks remain centralized.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/cli/src/backends/claude/remote/claudeRemoteAgentSdk.ts`:
- Line 553: Add a brief inline comment next to the
allowDangerouslySkipPermissions: true setting to explain this is intentional to
allow runtime escalation to bypassPermissions mode; reference that actual
enforcement is handled by permissionMode, the canUseTool hook, and
PermissionRequest flow so reviewers know this is not an accidental insecure
default and that permission checks remain centralized.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f62a8427-f677-4f81-a498-7389e538f7b3
📒 Files selected for processing (1)
apps/cli/src/backends/claude/remote/claudeRemoteAgentSdk.ts
Summary
allowDangerouslySkipPermissions: trueat Agent SDK session creation, so thatsetPermissionMode('bypassPermissions')works on follow-up messagesProblem
When a session is started with a non-yolo permission mode (e.g.
defaultoracceptEdits) and the user later switches to yolo mode from the phone, the runtimesetPermissionMode('bypassPermissions')call throws:This surfaces as:
The user sees the error on their phone, and the session continues running with the wrong permission mode — it stays on whatever mode it was launched with instead of switching to yolo.
Root cause
At session creation (
claudeRemoteAgentSdk.ts),allowDangerouslySkipPermissionsis only set totruewhen the initial mode isbypassPermissions:But on follow-up messages,
setPermissionMode()is called to update the mode — and it cannot escalate tobypassPermissionsbecause the Claude Agent SDK requiresallowDangerouslySkipPermissionsto have been set at launch time.Fix
Always set
allowDangerouslySkipPermissions: trueat session creation. This does not change the initial permission mode (still controlled bypermissionMode: mappedPermissionMode). It only removes the gate that prevents upgrading permissions at runtime viasetPermissionMode().Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit