What would you like to be added?
Refactor IDE mode context injection so that IDE context (active file, cursor position, selected text, open files) is merged into the user's message instead of being injected as separate role: 'user' Content entries in the API history.
Currently (client.ts:766-778), IDE context is added via addHistory() as an independent user message before each turn:
if (this.config.getIdeMode() && !hasPendingToolCall) {
// ...
this.getChat().addHistory({
role: 'user',
parts: [{ text: contextParts.join('\n') }],
});
}
The proposed change is to wrap IDE context in XML tags (e.g. <ide_context>) and prepend it to the user's actual prompt, so each turn still has exactly one user Content entry in the API history.
Why is this needed?
This is the root cause of #3644 — /rewind is disabled in IDE mode because the extra user Content entries break the UI-to-API turn mapping in computeApiTruncationIndex() (historyMapping.ts:73-126).
The current workaround is a hard guard (AppContainer.tsx:1694):
if (config.getIdeMode()) return; // rewind completely disabled in IDE mode
By merging IDE context into the user message, the 1:1 turn mapping is preserved and /rewind works in IDE mode without any changes to the rewind logic itself.
This approach aligns with how Claude Code handles IDE context — as attachments that get merged into user messages with XML tag wrappers rather than injected as separate API messages.
Additional context
Files involved:
| File |
Change |
packages/core/src/core/client.ts |
Merge IDE context into user prompt instead of addHistory() |
packages/cli/src/ui/AppContainer.tsx |
Remove IDE mode guard on rewind |
packages/cli/src/ui/utils/historyMapping.ts |
Update comments (IDE warning no longer applies) |
packages/cli/src/ui/components/RewindSelector.tsx |
Strip IDE tags from display text / resubmit |
Regression test matrix:
- IDE mode: basic conversation, delta context, tool calls, compression, resume
- IDE mode + rewind (the fix target)
- CLI mode: no regression
- Resubmit (UP arrow): IDE tags stripped, only user input preserved
Related: #3644
What would you like to be added?
Refactor IDE mode context injection so that IDE context (active file, cursor position, selected text, open files) is merged into the user's message instead of being injected as separate
role: 'user'Content entries in the API history.Currently (
client.ts:766-778), IDE context is added viaaddHistory()as an independent user message before each turn:The proposed change is to wrap IDE context in XML tags (e.g.
<ide_context>) and prepend it to the user's actual prompt, so each turn still has exactly one user Content entry in the API history.Why is this needed?
This is the root cause of #3644 —
/rewindis disabled in IDE mode because the extra user Content entries break the UI-to-API turn mapping incomputeApiTruncationIndex()(historyMapping.ts:73-126).The current workaround is a hard guard (
AppContainer.tsx:1694):By merging IDE context into the user message, the 1:1 turn mapping is preserved and
/rewindworks in IDE mode without any changes to the rewind logic itself.This approach aligns with how Claude Code handles IDE context — as attachments that get merged into user messages with XML tag wrappers rather than injected as separate API messages.
Additional context
Files involved:
packages/core/src/core/client.tsaddHistory()packages/cli/src/ui/AppContainer.tsxpackages/cli/src/ui/utils/historyMapping.tspackages/cli/src/ui/components/RewindSelector.tsxRegression test matrix:
Related: #3644