Skip to content

Shell 模式(Ctrl+X)应使用用户默认 Shell 而非固定 /bin/sh || Shell mode (Ctrl+X) should use the user default Shell instead of the fixed /bin/sh #2122

@scottli139

Description

@scottli139

Shell 模式(Ctrl+X)应使用用户默认 Shell 而非固定 /bin/sh

问题描述

在 zsh(或 fish 等)环境下启动 Kimi Code CLI 后,按 Ctrl+X 进入 Shell 模式,输入的命令实际上是由 /bin/sh 执行的,而不是用户当前的默认 Shell。

复现步骤

  1. 确保当前终端为 zsh:echo $SHELL/bin/zsh
  2. 启动 kimi
  3. Ctrl+X 切换到 Shell 模式
  4. 输入 echo $0 或尝试使用 zsh 别名/函数

实际结果

命令由 /bin/sh 执行,zsh 的别名、函数、插件扩展语法均不可用。

期望结果

Shell 模式应识别并复用用户的默认 Shell(通过 $SHELL 环境变量),或者在 asyncio.create_subprocess_shell() 时通过 executable= 参数显式指定。

相关代码位置

kimi_cli/ui/shell/__init__.py 第 739 行左右:

# TODO: For the sake of simplicity, we now use `create_subprocess_shell`.
proc = await asyncio.create_subprocess_shell(command, env=get_clean_env(), **kwargs)

asyncio.create_subprocess_shell 在 POSIX 上默认使用 /bin/sh。建议通过 executable=os.environ.get("SHELL", "/bin/sh") 传入用户默认 Shell。

另外,kimi_cli/utils/environment.py 中的 Environment.detect() 目前只检测 bash/sh,建议扩展为优先检测 $SHELL,以支持 zsh、fish 等常用 Shell。

使用场景

  • 使用 zsh 别名(如 llgs 等)加速操作
  • 依赖 zsh 函数或特定语法的脚本/命令
  • 保持与终端一致的行为,降低上下文切换成本

环境信息

  • OS: macOS / Linux
  • Shell: zsh
  • kimi-cli version: latest

Shell mode (Ctrl+X) should use the user default Shell instead of the fixed /bin/sh

Problem description

After starting Kimi Code CLI in the zsh (or fish, etc.) environment, press Ctrl+X to enter Shell mode. The entered command is actually executed by /bin/sh instead of the user's current default Shell.

Reproduction steps

  1. Make sure the current terminal is zsh: echo $SHELL/bin/zsh
  2. Start kimi
  3. Press Ctrl+X to switch to Shell mode
  4. Type echo $0 or try using zsh alias/function

Actual results

The command is executed by /bin/sh, and zsh's aliases, functions, and plug-in extension syntax are not available.

Expected results

Shell mode should recognize and reuse the user's default shell (via the $SHELL environment variable), or specified explicitly via the executable= parameter when asyncio.create_subprocess_shell().

Relevant code location

kimi_cli/ui/shell/__init__.py around line 739:

# TODO: For the sake of simplicity, we now use `create_subprocess_shell`.
proc = await asyncio.create_subprocess_shell(command, env=get_clean_env(), **kwargs)

asyncio.create_subprocess_shell defaults to /bin/sh on POSIX. It is recommended to pass in the user default Shell through executable=os.environ.get("SHELL", "/bin/sh").

In addition, Environment.detect() in kimi_cli/utils/environment.py currently only detects bash/sh. It is recommended to extend it to detect $SHELL first to support common shells such as zsh and fish.

Usage scenarios

  • Use zsh aliases (such as ll, gs, etc.) to speed up operations
  • Scripts/commands that rely on zsh functions or specific syntax
  • Maintain consistent behavior with the terminal and reduce context switching costs

Environment information

  • OS: macOS/Linux
  • Shell: zsh
  • kimi-cli version: latest

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions