github / github/copilot-cli

preToolUse hook cwd field does not expand ~ (tilde), blocking all tool calls

未关闭
#3,664 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
area:configuration area:platform-windows area:plugins
主要语言
Shell
星标
11.2k
派生
1.9k
平均合并
14 小时 16 分钟
30 天内合并 PR
6

描述

## Describe the bug

When a `preToolUse` hook entry in `.github/hooks/*.json` uses `"cwd": "~"`, the CLI does not expand the tilde to the user's home directory. The hook script path is resolved against the literal string `~` instead of (e.g.) `C:\Users\`, causing the script to not be found. The CLI then treats this as a hook failure and **blocks all subsequent tool calls** for the session.

## Affected version

Copilot CLI 1.0.59 (Windows)

## Steps to reproduce

1. Create `.github/hooks/skill-enforcement.json`:
```json
{
"version": 1,
"hooks": {
"preToolUse": [
{
"type": "command",
"powershell": ".github/hooks/scripts/skill-gate.ps1",
"cwd": "~",
"timeoutSec": 5
}
]
}
}
```

2. Create `~/.github/hooks/scripts/skill-gate.ps1`:
```powershell
function Write-Allow { Write-Output '{"decision":"allow"}' }
Write-Allow; exit 0
```

3. Start a Copilot CLI session. All tool calls will fail/be blocked.

4. Change `"cwd": "~"` to `"cwd": "C:\\Users\\"` (absolute path) and restart. Tool calls work normally.

## Isolation testing

| Configuration | Result |
|---|---|
| Inline `Write-Output` (no script, no cwd) | ✅ Works |
| Absolute script path, no cwd | ✅ Works |
| Relative script path + absolute `cwd` (`C:\Users\`) | ✅ Works |
| Relative script path + `cwd: "~"` | ❌ **All tool calls blocked** |

The script itself is a trivial 2-line allow-all — the content is not the issue.

## Expected behavior

`"cwd": "~"` should expand to the user's home directory (e.g., `C:\Users\` on Windows, `/home/` on Linux), consistent with standard shell tilde expansion.

Alternatively, if tilde expansion is not supported, the CLI should:
1. Document this limitation
2. Fail with a clear error message rather than "hook error"

## Additional notes

- OS: Windows 11, PowerShell 7+
- CLI installed via WinGet

贡献指南

打开贡献指南

调研方向

使用提供的 .github/hooks/skill-enforcement.json 和 skill-gate.ps1 文件复现 Windows 情况,然后跟踪 CLI 对 preToolUse hook 的处理以及 cwd 解析。检查 cwd 设置为 ~ 时的行为,并与绝对路径控制用例进行对比;当 hook 从主目录运行,或在不阻止无关工具调用的情况下报告清晰的不支持路径错误时,即视为完成。

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

评估

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

把新 issue 发到你的邮箱

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