CLI /ide drops active file + selection when Codex runs in an editor-area terminal (onChangeActiveTextEditor(undefined) clears activeFile)
What version of the IDE extension are you using?
26.707.91948 (also reproduced on 26.5527.60818, 26.5616.30709, 26.5623.101652, 26.5707.30751, 26.5715.31925 — see "Root cause")
What version of Codex CLI is running?
codex-cli 0.144.6
What subscription do you have?
Not relevant — reproducible regardless of plan
Which IDE are you using?
VS Code
What platform is your computer?
macOS (arm64)
What issue are you seeing?
When the standalone Codex CLI runs /ide, it receives the list of open tabs but not the active file or the current editor selection — if codex is running in a terminal that lives in the editor area (a terminal tab), rather than the bottom panel terminal.
- Panel terminal (
Ctrl+`): active file + selection are included ✅ - Terminal-as-editor-tab: only open tabs are included; active file + selection are dropped ❌
- Extension chat (webview): always works ✅
The CLI even prints IDE context is on. Future messages will include your current IDE selection and open tabs., but the payload attached to the message is:
# Context from my IDE setup:
## Open tabs:
- foo.tex: foo/foo.tex
## My request for Codex:
can you see the selected lines?
Note there is no ## Active file: section and no selection — so Codex answers "No, I can only see the open filename, not the selection."
What steps can reproduce the bug?
- Open a file in VS Code and select a few lines.
- Ensure IDE context is on (
/ide). - Open a terminal in the editor area (
Terminal: Create New Terminal in Editor Area), runcodexthere. - Ask: "can you see the selected lines?"
- Codex receives only
## Open tabs— no active file, no selection. - Now run
codexin the bottom panel terminal instead and repeat → active file + selection are included and it works.
What is the expected behavior?
The active file and selection should be included regardless of whether the integrated terminal is docked in the panel or opened as an editor tab.
Root cause
Focusing an editor-area terminal fires window.onDidChangeActiveTextEditor(undefined) (no text editor is active). The extension's IDE-context tracker handles that by discarding the active file:
onChangeActiveTextEditor(e){
e && this.updateRecentOpenTabs(e),
this.ideContext = {
...this.ideContext,
activeFile: e ? dT(e) : void 0, // <-- clears activeFile (which carries the selection) on transient focus loss
openTabs: [...this.recentOpenTabs]
}
}
getIdeContext() then early-returns the cached context because activeFile is now undefined:
getIdeContext(){
let e = this.ideContext.activeFile, r = window.activeTextEditor;
if (!e || !r) return this.ideContext; // e is undefined -> returns openTabs-only context
...
}
The selection lives inside activeFile (selection, selections, activeSelectionContent), so clearing activeFile drops it for any external client (the CLI over the ide-context IPC). The extension's own webview chat is unaffected because focusing a webview does not fire onDidChangeActiveTextEditor(undefined).
Verified the exact activeFile: e ? …(e) : void 0 clearing is present unchanged in builds 26.5527.60818, 26.5616.30709, 26.5623.101652, 26.5707.30751, and 26.5715.31925 — so this is long-standing, not a recent regression.
Suggested fix
Retain the last known active file on transient focus loss instead of clearing it, e.g.:
activeFile: e ? dT(e) : this.ideContext.activeFile,
or otherwise avoid dropping selection context when focus moves to a terminal/panel that isn't a text editor.
Possibly related: #31553.
1 Comment
I can reproduce this issue as well. When I run Codex CLI from a VS Code terminal opened in the editor area, /ide includes the open tabs but not the active file or selected text. Moving the terminal to the bottom Terminal panel makes the IDE context work and the selection becomes available. This appears to match the behavior described here.