feat: add permission request UI for sensitive tool operations#1200
feat: add permission request UI for sensitive tool operations#1200Gkrumbach07 wants to merge 3 commits intomainfrom
Conversation
When Claude Code SDK needs user approval for sensitive operations (e.g. editing .mcp.json), the can_use_tool callback now emits a synthetic PermissionRequest tool call that halts the stream and surfaces an interactive Allow/Deny UI in the frontend. Approved operations are tracked per-session so retries succeed automatically. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughAdds a permission-request human-in-the-loop flow: new PermissionRequest tool input and frontend UI, shared result-presence helper, and adapter/runtime plumbing that emits synthetic permission events, awaits user approval, and resumes or denies tool execution accordingly. Changes
Sequence Diagram(s)sequenceDiagram
participant Claude as Claude SDK
participant Adapter as ClaudeAgentAdapter
participant WorkerQueue as SessionWorker Output Queue
participant Frontend as Frontend UI
participant User as User
Claude->>Adapter: can_use_tool(tool_call)
Adapter->>Adapter: compute permission_key
alt key in _approved_operations
Adapter->>Claude: allow tool usage
else not approved
Adapter->>WorkerQueue: inject synthetic PermissionRequest (ToolCallStart/Args/End)
Adapter->>Claude: deny tool usage
WorkerQueue->>Frontend: deliver PermissionRequest event
Frontend->>Frontend: render PermissionRequestMessage
Frontend->>User: display prompt (Allow/Deny)
User->>Frontend: respond (approved/denied)
Frontend->>WorkerQueue: submit JSON response (approved, key)
WorkerQueue->>Adapter: deliver permission response
Adapter->>Adapter: update _approved_operations if approved
Adapter->>Claude: retry tool call (allow/deny)
end
Claude->>Claude: execute tool (if allowed)
Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error, 1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
- Remove hasResult alias, use hasToolResult directly - Collapse config/resolvedConfig/activeConfig triple to single lookup - Remove redundant hasattr/isinstance guards on ToolCallEndEvent - Use getattr for placeholder ID checks - Clear _permission_worker in bridge finally block (prevent GC leak) - Remove dead description initializer - Add PermissionRequest to use-agent-status.ts waiting_input detection Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@components/runners/ambient-runner/ag_ui_claude_sdk/adapter.py`:
- Around line 976-992: The conditional uses
message.tool_call_id.startswith(_PERM_TOOL_ID_PREFIX) without guarding against
tool_call_id being None, which can raise AttributeError for ToolCallEndEvent
instances missing tool_call_id; update the if condition in the block handling
ToolCallEndEvent to first verify message.tool_call_id is not None (or truthy)
before calling startswith, then proceed to call flush_pending_msg(), set
self._halted, self._halted_tool_call_id and halt_event_stream as currently
implemented when the guarded check passes.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 019bb7d7-c398-4f4e-a5ff-c25149531d0b
📒 Files selected for processing (5)
components/frontend/src/components/session/ask-user-question.tsxcomponents/frontend/src/components/session/permission-request.tsxcomponents/frontend/src/hooks/use-agent-status.tscomponents/runners/ambient-runner/ag_ui_claude_sdk/adapter.pycomponents/runners/ambient-runner/ambient_runner/bridges/claude/bridge.py
🚧 Files skipped from review as they are similar to previous changes (1)
- components/frontend/src/components/session/permission-request.tsx
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
AI was unable to resolve issues after 3 attempts. Needs human attention. |
|
@ambient-code please fix Performance And Algorithmic Complexity | ❌ Error | The _approved_operations set persists across runs without eviction, accumulating indefinitely as the adapter is intentionally cached and reused. | Implement LRU cache with fixed size (e.g., max 1000 entries), add TTL-based auto-eviction, or clear at session boundaries; document approval persistence scope. |
Summary
can_use_toolcallback in the Claude SDK adapter to intercept sensitive tool operations (e.g., editing.mcp.json)PermissionRequesttool calls through the AG-UI event stream, reusing the existing halt-interrupt-resume pattern fromAskUserQuestionPermissionRequestMessagefrontend component with Allow/Deny buttons that surfaces permission requests in the session chat UITest plan
npm run build— 0 errors, 0 warnings)tsc --noEmit)npx vitest run)🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Refactor