Skip to content

The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.

Desktop on Windows: Codex from the Codex app starts (#115)

riverisbuilding1baa02b16969
diff --git a/.changeset/codex-windows-app-copy.md b/.changeset/codex-windows-app-copy.md
new file mode 100644
index 0000000..de6cdcb
--- /dev/null
+++ b/.changeset/codex-windows-app-copy.md
@@ -0,0 +1,5 @@
+---
+"@openfilm/desktop": patch
+---
+
+Desktop on Windows: Codex starts for people who have the Codex app. OpenFilm used the codex.exe inside the app's Microsoft Store folder, which Windows lets no other program start ("Access is denied"); it now uses the copy the Codex app itself starts, in %LOCALAPPDATA%\OpenAI\Codex\bin, and never a program inside a Store app's folder.
diff --git a/apps/desktop/src/agent-installation.mjs b/apps/desktop/src/agent-installation.mjs
index 8d53739..4968677 100644
--- a/apps/desktop/src/agent-installation.mjs
+++ b/apps/desktop/src/agent-installation.mjs
@@ -59,9 +59,17 @@ const LAUNCHERS = [
/[\\/](?:Microsoft VS Code|Visual Studio Code)[^\\/]*[\\/]/i,
];
+/**
+ * A Microsoft Store app's own folder (C:\Program Files\WindowsApps\<name>_<version>_<arch>__<publisher>\…): Windows
+ * lets no other program start what is in it ("Access is denied"). Its commands (…\Microsoft\WindowsApps\<name>.exe)
+ * are elsewhere and start.
+ */
+const STORE_PACKAGE = /[\\/]WindowsApps[\\/][^\\/]+_[^\\/]*__[0-9a-z]+[\\/]/i;
+
/**
* Why a program found or chosen for an agent is not the agent, or null: `app`, an editor's or a desktop app's own
- * launcher (on Windows, a window program too); `not-cursor-agent`, one for Cursor outside Cursor's own folder.
+ * launcher (on Windows, a window program too, and anything inside a Store app's own folder); `not-cursor-agent`, one
+ * for Cursor outside Cursor's own folder.
* `chosen`: what the person chose, when `file` is what it runs.
* @returns {'app' | 'not-cursor-agent' | null}
*/
@@ -69,6 +77,7 @@ export function notTheAgent(id, file, { chosen = null, win = windows } = {}) {
const real = (p) => { try { return realpathSync(p); } catch { return p; } };
const paths = [file, real(file), ...(chosen ? [chosen, real(chosen)] : [])];
if (paths.some((p) => LAUNCHERS.some((re) => re.test(p)))) return 'app';
+ if ([file, chosen].some((p) => p && STORE_PACKAGE.test(p))) return 'app';
if (win && /\.exe$/i.test(file) && exeSubsystem(real(file)) === WINDOW_SUBSYSTEM) return 'app';
if (id === 'cursor' && !inCursorFolder(file)) return 'not-cursor-agent';
return null;
@@ -358,6 +367,17 @@ function codexInApps(/** @type {string[]} */ applicationDirs) {
return applicationDirs.flatMap((dir) => ['Codex.app', 'ChatGPT.app'].flatMap((app) => CODEX_IN_APP.map((p) => join(dir, app, p)))).filter(executableFile);
}
+/**
+ * The copies of Codex the Codex app for Windows starts: it can't start the one in its Store folder either, so it keeps
+ * one in %LOCALAPPDATA%\OpenAI\Codex\bin, in a folder per build (`bin\<build>\codex.exe`). The latest written first.
+ */
+export function codexAppCopies(home = homedir()) {
+ const bin = join(localAppData(home), 'OpenAI', 'Codex', 'bin');
+ const at = (file) => { try { return statSync(file).isFile() ? statSync(file).mtimeMs : -1; } catch { return -1; } };
+ return [...folders(bin, /./).map((dir) => join(dir, 'codex.exe')), join(bin, 'codex.exe')]
+ .map((file) => ({ file, time: at(file) })).filter((c) => c.time >= 0).sort((a, b) => b.time - a.time).map((c) => c.file);
+}
+
/* where OpenCode is inside OpenCode.app, its desktop app (macOS) */
const OPENCODE_IN_APP = 'Contents/Resources/opencode-cli';
@@ -415,8 +435,9 @@ export function detectAgentInstallation(id, { home = homedir(), env = process.en
}
}
const usable = (file) => (win ? presentFile(file) : executableFile(file));
- /* copies kept up to date by the maker's app (Codex: or a Store app), and how their version is told */
- const copies = id === 'codex' ? [...codexInApps(applicationDirs), ...others.filter(usable)] : id === 'opencode' ? opencodeInApps(applicationDirs) : [];
+ /* copies kept up to date by the maker's app (Codex: the Mac apps', or the one the Windows app starts), and how their
+ version is told */
+ const copies = id === 'codex' ? [...codexInApps(applicationDirs), ...(win ? codexAppCopies(home) : []), ...others.filter((f) => usable(f) && !notTheAgent(id, f, { win }))] : id === 'opencode' ? opencodeInApps(applicationDirs) : [];
const versionOf = id === 'opencode' ? opencodeVersionOf : codexVersionOf;
if (cli) {
/* Claude Code both on the PATH (an npm install that is never updated, say) and in the Claude app, which keeps its
@@ -436,7 +457,7 @@ export function detectAgentInstallation(id, { home = homedir(), env = process.en
}
cli = copies[0] ?? null;
if (!cli && id === 'claude') cli = claudeAppCli(home, { win });
- if (!cli) cli = others.find(usable) ?? null;
+ if (!cli) cli = others.find((f) => usable(f) && !notTheAgent(id, f, { win })) ?? null;
return { installed: Boolean(cli), cli, source: cli ? 'app' : null, install };
}
diff --git a/apps/desktop/src/agent-installation.test.mjs b/apps/desktop/src/agent-installation.test.mjs
index 267a722..a5b6f4a 100644
--- a/apps/desktop/src/agent-installation.test.mjs
+++ b/apps/desktop/src/agent-installation.test.mjs
@@ -1,9 +1,9 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
-import { mkdirSync, mkdtempSync, symlinkSync, writeFileSync } from 'node:fs';
+import { mkdirSync, mkdtempSync, symlinkSync, utimesSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
-import { AGENT_INSTALLERS, chosenProgram, claudeAppCli, claudeVersion, cmdTarget, codexVersion, consoleProgram, desktopApp, detectAgentInstallation, findExecutable, installCommand, laterVersion, notTheAgent, opencodeVersion, searchReport, windowsBinDirs } from './agent-installation.mjs';
+import { AGENT_INSTALLERS, chosenProgram, claudeAppCli, codexAppCopies, claudeVersion, cmdTarget, codexVersion, consoleProgram, desktopApp, detectAgentInstallation, findExecutable, installCommand, laterVersion, notTheAgent, opencodeVersion, searchReport, windowsBinDirs } from './agent-installation.mjs';
test("an npm .cmd shim (Windows) runs its package's script: that is what gets started", () => {
const npm = mkdtempSync(join(tmpdir(), 'of-npm-'));
@@ -444,3 +444,21 @@ test('the report says which file is not the agent, and why', () => {
assert.equal(report.files[0].refused, 'app');
assert.equal(report.files[0].usable, false);
});
+
+test("Codex on Windows: never the copy in the Store app's own folder, which Windows won't start; the copy the Codex app starts", () => {
+ if (process.platform === 'win32') return;
+ const home = mkdtempSync(join(tmpdir(), 'of-home-'));
+ const store = put(join(home, 'Program Files', 'WindowsApps', 'OpenAI.Codex_26.1002.7124.0_x64__2p2nqsd0c76g0', 'app', 'resources', 'codex.exe'));
+ assert.equal(notTheAgent('codex', store, { win: true }), 'app');
+ assert.equal(notTheAgent('codex', store, { chosen: store, win: true }), 'app');
+ /* a Store app's command is not in its folder, and starts */
+ assert.equal(notTheAgent('codex', join(home, 'AppData', 'Local', 'Microsoft', 'WindowsApps', 'codex.exe'), { win: true }), null);
+ const none = { home, env: { PATH: '' }, pathDirs: [], applicationDirs: [], win: true, codexVersionOf: () => null };
+ assert.equal(detectAgentInstallation('codex', { ...none, others: [store] }).cli, null);
+ const bin = join(home, 'AppData', 'Local', 'OpenAI', 'Codex', 'bin');
+ const old = put(join(bin, '5d35d2790d1d3d7b', 'codex.exe'));
+ const recent = put(join(bin, '247581e40ee272fb', 'codex.exe'));
+ utimesSync(old, new Date(2026, 9, 1), new Date(2026, 9, 1));
+ assert.deepEqual(codexAppCopies(home), [recent, old]);
+ assert.deepEqual(detectAgentInstallation('codex', { ...none, others: [store] }), { installed: true, cli: recent, source: 'app', install: detectAgentInstallation('codex', none).install });
+});
diff --git a/apps/desktop/src/agents.mjs b/apps/desktop/src/agents.mjs
index 12719c3..76bf9ca 100644
--- a/apps/desktop/src/agents.mjs
+++ b/apps/desktop/src/agents.mjs
@@ -33,7 +33,7 @@ import { Readable, Writable } from 'node:stream';
import { fileURLToPath } from 'node:url';
import * as acp from '@agentclientprotocol/sdk';
import { PATH_SEP, childEnvironment, lastPathSource, loginShellEnvironment, loginShellVariables, shellSubset } from './environment.mjs';
-import { AGENT_PROGRAMS, HOME_BIN_CANDIDATES, chosenProgram, codexVersion, consoleProgram, desktopApp, detectAgentInstallation, installCommand, laterVersion, notTheAgent, searchReport } from './agent-installation.mjs';
+import { AGENT_PROGRAMS, HOME_BIN_CANDIDATES, chosenProgram, codexAppCopies, codexVersion, desktopApp, detectAgentInstallation, installCommand, laterVersion, notTheAgent, searchReport } from './agent-installation.mjs';
import { logSwitches } from './agent-logs.mjs';
import { mergeConfig, sessionSkills } from './agent-skills.mjs';
import { nodeBinary } from './node-runtime.mjs';
@@ -189,32 +189,23 @@ export function codexLaunchEnv(/** @type {string} */ path, { win = windows, dir
return { CODEX_PATH: path };
}
}
-/** what the slower search found last (Windows): npm's global folder, Codex inside a Microsoft Store app */
-let slowFound = { npmPrefix: null, storeCodex: null };
+/** what the slower search found last (Windows): npm's global folder */
+let slowFound = { npmPrefix: null };
let slowCache = null;
const SLOW_FOR_MS = 10 * 60_000;
-/* an OpenAI app from the Microsoft Store (ChatGPT, Codex) that carries Codex: where its codex.exe is */
-const STORE_CODEX = "Get-AppxPackage -Name 'OpenAI.*' | ForEach-Object { Get-ChildItem -LiteralPath $_.InstallLocation -Recurse -Depth 5 -Filter codex.exe -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName }";
/**
* Windows only, and only when an agent is not found the quick way: where npm puts global commands (a prefix of the
- * person's own that is not on their PATH), and Codex inside an OpenAI app from the Microsoft Store. Asked again after
- * ten minutes, or at once with `fresh`.
+ * person's own that is not on their PATH). Asked again after ten minutes, or at once with `fresh`.
*/
function windowsSlowSearch({ fresh = false } = {}) {
if (!windows) return Promise.resolve(slowFound);
if (slowCache && !fresh && Date.now() - slowCache.at < SLOW_FOR_MS) return slowCache.value;
const value = (async () => {
const env = childEnvironment({ shell: await loginShellEnvironment() });
- const [npm, store] = await Promise.all([
- run(process.env.ComSpec || 'cmd.exe', ['/d', '/s', '/c', 'npm prefix -g'], 15_000, { env }),
- run('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', STORE_CODEX], 20_000, { env }),
- ]);
+ const npm = await run(process.env.ComSpec || 'cmd.exe', ['/d', '/s', '/c', 'npm prefix -g'], 15_000, { env });
const prefix = npm.ok ? npm.stdout.trim().split(/\r?\n/).pop()?.trim() : null;
- /* the Codex app's own window program is a codex.exe too (`app\Codex.exe`, the filter ignores case): only a console
- program is the CLI */
- const exe = store.ok ? store.stdout.split(/\r?\n/).map((l) => l.trim()).find((l) => /codex\.exe$/i.test(l) && isAbsolute(l) && consoleProgram(l)) : null;
- slowFound = { npmPrefix: prefix && isAbsolute(prefix) ? prefix : null, storeCodex: exe && isAbsolute(exe) ? exe : null };
+ slowFound = { npmPrefix: prefix && isAbsolute(prefix) ? prefix : null };
return slowFound;
})().catch(() => slowFound);
slowCache = { at: Date.now(), value };
@@ -234,7 +225,6 @@ export function resolveAgentCli(id, { pathDirs = [] } = {}) {
env: { PATH: pathDirs.join(PATH_SEP) },
pathDirs: searchDirs(),
chosen: chosenPaths[id] ?? null,
- others: id === 'codex' && slowFound.storeCodex ? [slowFound.storeCodex] : [],
});
return found.cli ? { path: found.cli, source: found.source } : null;
}
@@ -329,7 +319,7 @@ export async function diagnoseAgent(id, { appVersion = '' } = {}) {
`Found: ${found ? `${found.path} (${found.source})` : '(not found)'}`,
...(windows ? [
`npm global folder: ${slow.npmPrefix ?? '(unknown)'}`,
- ...(id === 'codex' ? [`Codex in a Store app: ${slow.storeCodex ?? '(none)'}`] : []),
+ ...(id === 'codex' ? [`Codex the Codex app starts: ${codexAppCopies()[0] ?? '(none)'}`] : []),
`In WSL: ${found ? '(not checked)' : wsl ?? '(no)'}`,
] : []),
'',
@@ -603,9 +593,8 @@ export async function openAgentInstaller(id) {
export async function listAgents() {
/* looked at as the person comes back from installing one: a PATH from a few seconds ago at most */
const pathDirs = (await loginShellEnvironment({ maxAgeMs: 10_000 })).PATH.split(PATH_SEP);
- /* the slower search (Windows): always, as it finds Codex inside a Store app, which may be later than one on the PATH
- (resolveAgentCli takes the later); waited for, a few seconds at most, when one is not found the quick way. What it
- finds later is there on the next look */
+ /* the slower search (Windows): waited for, a few seconds at most, when one is not found the quick way. What it finds
+ later is there on the next look */
if (windows) {
const slow = windowsSlowSearch();
if (Object.keys(AGENTS).some((id) => !resolveAgentCli(id, { pathDirs }))) {