Skip to content

sessionStart hook fires on every user message, not once per session #2491

Closed as duplicate

Description

@demorgi

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

  1. 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
      }
    ]
  }
}
  1. Clear the log and start Copilot with debug logging:
rm -f /tmp/copilot-hook-test.log
copilot --log-level debug --log-dir ./logs
  1. Send a first message (e.g., "hello")
  2. Wait for the response
  3. Send a second message (e.g., "hello again")
  4. Wait for the response
  5. Send a third message (e.g., "one more")
  6. Check the log:
cat /tmp/copilot-hook-test.log

Expected 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:sessionsSession management, resume, history, session picker, and session state

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions