fix: allow permissionMode to override yolo in claude_code provider#322
Conversation
When running as root/sudo, Claude Code refuses --dangerously-skip-permissions. The yolo mode was unconditionally passing that flag, causing initialization to fail. This change lets profile.permissionMode take precedence over yolo, so users can configure 'auto' or 'bypassPermissions' to avoid the blocked flag.
There was a problem hiding this comment.
Pull request overview
Adjusts how the Claude Code provider selects its base permission flags so agent profile permissionMode can override “yolo” behavior, avoiding Claude Code startup failures when run under root/sudo.
Changes:
- Updates
_build_claude_command()to prioritizeprofile.permissionModeeven whenallowedTools: ["*"](yolo) is active. - Changes the yolo path to omit
--dangerously-skip-permissions(intended to avoid root/sudo rejection).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| elif yolo: | ||
| # yolo mode: no --dangerously-skip-permissions flag because | ||
| # Claude Code refuses it under root/sudo. Let CAO handle permissions. | ||
| command_parts = ["claude"] |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #322 +/- ##
=======================================
Coverage ? 87.25%
=======================================
Files ? 99
Lines ? 12220
Branches ? 0
=======================================
Hits ? 10663
Misses ? 1557
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@zz327455573 One concern with the new I confirmed the current command builder output: Suggested fix: keep is_root = getattr(os, "geteuid", lambda: -1)() == 0
if profile and profile.permissionMode:
command_parts = ["claude", "--permission-mode", profile.permissionMode]
elif yolo and is_root:
command_parts = ["claude"]
else:
command_parts = ["claude", "--dangerously-skip-permissions"]Please also add regression tests for yolo/non-root, yolo/root, and yolo+ Finally, please update the Claude Code docs because they still say yolo always forces Focused checks pass locally: FindingP1 - Non-root yolo launches no longer bypass Claude tool prompts
if profile and profile.permissionMode:
command_parts = ["claude", "--permission-mode", profile.permissionMode]
elif yolo:
command_parts = ["claude"]
else:
command_parts = ["claude", "--dangerously-skip-permissions"]That fixes the root/sudo case, where Claude rejects I confirmed the current command builder output: Suggested fix: keep is_root = getattr(os, "geteuid", lambda: -1)() == 0
if profile and profile.permissionMode:
command_parts = ["claude", "--permission-mode", profile.permissionMode]
elif yolo and is_root:
command_parts = ["claude"]
else:
command_parts = ["claude", "--dangerously-skip-permissions"]Add regression tests for:
Also update Checks Runuv run pytest test/providers/test_claude_code_unit.py -q
# 108 passed
uv run black --check src/cli_agent_orchestrator/providers/claude_code.py test/providers/test_claude_code_unit.py
# 2 files would be left unchanged
uv run isort --check-only src/cli_agent_orchestrator/providers/claude_code.py test/providers/test_claude_code_unit.py
# passed
git diff --check
# passed |
…oot, not all yolo Previously the elif-yolo branch dropped --dangerously-skip-permissions for every yolo launch (allowedTools=["*"]), which broke non-root headless sessions by letting Claude prompt for tool approval inside tmux panes and silently block handoff/assign. Fix: add is_root guard so the flag is only omitted when running as root/sudo. Priority order: 1. profile.permissionMode set => claude --permission-mode <value> 2. yolo + is_root => claude (flag rejected by Claude under root) 3. everything else => claude --dangerously-skip-permissions Also adds three regression tests covering yolo/non-root, yolo/root, and yolo+permissionMode to address the Codecov patch coverage warning. Updates docs/claude-code.md and docs/agent-profile.md to reflect correct priority (permissionMode > yolo, root-only omission). Fixes: awslabs#322
|
@haofeif 我已经按照你的建议修复了,看看还有什么问题 |
|
@zz327455573 thanks for your fixes. can you please address the 3 CI errors before we can approve the PR. Much appreciated for your help!
|
45ef3c2 to
4c6414e
Compare
haofeif
left a comment
There was a problem hiding this comment.
Thank you @zz327455573 for your great contribution!
Problem
When running CAO as root/sudo with a third-party model (e.g. LongCat via custom ANTHROPIC_BASE_URL), the yolo mode unconditionally passes
--dangerously-skip-permissionsto Claude Code. Claude Code refuses this flag under root privileges with:This causes Claude Code initialization to hang and eventually time out (30s).
Root Cause
In
claude_code.pyline 167, the condition was:When
yolo=True(allowedTools: ["*"]in profile), the code always fell through to the else branch which passed--dangerously-skip-permissions— a flag that Claude Code rejects under root.Fix
Changed the condition so
profile.permissionModealways takes precedence regardless of yolo mode:Users running as root can now set
permissionMode: autoorpermissionMode: bypassPermissionsin their agent profile to avoid the blocked flag.Test Plan
--dangerously-skip-token-permissionsstill works (unchanged path)