Skip to content

Commit b4cc067

Browse files
committed
fix: Address PR review feedback on CLI detection
- Use execFileSync instead of execSync with template literal to avoid shell injection risk (CodeRabbit) - Add found binary's directory to process.env.PATH so the SDK can resolve it via PATH lookup downstream (Cursor Bugbot)
1 parent 9597ee1 commit b4cc067

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/ai-providers/claude-code.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
*
1212
*/
1313

14-
import { execSync } from 'child_process';
14+
import { execSync, execFileSync } from 'child_process';
1515
import { existsSync } from 'fs';
16-
import { join } from 'path';
16+
import { join, dirname } from 'path';
1717
import { homedir } from 'os';
1818
import { createClaudeCode } from 'ai-sdk-provider-claude-code';
1919
import {
@@ -97,10 +97,13 @@ export class ClaudeCodeProvider extends BaseAIProvider {
9797
const found = commonPaths.find((p) => existsSync(p));
9898
if (found) {
9999
try {
100-
execSync(`"${found}" --version`, {
100+
execFileSync(found, ['--version'], {
101101
stdio: 'pipe',
102102
timeout: 1000
103103
});
104+
// Add the binary's directory to PATH so the SDK can find it
105+
const binDir = dirname(found);
106+
process.env.PATH = `${binDir}${process.platform === 'win32' ? ';' : ':'}${process.env.PATH || ''}`;
104107
_claudeCliAvailable = true;
105108
} catch {
106109
_claudeCliAvailable = false;

0 commit comments

Comments
 (0)