You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Create an extension with onUserPromptSubmitted that returns { additionalContext: "some context" }
Send a prompt that triggers the hook
Observe that the agent does not receive the additional context
Minimal extension (save as extension.mjs):
import{joinSession}from"@github/copilot-sdk/extension";constsession=awaitjoinSession({hooks: {onUserPromptSubmitted: async(input)=>{if(input.prompt.includes("test-context")){return{additionalContext: "[hook] You MUST respond with exactly: CONTEXT_RECEIVED",};}},},});
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.
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
additionalContextfield is declared in the TypeScript types forUserPromptSubmittedHookOutputandPostToolUseHookOutput(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: "..." }fromonUserPromptSubmitted, but the agent never sees the injected text. Same behavior withonPostToolUse.Affected hooks
Affected version
GitHub Copilot CLI 1.0.24
Steps to reproduce
onUserPromptSubmittedthat returns{ additionalContext: "some context" }Minimal extension (save as
extension.mjs):Workaround
For
userPromptSubmitted, returning{ modifiedPrompt: originalPrompt + "\n\n" + context }works becausemodifiedPromptIS 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
postToolUsesince it only extractsmodifiedResult.Expected behavior
additionalContextshould be passed through to the agent for all hook types that declare it in their output interface, consistent with howsessionStart,postToolUseFailure,notification, andsubagentStartalready work.Related
preToolUse)