Skip to content

Linux 终端启动失败:claude 命令未找到 Linux terminal launch fails: claude command not found (PATH missing ~/.local/bin due to --norc --noprofile) #2402

@hasibagen

Description

@hasibagen

Self Checks / 自检

CC Switch Version / 版本号

3.14。1

Operating System / 操作系统

Linux

Related App / 涉及应用

Claude Code

Steps to Reproduce / 重现步骤

  1. 通过官方脚本安装 Claude Code:curl -fsSL https://claude.ai/install.sh | bash(安装到 ~/.local/bin/claude)
  2. 确保 ~/.local/bin 在 PATH 中(在 .bashrc 中添加:export PATH="$HOME/.local/bin:$PATH")
  3. 打开 CC Switch 应用,选择一个 Claude provider
  4. 点击终端启动按钮(例如为项目打开终端)
  5. 在启动的终端中看到错误:claude: command not found

Expected Behavior / 期望行为

终端应成功启动 Claude Code 并使用提供商特定的配置文件。由于 ~/.local/bin 已在用户的 .bashrc 中正确配置,claude 命令应能被找到并执行。

Actual Behavior / 实际行为

终端显示错误:
Using provider-specific claude config:
/tmp/claude_e9e9a082-c265-4e5c-bd7d-2e83df42e6f6_1455548.json
/tmp/cc_switch_launcher_1455548.sh: 行 7: claude: 未找到命令
bash-5.2$

生成的启动脚本内容:
#!/bin/bash
trap 'rm -f "/tmp/claude_..." "/tmp/cc_switch_launcher_..."' EXIT
cd '/home/mind/project/...'
echo "Using provider-specific claude config:"
echo "/tmp/claude_..."
claude --settings "/tmp/claude_..."
exec bash --norc --noprofile

Additional Context / 补充信息

在 src-tauri/src/commands/misc.rs 第 1104 行(Linux 终端启动器),脚本模板存在两个问题:

  1. 硬编码 claude 命令名:脚本直接写 claude --settings "...",而不是使用完整路径或动态查找可执行文件位置。官方安装脚本将 claude 安装到 ~/.local/bin/claude,这个路径依赖用户 .bashrc 中的 PATH
    配置才能被找到。
  2. exec bash --norc --noprofile:最后一行启动 bash 时使用了 --norc --noprofile 参数,跳过 .bashrc 和 .bash_profile 的加载。结果是新 shell 的 PATH 不包含
    ~/.local/bin,即使该路径在用户配置中已正确设置。

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions