Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 41 additions & 12 deletions crates/goose/src/providers/claude_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ use crate::model::ModelConfig;
use rmcp::model::Tool;

pub const CLAUDE_CODE_DEFAULT_MODEL: &str = "claude-sonnet-4-20250514";
pub const CLAUDE_CODE_KNOWN_MODELS: &[&str] = &["sonnet", "opus", "claude-sonnet-4-20250514"];

pub const CLAUDE_CODE_DOC_URL: &str = "https://claude.ai/cli";
pub const CLAUDE_CODE_KNOWN_MODELS: &[&str] = &["sonnet", "opus"];
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing 'claude-sonnet-4-20250514' from CLAUDE_CODE_KNOWN_MODELS will cause the model argument to not be passed to the CLI when using the default model (since line 337 checks if the model is in KNOWN_MODELS). This breaks the default behavior where users expect the default model to be passed to the command.

Suggested change
pub const CLAUDE_CODE_KNOWN_MODELS: &[&str] = &["sonnet", "opus"];
pub const CLAUDE_CODE_KNOWN_MODELS: &[&str] = &["claude-sonnet-4-20250514", "sonnet", "opus"];

Copilot uses AI. Check for mistakes.
pub const CLAUDE_CODE_DOC_URL: &str = "https://code.claude.com/docs/en/setup";

#[derive(Debug, serde::Serialize)]
pub struct ClaudeCodeProvider {
Expand Down Expand Up @@ -169,6 +168,34 @@ impl ClaudeCodeProvider {
}

/// Parse the JSON response from claude CLI
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc comment '/// Parse the JSON response from claude CLI' is incorrect for this function. It should describe applying permission flags to the command, not parsing JSON responses.

Suggested change
/// Parse the JSON response from claude CLI
/// Apply permission flags to the command based on the current GooseMode

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, co-pilot! or delete the comment

fn apply_permission_flags(cmd: &mut Command) -> Result<(), ProviderError> {
let config = Config::global();
match config.get_goose_mode() {
Ok(GooseMode::Auto) => {
cmd.arg("--dangerously-skip-permissions");
}
Ok(GooseMode::SmartApprove) => {
cmd.arg("--permission-mode").arg("acceptEdits");
}
Ok(GooseMode::Approve) => {
return Err(ProviderError::RequestFailed(
"\n\n\n### NOTE\n\n\n \
Claude Code CLI provider does not support Approve mode.\n \
Please use Auto (which will run anything it needs to) or \
SmartApprove (most things will run or Chat Mode)\n\n\n"
Comment on lines +184 to +185
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message has unclear wording. 'SmartApprove (most things will run or Chat Mode)' is grammatically incorrect. It should be clearer, such as: 'Please use Auto (which will run anything it needs to), SmartApprove (most things will run), or Chat Mode.'

Suggested change
Please use Auto (which will run anything it needs to) or \
SmartApprove (most things will run or Chat Mode)\n\n\n"
Please use Auto (which will run anything it needs to), SmartApprove (most things will run), or Chat Mode\n\n\n"

Copilot uses AI. Check for mistakes.
.to_string(),
));
}
Ok(GooseMode::Chat) => {
// Chat mode doesn't need permission flags
}
Err(_) => {
// Default behavior if mode is not set
}
}
Ok(())
}

fn parse_claude_response(
&self,
json_lines: &[String],
Expand Down Expand Up @@ -314,19 +341,21 @@ impl ClaudeCodeProvider {
cmd.arg("--verbose").arg("--output-format").arg("json");

// Add permission mode based on GOOSE_MODE setting
let config = Config::global();
if let Ok(GooseMode::Auto) = config.get_goose_mode() {
cmd.arg("--permission-mode").arg("acceptEdits");
}
Self::apply_permission_flags(&mut cmd)?;

cmd.stdout(Stdio::piped()).stderr(Stdio::piped());

let mut child = cmd
.spawn()
.map_err(|e| ProviderError::RequestFailed(format!(
"Failed to spawn Claude CLI command '{}': {}. \
Make sure the Claude Code CLI is installed and in your PATH, or set CLAUDE_CODE_COMMAND in your config to the correct path.",
self.command, e
"\n\n ## Unable to find Claude Code CLI on the path.\n\n\
**Error details:** Failed to spawn command '{}': {}\n\n\
**Please ensure:**\n\
- Claude Code CLI is installed and logged in\n\
- The command is in your PATH, or set `CLAUDE_CODE_COMMAND` in your config\n\n\
**For full features, please use the Anthropic provider with an API key if possible.**\n\n\
Visit {} for installation instructions.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or change the path using @jamadeo 's new tricks

self.command, e, CLAUDE_CODE_DOC_URL
)))?;

let stdout = child
Expand Down Expand Up @@ -427,8 +456,8 @@ impl Provider for ClaudeCodeProvider {
fn metadata() -> ProviderMetadata {
ProviderMetadata::new(
"claude-code",
"Claude Code",
"Execute Claude models via claude CLI tool",
"Claude Code CLI",
"Requires claude CLI installed, no MCPs. Use Anthropic provider for full features.",
CLAUDE_CODE_DEFAULT_MODEL,
CLAUDE_CODE_KNOWN_MODELS.to_vec(),
CLAUDE_CODE_DOC_URL,
Expand Down