Skip to content

Hooks loader supports only 6 of 13 CLI SDK hook events — missing preCompact, agentStop, subagent*, permissionRequest, notification, postToolUseFailure #211

Description

@raykao

Summary

src/core/hooks-loader.ts wires up 6 hook events:

preToolUse, postToolUse, userPromptSubmitted,
sessionStart, sessionEnd, errorOccurred

The upstream @github/copilot SDK (QueryHooks interface) supports 13:

export declare interface QueryHooks {
  preToolUse?: PreToolUseHook[];
  postToolUse?: PostToolUseHook[];
  postToolUseFailure?: PostToolUseFailureHook[];   // ← missing
  userPromptSubmitted?: UserPromptSubmittedHook[];
  sessionStart?: SessionStartHook[];
  sessionEnd?: SessionEndHook[];
  errorOccurred?: ErrorOccurredHook[];
  agentStop?: AgentStopHook[];                     // ← missing
  subagentStop?: SubagentStopHook[];               // ← missing
  subagentStart?: SubagentStartHook[];             // ← missing
  preCompact?: PreCompactHook[];                   // ← missing
  permissionRequest?: PermissionRequestHook[];     // ← missing
  notification?: NotificationHook[];               // ← missing
}

(Source: node_modules/@github/copilot/sdk/index.d.ts:11762)

The CLI hooks reference documents all 13 events: https://docs.github.com/en/copilot/reference/copilot-cli-reference/cli-hooks-reference

Why this matters

The 7 missing hooks unlock several high-value use cases that aren't possible today through the bridge:

Hook Use case
preCompact Persist context before compaction discards it — critical for memory-capture pipelines (e.g. auto-write Beads memories before tokens are dropped)
agentStop End-of-turn checkpoints; can block and force another turn (e.g. "did you write memories?" gate)
subagentStart / subagentStop Observe and control delegated agent task tool calls — important for fleet-mode/multi-agent observability
permissionRequest Programmatic allow/deny for headless / -p mode and CI; complements preToolUse
notification Inject additionalContext into session on shell completion, agent idle, etc. — async signal hooks
postToolUseFailure Provide structured recovery guidance when a tool fails (vs. just suppressing)

The most impactful is preCompact — it's the missing piece for an "auto-memory" hook similar to claude-mem's pipeline, where observed tool calls get summarised into persistent storage before the context window collapses.

Proposed change

Mostly mechanical:

  1. Extend the LoadedHooks interface in src/core/hooks-loader.ts with the 7 missing on* callbacks.
  2. Extend the EVENT_TO_SDK map with the 7 new event-name mappings.
  3. Forward them through to the SDK's QueryHooks when constructing sessions in session-manager.ts.
  4. Update docs/configuration.md (Hooks section) — currently only documents preToolUse and postToolUse; should reflect the full event list and link to the upstream CLI hooks reference.

Decision-control surface (allow/deny/block/additionalContext) for the new events is already defined by the SDK and CLI docs, so no new wire-format design is needed — the bridge just needs to forward stdin/stdout shape per event.

Scope check

  • Bridge-only change. No upstream @github/copilot SDK enhancement required — the SDK already exposes all 13 events.
  • Docs in docs/configuration.md (Hooks section) currently lists only preToolUse/postToolUse; the loader actually supports 6, so there's already a doc/code drift to close as part of this.

Happy to put up a PR if helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions