claude CLI问题处理
在idea中点击Terminal图标,就会新建一个PowerShell窗口
然后输入claude,回车,出现以下问题
PS D:\software\project\tuge-esim-kiosk> claude Bun is a fast JavaScript runtime, package manager, bundler, and test runner. (1.4.0+fe06227f0) Usage: bun <command> [...flags] [...args] Commands: run ./my-script.ts Execute a file with Bun lint Run a package.json script test Run unit tests with Bun x next Execute a package binary (CLI), installing if needed (bunx) repl Start a REPL session with Bun exec Run a shell script directly with Bun install Install dependencies for a package.json (bun i) add @zarfjs/zarf Add a dependency to package.json (bun a) remove jquery Remove a dependency from package.json (bun rm) update zod Update outdated dependencies audit Check installed packages for vulnerabilities outdated Display latest versions of outdated dependencies link [<package>] Register or link a local npm package unlink Unregister a local npm package publish Publish a package to the npm registry patch <pkg> Prepare a package for patching pm <subcommand> Additional package management utilities info tailwindcss Display package metadata from the registry why elysia Explain why a package is installed build ./a.ts ./b.jsx Bundle TypeScript & JavaScript into a single file init Start an empty Bun project from a built-in template create elysia Create a new project from a template (bun c) upgrade Upgrade to latest version of Bun. feedback ./file1 ./file2 Provide feedback to the Bun team. <command> --help Print help text for command. Learn more about Bun: https://bun.com/docs Join our Discord community: https://bun.com/discord问题根因:PowerShell 里claude被错误映射到了 bun 命令
你输入claude回车直接输出 Bun 的帮助,根本不是装了 Claude CLI,是系统别名 / 脚本冲突:
- 存在一个叫
claude.ps1/claude.cmd的脚本,内部直接调用了bun; - 或者 Path 环境变量被污染,
claude被解析成 bun 入口; - 真正的 Anthropic 官方 claude 命令完全没安装。
第一步:先排查冲突,删掉错误的 claude 映射
1. 查找到底哪里来的 claude 命令
可以在这个地方输入PowerShell
然后就会出现下图样式,点击红框里面的PowerShell
然后再这个地方输入PowerShell命令
PowerShell 执行:
Get-Command claude大概率会返回Application或者Script,记下路径,直接删除该文件即可。
找到文件位置,如下图
要删掉的三个:
claude(无后缀文件)claude.cmdclaude.ps1
这三个是手动自定义的错误包装脚本,内部写死调用了bun,所以你输入claude只会弹出 Bun 帮助,并不是真正 Anthropic 官方 CLI。
第二步:操作步骤
1. 文件删除
直接在文件夹选中删除:
- claude
- claude.cmd
- claude.ps1
2. 重装真正官方 Claude CLI(二选一)
用你本机已装的 bun 安装(推荐)
在idea这个窗口执行下面命令
bun add -g @anthropic-ai/claude或者 npm 安装
npm install -g @anthropic-ai/claude若出现下面报错
PS D:\software\project\tuge-esim-kiosk> bun add -g @anthropic-ai/claude bun : 无法将 “bun” 项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:1 字符: 1 bun add -g @anthropic-ai/claude ```plaintext + CategoryInfo : ObjectNotFound: (bun:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException ```只是能执行bun输出帮助,但Bun 没有配置到系统环境变量 PATH,删了假 claude 后连 bun 命令也找不到了,直接改用npm 安装最简单。
npm install -g @anthropic-ai/claude要是出现下面错误
PS D:\software\project\tuge-esim-kiosk> npm install -g @anthropic-ai/claude npm error code E404 npm error 404 Not Found - GET https://registry.npmjs.org/@anthropic-ai%2fclaude - Not found npm error 404 npm error 404 The requested resource '@anthropic-ai/claude@*' could not be found or you do not have permission to access it. npm error 404 npm error 404 Note that you can also install from a npm error 404 tarball, folder, http url, or git url. npm error A complete log of this run can be found in: D:\ruanjian\install\node\node_cache_logs\2026-07-29T10_10_29_753Z-debug-0.log PS D:\software\project\tuge-esim-kiosk>报错原因:包名写错了
官方 CLI 包名不是@anthropic-ai/claude,正确包名:@anthropic-ai/claude-code,所以之前拉取直接 404。
正确的安装命令:
npm install -g @anthropic-ai/claude-code回车成功之后找到该目录,会出现这个三个文件,该目录就是第一步执行的命令出现的目录。这样就表示安装成功了。
在从idea的Terminal窗口输入claude,出现下图内容表示已经好了
这个整体的前提是,我在搜索窗口搜索PowerShell,点击之后输入自己的秘钥,然后回车,配置电脑的全局环境变量,把秘钥加进去
