-
Notifications
You must be signed in to change notification settings - Fork 1.3k
sessionStart hook fires on every user message, not once per session #2491
Description
Describe the bug
sessionStart hook fires on every user message, not once per session
Version: GitHub Copilot CLI 1.0.16
OS: macOS (Darwin)
Description
The sessionStart hook fires on every user message within a conversation, not just once when the session is first created. Additionally, a sessionEnd hook fires after each agent response, before the next user message triggers sessionStart again. This makes sessionStart/sessionEnd behave as per-turn events rather than true session lifecycle events.
This is problematic for hooks that perform expensive one-time setup (dependency installation, environment provisioning, etc.) — they re-run on every single message.
Steps to Reproduce
- Create a hooks file at
.github/hooks/test-hook.json:
{
"version": 1,
"hooks": {
"sessionStart": [
{
"type": "command",
"bash": "echo 'SESSION_START fired' >> /tmp/copilot-hook-test.log",
"cwd": ".",
"timeoutSec": 10
}
]
}
}- Clear the log and start Copilot with debug logging:
rm -f /tmp/copilot-hook-test.log
copilot --log-level debug --log-dir ./logs- Send a first message (e.g.,
"hello") - Wait for the response
- Send a second message (e.g.,
"hello again") - Wait for the response
- Send a third message (e.g.,
"one more") - Check the log:
cat /tmp/copilot-hook-test.logExpected Result
SESSION_START fired
sessionStart should fire once — when the session is first initialized.
Actual Result
SESSION_START fired
SESSION_START fired
SESSION_START fired
Debug logs also confirm a sessionEnd fires after each agent response, creating a start/end cycle per turn:
20:29:20Z Executing hook: sessionStart ← message 1
20:29:45Z Executing hook: sessionEnd ← response 1 complete
20:29:59Z Executing hook: sessionStart ← message 2
20:30:04Z Executing hook: sessionEnd ← response 2 complete
20:30:27Z Executing hook: sessionStart ← message 3
Impact
Any hook registered under sessionStart that performs expensive or non-idempotent work (installing dependencies, provisioning resources, sending notifications) will execute redundantly on every conversation turn, adding latency and unnecessary side effects.