claude-code - 💡(How to fix) Fix UserPromptSubmit hook additionalContext not injected into model context in VSCode extension [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#49063Fetched 2026-04-17 08:51:58
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×5commented ×1

A UserPromptSubmit hook that outputs valid {"additionalContext": "..."} JSON to stdout executes successfully but the content never reaches the model context. The same hook mechanism works as expected in CLI.

Root Cause

A UserPromptSubmit hook that outputs valid {"additionalContext": "..."} JSON to stdout executes successfully but the content never reaches the model context. The same hook mechanism works as expected in CLI.

Code Example

"UserPromptSubmit": [{
     "hooks": [{
       "type": "command",
       "command": "python path/to/hook.py",
       "timeout": 10
     }]
   }]

---

{"additionalContext": "Current time: 2026-04-16 16:28 ..."}
RAW_BUFFERClick to expand / collapse

Environment

  • Claude Code VSCode Extension (tested on v2.1.109+)
  • Windows 11, Python 3.x
  • Hook registered in ~/.claude/settings.json under hooks.UserPromptSubmit

Summary

A UserPromptSubmit hook that outputs valid {"additionalContext": "..."} JSON to stdout executes successfully but the content never reaches the model context. The same hook mechanism works as expected in CLI.

Reproduction

  1. Register a UserPromptSubmit hook in settings.json:
    "UserPromptSubmit": [{
      "hooks": [{
        "type": "command",
        "command": "python path/to/hook.py",
        "timeout": 10
      }]
    }]
  2. The hook script reads stdin JSON, builds context, outputs:
    {"additionalContext": "Current time: 2026-04-16 16:28 ..."}
  3. Open VSCode, start a new Claude Code conversation
  4. Ask the model: "What startup context did you receive from hooks?"
  5. Model reports: none received

Evidence that the hook DID execute

  • Hook writes a state file on successful execution → file exists with correct session_id and timestamp
  • Running the hook manually with echo '{"session_id":"test"}' | python hook.py produces valid JSON output
  • A second hook (session_reset.py) registered on the same event also executes and writes its own state file

Evidence that additionalContext is NOT injected

  • Model explicitly reports no startup context received
  • No <user-prompt-submit-hook> tag visible in conversation
  • No time/memory/backlog content visible anywhere in model context

What works

  • Hook triggering: ✅
  • Hook script execution: ✅
  • Hook stdout output (valid JSON with additionalContext): ✅
  • Stop hook blocking feedback (non-zero exit): ✅ (reaches model)
  • CLAUDE.md loading: ✅
  • MCP tool calls: ✅

What doesn't work

  • UserPromptSubmit hook additionalContext → model context: ❌

Expected behavior

Per Claude Code hooks documentation, additionalContext returned from a hook's stdout should be appended to the model's context for that turn. This works in CLI but not in the VSCode extension.

extent analysis

TL;DR

The UserPromptSubmit hook's additionalContext is not being injected into the model context, suggesting a potential issue with how the VSCode extension handles hook output.

Guidance

  • Verify that the hook.py script is correctly outputting the additionalContext JSON to stdout, and that the JSON is properly formatted.
  • Check the VSCode extension's documentation and settings to ensure that it is configured to capture and forward hook output to the model context.
  • Investigate potential differences in how the CLI and VSCode extension handle hook execution and output, as the issue only occurs in the VSCode extension.
  • Consider adding logging or debugging statements to the hook.py script to confirm that it is executing correctly and producing the expected output in the VSCode extension environment.

Example

No code snippet is provided as it is not clearly supported by the issue, but an example of how to add logging to the hook.py script could be:

import logging
import json

# ... (rest of the script)

logging.basicConfig(level=logging.INFO)
# ... (rest of the script)
print(json.dumps({"additionalContext": "Current time: 2026-04-16 16:28 ..."}))
logging.info("Hook output: %s", json.dumps({"additionalContext": "Current time: 2026-04-16 16:28 ..."}))

Notes

The issue may be specific to the VSCode extension or its configuration, and further investigation is needed to determine the root cause.

Recommendation

Apply workaround: Modify the hook.py script to log its output and verify that it is executing correctly in the VSCode extension environment, to help identify the issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Per Claude Code hooks documentation, additionalContext returned from a hook's stdout should be appended to the model's context for that turn. This works in CLI but not in the VSCode extension.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix UserPromptSubmit hook additionalContext not injected into model context in VSCode extension [1 comments, 2 participants]