Skip to content

PostToolUse hook additionalContext not injected into same-turn model request #311138

@digitarald

Description

@digitarald

Bug

A PostToolUse hook that returns additionalContext successfully executes and returns the context, but the context is not injected into the tool result for the model request on the same turn. It only becomes visible in subsequent turns when conversation history is replayed.

This means a hook designed to influence the model's immediate next action (e.g., "before presenting this plan, run a review skill") has no effect — the model never sees the instruction on the turn it matters.

Reproduction

  1. Configure a PostToolUse hook that matches the memory tool and returns additionalContext:
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "memory",
        "hooks": [
          {
            "type": "command",
            "command": "node ${PLUGIN_ROOT}/hooks/remind-plan-review.mts"
          }
        ]
      }
    ]
  }
}
  1. The hook script outputs:
{
  "hookSpecificOutput": {
    "hookEventName": "PostToolUse",
    "additionalContext": "Before presenting the plan to the user, you MUST use the 'review-plan' skill"
  }
}
  1. Trigger the hook by having the agent call the memory tool to create a plan.md file.

Evidence from debug logs

Timestamp (ms) Event Detail
604432 tool_call (memory) Completed successfully
604457 hook (PostToolUse) Ran in 118ms, resultKind: "success", returned additionalContext
604467 llm_request Sent to model — tool result contains only "File created successfully at: /memories/session/plan.md"
  • The additionalContext text ("Before presenting the plan...") appears 0 times in the inputMessages of the same-turn llm_request (line 33 of main.jsonl).
  • The same text appears in every subsequent llm_request (line 44+), because the conversation history now includes the PostToolUse-context annotation from the transcript.

Expected behavior

The additionalContext from a PostToolUse hook should be appended to the tool result before the next model request on the same turn, so the model can act on it immediately.

Actual behavior

The additionalContext is recorded in the transcript but not injected into the tool result for the same-turn model call. It only becomes visible on the next user message turn, making it too late to influence the model's behavior.

Version

  • VS Code Insiders (version from session log)
  • Copilot Chat extension

Metadata

Metadata

Assignees

Labels

bugIssue identified by VS Code Team member as probable bugcopilot-chat

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions