Auto approve in plan mode (#1450)

This commit is contained in:
Alex Netsch
2025-12-07 13:47:57 +00:00
committed by GitHub
parent e6a5694bda
commit d72ec43d3b
2 changed files with 31 additions and 11 deletions

View File

@@ -17,7 +17,11 @@ use workspace_utils::{
path::make_path_relative,
};
use self::{client::ClaudeAgentClient, protocol::ProtocolPeer, types::PermissionMode};
use self::{
client::{AUTO_APPROVE_CALLBACK_ID, ClaudeAgentClient},
protocol::ProtocolPeer,
types::PermissionMode,
};
use crate::{
approvals::ExecutorApprovalService,
command::{CmdOverrides, CommandBuilder, CommandParts, apply_overrides},
@@ -130,6 +134,10 @@ impl ClaudeCode {
{
"matcher": "^ExitPlanMode$",
"hookCallbackIds": ["tool_approval"],
},
{
"matcher": "^(?!ExitPlanMode$).*",
"hookCallbackIds": [AUTO_APPROVE_CALLBACK_ID],
}
]
}))

View File

@@ -19,6 +19,7 @@ use crate::{
};
const EXIT_PLAN_MODE_NAME: &str = "ExitPlanMode";
pub const AUTO_APPROVE_CALLBACK_ID: &str = "AUTO_APPROVE_CALLBACK_ID";
/// Claude Agent client with control protocol support
pub struct ClaudeAgentClient {
@@ -141,7 +142,7 @@ impl ClaudeAgentClient {
pub async fn on_hook_callback(
&self,
_callback_id: String,
callback_id: String,
_input: serde_json::Value,
_tool_use_id: Option<String>,
) -> Result<serde_json::Value, ExecutorError> {
@@ -154,16 +155,27 @@ impl ClaudeAgentClient {
}
}))
} else {
// Hook callbacks is only used to forward approval requests to can_use_tool.
// This works because `ask` decision in hook callback triggers a can_use_tool request
// https://docs.claude.com/en/api/agent-sdk/permissions#permission-flow-diagram
Ok(serde_json::json!({
"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"permissionDecision": "ask",
"permissionDecisionReason": "Forwarding to canusetool service"
match callback_id.as_str() {
AUTO_APPROVE_CALLBACK_ID => Ok(serde_json::json!({
"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"permissionDecision": "allow",
"permissionDecisionReason": "Approved by SDK"
}
})),
_ => {
// Hook callbacks is only used to forward approval requests to can_use_tool.
// This works because `ask` decision in hook callback triggers a can_use_tool request
// https://docs.claude.com/en/api/agent-sdk/permissions#permission-flow-diagram
Ok(serde_json::json!({
"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"permissionDecision": "ask",
"permissionDecisionReason": "Forwarding to canusetool service"
}
}))
}
}))
}
}
}