github / github/copilot-cli

sessionStart hook doesn't print to terminal and doesn't run at CLI startup

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

描述

### Describe the bug

I followed the hooks tutorial here: https://docs.github.com/en/copilot/tutorials/copilot-cli-hooks

However, nothing gets printed at CLI startup.

I edited my session-banner script to add to the audit log that the tutorial sets up:

```
$ErrorActionPreference = "Stop"

Write-Host @"
COPILOT CLI POLICY ACTIVE
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
• Prompts and tool use may be logged for auditing
• High-risk commands may be blocked automatically
• If something is blocked, follow the guidance shown
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
"@

# NEW CODE BELOW

$logDir = "./logs"
if (-not (Test-Path $logDir)) {
New-Item -ItemType Directory -Path $logDir -Force | Out-Null
}

$logEntry = @{
event = "sessionStart"
timestamp = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds()
} | ConvertTo-Json -Compress

Add-Content -Path "$logDir/audit.jsonl" -Value $logEntry

Write-Host "🚀 XBC Copilot session started — hooks active."
exit 0
```

And when I look at the audit.jsonl, the sessionStart entry is _after_ the userPromptSubmitted:
```
{"event":"userPromptSubmitted","timestampMs":1774043873173,"cwd":"E:\\xbc1","prompt":"copilot launched at 2:57:45. It is now past that. There is no log in .github\\hooks\\logs. I followed the hooks guide here (https://docs.github.com/en/copilot/tutorials/copilot-cli-hooks) but sessionStart doesn't actually start at sessionStart."}
{"event":"sessionStart","timestamp":1774043874301}
{"toolName":"report_intent","toolArgs":"{\"intent\": \"Debugging CLI hooks setup\"}","event":"preToolUse"}
{"toolArgs":"","event":"preToolUse","toolName":"fetch_copilot_cli_documentation"}
```

### Affected version

GitHub Copilot CLI 1.0.10

### Steps to reproduce the behavior

Follow the guide https://docs.github.com/en/copilot/tutorials/copilot-cli-hooks , then open copilot. Observe that nothing gets printed at session startup.

Update the session-banner to the one I described above. Re-run copilot, ask it any question, then observe the log at `.github/hooks/logs/audit.jsonl`. It should show that sessionStart actually fires after userPromptSubmitted... which is weird???

### Expected behavior

I would have expected sessionStart to start at copilot CLI startup... _AND_ I would expect the sessionStart's stdout to show up in the CLI. Otherwise, what was the point of sessionStart? It explicitly states that the sessionStart hook "Shows an informational message when a new agent session starts or resumes.", which seems to be false. It also says "Any output from this hook is ignored by Copilot CLI, which makes it suitable for informational messages." , but if it doesn't actually show the message, how is it informational?

### Additional context

_No response_

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

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