🐛 fix(vscode): GUI 下解析 claude 绝对路径(含 ~/.local/bin 官方安装)
This commit is contained in:
1 parent
81ab00bdba
commit
9255b55625
4 files changed
+127
-14
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import { existsSync } from 'node:fs'
|
||||
import * as os from 'node:os'
|
||||
import * as path from 'node:path'
|
||||
|
||||
/**
|
||||
* 解析 claude 可执行文件绝对路径;找不到返回 null。
|
||||
*
|
||||
* 顺序:env.PATH 各目录下的 claude → 官方/常见绝对路径候选。
|
||||
* GUI 启动的 VS Code 常缺 ~/.local/bin,不能只靠 spawn('claude')。
|
||||
*/
|
||||
export function resolveClaudeBin(
|
||||
env: NodeJS.ProcessEnv = process.env,
|
||||
homeDir?: string,
|
||||
): string | null {
|
||||
const home = homeDir ?? env.HOME ?? os.homedir()
|
||||
|
||||
for (const dir of (env.PATH ?? '').split(path.delimiter)) {
|
||||
if (!dir)
|
||||
continue
|
||||
const candidate = path.join(dir, 'claude')
|
||||
if (existsSync(candidate))
|
||||
return candidate
|
||||
}
|
||||
|
||||
const fallbacks = [
|
||||
path.join(home, '.local', 'bin', 'claude'),
|
||||
'/usr/local/bin/claude',
|
||||
'/usr/bin/claude',
|
||||
path.join(home, '.claude', 'local', 'claude'),
|
||||
]
|
||||
for (const candidate of fallbacks) {
|
||||
if (existsSync(candidate))
|
||||
return candidate
|
||||
}
|
||||
return null
|
||||
}
|
||||
Reference in new issue
Block a user