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

貢獻指南

開啟貢獻指南

研究方向

Reproduce the Windows case using the provided .github/hooks/skill-enforcement.json and skill-gate.ps1 files, then trace the CLI's preToolUse hook handling and cwd resolution. Check the behavior for cwd set to ~ alongside the absolute-path control case; done means the hook runs from the home directory or reports a clear unsupported-path error without blocking unrelated tool calls.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
powershell
領域
cli
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
冷清
描述清晰度
基本清楚
新手友好度
58/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。