diff --git a/.changeset/fix-claude-code-install-detection.md b/.changeset/fix-claude-code-install-detection.md new file mode 100644 index 0000000000..90c421281a --- /dev/null +++ b/.changeset/fix-claude-code-install-detection.md @@ -0,0 +1,5 @@ +--- +"task-master-ai": patch +--- + +Fix Claude Code CLI detection for native binary installations and update install instructions to reference official documentation diff --git a/docs/examples/claude-code-usage.md b/docs/examples/claude-code-usage.md index ff37e2cee2..3ffe9adc87 100644 --- a/docs/examples/claude-code-usage.md +++ b/docs/examples/claude-code-usage.md @@ -59,16 +59,15 @@ task-master set-status --id=task-001 --status=in-progress ## Requirements -1. Claude Code CLI must be installed and authenticated on your system -2. Install the optional `@anthropic-ai/claude-code` package if you enable this provider: +1. Claude Code CLI must be installed and authenticated on your system. Install from the [official docs](https://docs.anthropic.com/en/docs/claude-code/overview) or run: ```bash - npm install @anthropic-ai/claude-code + curl -fsSL https://claude.ai/install.sh | bash ``` -3. Run Claude Code for the first time and authenticate with your Anthropic account: +2. Run Claude Code for the first time and authenticate with your Anthropic account: ```bash claude ``` -4. No API key is required in your environment variables or MCP configuration +3. No API key is required in your environment variables or MCP configuration ## Advanced Settings diff --git a/packages/tm-core/src/modules/loop/services/loop.service.ts b/packages/tm-core/src/modules/loop/services/loop.service.ts index 3533d48219..5bcc506d41 100644 --- a/packages/tm-core/src/modules/loop/services/loop.service.ts +++ b/packages/tm-core/src/modules/loop/services/loop.service.ts @@ -586,7 +586,7 @@ Loop iteration ${iteration} of ${config.iterations}${tagInfo}`; if (error.code === 'ENOENT') { return sandbox ? 'Docker is not installed. Install Docker Desktop to use --sandbox mode.' - : 'Claude CLI is not installed. Install with: npm install -g @anthropic-ai/claude-code'; + : 'Claude Code CLI is not installed. Install it from: https://docs.anthropic.com/en/docs/claude-code/getting-started'; } if (error.code === 'EACCES') { diff --git a/src/ai-providers/claude-code.js b/src/ai-providers/claude-code.js index 38d42baeb7..072702f842 100644 --- a/src/ai-providers/claude-code.js +++ b/src/ai-providers/claude-code.js @@ -11,7 +11,10 @@ * */ -import { execSync } from 'child_process'; +import { execSync, execFileSync } from 'child_process'; +import { existsSync } from 'fs'; +import { join, dirname } from 'path'; +import { homedir } from 'os'; import { createClaudeCode } from 'ai-sdk-provider-claude-code'; import { getClaudeCodeSettingsForCommand, @@ -82,11 +85,39 @@ export class ClaudeCodeProvider extends BaseAIProvider { execSync('claude --version', { stdio: 'pipe', timeout: 1000 }); _claudeCliAvailable = true; } catch (error) { - _claudeCliAvailable = false; - log( - 'warn', - 'Claude Code CLI not detected. Install it with: npm install -g @anthropic-ai/claude-code' - ); + // PATH-based lookup failed - check common install locations + // The native binary may be installed outside the current PATH + // (e.g. when running as an MCP server with a minimal environment) + const home = homedir(); + const commonPaths = [ + join(home, '.local', 'bin', 'claude'), + join(home, '.bun', 'bin', 'claude'), + '/usr/local/bin/claude' + ]; + const found = commonPaths.find((p) => existsSync(p)); + if (found) { + try { + execFileSync(found, ['--version'], { + stdio: 'pipe', + timeout: 1000 + }); + // Add the binary's directory to PATH so the SDK can find it + const binDir = dirname(found); + process.env.PATH = `${binDir}${process.platform === 'win32' ? ';' : ':'}${process.env.PATH || ''}`; + _claudeCliAvailable = true; + } catch { + _claudeCliAvailable = false; + } + } else { + _claudeCliAvailable = false; + } + + if (!_claudeCliAvailable) { + log( + 'warn', + 'Claude Code CLI not detected. Install it from: https://docs.anthropic.com/en/docs/claude-code/getting-started' + ); + } } finally { _claudeCliChecked = true; } @@ -147,7 +178,7 @@ export class ClaudeCodeProvider extends BaseAIProvider { const code = error?.code; if (code === 'ENOENT' || /claude/i.test(msg)) { const enhancedError = new Error( - `Claude Code CLI not available. Please install Claude Code CLI first. Original error: ${error.message}` + `Claude Code CLI not available. Install it from: https://docs.anthropic.com/en/docs/claude-code/getting-started - Original error: ${error.message}` ); enhancedError.cause = error; this.handleError('Claude Code CLI initialization', enhancedError);