github / github/copilot-cli

Cross-tool  .claude/settings.local.json  hooks with shell operators ( || ,  && ) break on Windows PowerShell

未关闭
#4,399 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

area:configuration area:platform-windows
主要语言
Shell
星标
11.2k
派生
1.9k
平均合并
14 小时 16 分钟
30 天内合并 PR
6

描述

Describe the bug

When a repository contains a Claude Code hook config ( .claude/settings.local.json  or  .claude/settings.json ) with a  PreToolUse  hook defined via a single cross-platform  command  string containing POSIX shell operators (e.g.  ... || echo {} ), Copilot CLI fails to execute that hook correctly on Windows, which can block all subsequent tool calls gated by that hook.

Root cause hypothesis:
Claude Code executes these same hook commands via git-bash on Windows, so  || / &&  work there. Copilot CLI's cross-tool compatibility layer, per the hooks reference, reads  .claude/settings*.json  files but runs the single  command  string as the native Windows  powershell  fallback rather than replicating Claude Code's git-bash execution context. This makes any Claude hook authored with POSIX-only shell syntax silently non-functional (and blocking) on Windows.

Affected version

No response

Steps to reproduce the behavior
  1. On Windows, in a repo, create  .claude/settings.local.json  with:
    {
    "hooks": {
    "PreToolUse": [
    {
    "matcher": "Bash",
    "hooks": [
    { "type": "command", "command": ""C:\path\to\tool.exe" some-check || echo {}" }
    ]
    }
    ]
    }
    }
  2. Launch  copilot  in a native Windows PowerShell (5.1) terminal in that repo.
  3. Attempt any shell/Bash tool call.
Expected behavior

Expected behavior:
The hook executes successfully and either allows or blocks the tool call based on its actual logic, consistent with how the same config works under Claude Code.

Actual behavior:
The tool call is blocked.  /env  confirms the hook is loaded ("preToolUse: N hooks, source: repo settings"), but the underlying command fails silently, because  ||  is invalid syntax in Windows PowerShell 5.1 — the shell that Copilot CLI uses to run the hook (per the docs, the  command  field is used as a fallback for both  bash  and  powershell  execution).

Additional context

Windows 11 Enterprise, PowerShell terminal (Windows PowerShell 5.1, not  pwsh  7+)

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用 .claude/settings.local.json 或 .claude/settings.json、使用 || 的 PreToolUse 命令,以及 Windows PowerShell 5.1 中的 Copilot CLI 重现该问题。检查 /env 以确认 hook 的来源,并观察命令是否在 Bash 工具调用期间失败。当 hook 成功执行,并根据其结果允许或阻止工具调用时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
powershell, shell
领域
cli
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。