Skip to content

additionalContext silently dropped for userPromptSubmitted and postToolUse extension hooks #2652

@Arithmomaniac

Description

@Arithmomaniac

Note

This issue was filed by the GitHub Copilot CLI (v1.0.24) on behalf of a user, while debugging an extension that wasn't working as expected.

Describe the bug

The additionalContext field is declared in the TypeScript types for UserPromptSubmittedHookOutput and PostToolUseHookOutput (in @github/copilot-sdk), but returning it from an extension hook has no effect -- the value is silently discarded at runtime.

This was discovered while building an extension that needs to inject context based on the user's prompt (e.g., detecting a project reference and prompting the agent to ask the user about switching directories). The extension returns { additionalContext: "..." } from onUserPromptSubmitted, but the agent never sees the injected text. Same behavior with onPostToolUse.

Affected hooks

Hook additionalContext in types? Actually works at runtime?
sessionStart Yes Yes
userPromptSubmitted Yes No -- dropped
preToolUse Yes No -- dropped (see #2585)
postToolUse Yes No -- dropped
postToolUseFailure Yes Yes
notification Yes Yes
subagentStart Yes Yes

Affected version

GitHub Copilot CLI 1.0.24

Steps to reproduce

  1. Create an extension with onUserPromptSubmitted that returns { additionalContext: "some context" }
  2. Send a prompt that triggers the hook
  3. Observe that the agent does not receive the additional context

Minimal extension (save as extension.mjs):

import { joinSession } from "@github/copilot-sdk/extension";

const session = await joinSession({
    hooks: {
        onUserPromptSubmitted: async (input) => {
            if (input.prompt.includes("test-context")) {
                return {
                    additionalContext: "[hook] You MUST respond with exactly: CONTEXT_RECEIVED",
                };
            }
        },
    },
});
  1. Send a prompt containing "test-context" -- the agent will NOT respond with "CONTEXT_RECEIVED" because it never sees the injected context.

Workaround

For userPromptSubmitted, returning { modifiedPrompt: originalPrompt + "\n\n" + context } works because modifiedPrompt IS extracted. But this is a hack -- it pollutes the user's visible prompt text rather than injecting separate system-level context.

There is no workaround for postToolUse since it only extracts modifiedResult.

Expected behavior

additionalContext should be passed through to the agent for all hook types that declare it in their output interface, consistent with how sessionStart, postToolUseFailure, notification, and subagentStart already work.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions