Stop-hook continuation disables Anthropic thinking and invalidates prompt cache
- Dominant language
- TypeScript
- Stars
- 193k
- Forks
- 42.4k
- PR merge metrics
- PR metrics pending
Description
### Type
Bug
### Description
In the Local agent harness, a Stop hook that blocks termination and supplies a follow-up reason makes the next Anthropic request a continuation. If the accumulated messages do not contain a thinking block yet, VS Code disables thinking for that request.
The Stop-hook follow-up consequently omits both `thinking` and `output_config.effort`, although they were present on the preceding request. Anthropic documents that changing either setting invalidates message cache entries and, depending on the model, also tool/system cache entries:
https://platform.claude.com/docs/en/build-with-claude/prompt-caching#what-invalidates-the-cache
In Cache Explorer, `cache_read_input_tokens` drops to 0 exactly on the Stop-hook follow-up.
### Steps to reproduce
1. Use an Anthropic model with thinking/effort enabled in a VS Code Local agent session.
2. Configure a Stop hook that returns a blocking result with a reason.
3. Reach that hook before the history contains a thinking block.
4. Compare the preceding request and generated follow-up in Cache Explorer.
### Actual behavior
The follow-up omits `thinking` and `output_config.effort`; the prompt cache is rebuilt and cache-read tokens fall to 0.
### Expected behavior
A Stop-hook-generated continuation preserves the conversation's thinking and effort configuration so the stable prefix remains cacheable.
### Source analysis
The Stop hook sets both `isContinuation` and `hasStopHookQuery`:
https://github.com/microsoft/vscode/blob/002b200b892a8538e2ce269631f8fabd9cbe705b/extensions/copilot/src/extension/intents/node/toolCallingLoop.ts#L434-L469
All Anthropic continuations without a thinking block then disable thinking:
https://github.com/microsoft/vscode/blob/002b200b892a8538e2ce269631f8fabd9cbe705b/extensions/copilot/src/extension/intents/node/toolCallingLoop.ts#L1890-L1894
Matching background-summarization logic:
https://github.com/microsoft/vscode/blob/002b200b892a8538e2ce269631f8fabd9cbe705b/extensions/copilot/src/extension/intents/node/agentIntent.ts#L1023-L1031
Since `hasStopHookQuery` already distinguishes the hook-generated request, the main condition could add `!context.hasStopHookQuery`; the background-summarization parity condition should add `!promptContext.hasStopHookQuery` as well.
Contributor guide
Assessment
This issue has not been assessed yet.