From 2a839ff94e5651510eeac841234d817ebb86d6d7 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 8 Feb 2026 12:57:10 +0800 Subject: [PATCH] Add Claude CLI argument mapping for sandbox arguments - Introduce a whitelist mapping for `package.yao` sandbox arguments to corresponding Claude CLI flags, allowing selective argument passing. - Update `BuildCommandWithContinuation` to iterate over the whitelist and append valid arguments to the Claude CLI command. This change enhances the flexibility of argument handling in the Claude CLI, ensuring only specified arguments are processed. --- agent/sandbox/claude/command.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/agent/sandbox/claude/command.go b/agent/sandbox/claude/command.go index e2e4648d..0c5a8fe1 100644 --- a/agent/sandbox/claude/command.go +++ b/agent/sandbox/claude/command.go @@ -49,6 +49,14 @@ When working with GitHub and a token is provided: 3. Do NOT use curl to call GitHub API directly - always prefer gh CLI ` +// claudeArgWhitelist maps package.yao sandbox.arguments keys to Claude CLI flags. +// Only keys listed here are passed through; everything else is ignored. +var claudeArgWhitelist = map[string]string{ + "max_turns": "--max-turns", // Maximum conversation turns + "disallowed_tools": "--disallowed-tools", // Comma-separated tool blacklist (e.g. "WebSearch,WebFetch") + "allowed_tools": "--allowedTools", // Comma-separated tool whitelist (e.g. "Bash,Read,Write") +} + // BuildCommand builds the Claude CLI command and environment variables // Uses stdin with --input-format stream-json for unlimited prompt length // isContinuation: if true, uses --continue to resume previous session (only sends last user message) @@ -109,10 +117,13 @@ func BuildCommandWithContinuation(messages []agentContext.Message, opts *Options claudeArgs = append(claudeArgs, "--continue") } - // Add max_turns if specified + // Pass through whitelisted arguments to Claude CLI flags. + // Map: package.yao arguments key → Claude CLI flag if opts != nil && opts.Arguments != nil { - if maxTurns, ok := opts.Arguments["max_turns"]; ok { - claudeArgs = append(claudeArgs, "--max-turns", fmt.Sprintf("%v", maxTurns)) + for key, flag := range claudeArgWhitelist { + if val, ok := opts.Arguments[key]; ok { + claudeArgs = append(claudeArgs, flag, fmt.Sprintf("%v", val)) + } } }