Windows: Codex leaves orphaned Q*.tmp temp files in the working directory (not cleaned up)
Open 💬 4 comments Opened Aug 6, 2026 by freedally
💡 Likely answer: A maintainer (github-actions[bot], contributor)
responded on this thread — see the highlighted reply below.
Summary
On Windows, Codex (CLI/Desktop) leaves orphaned Q<8-hex>.tmp files directly in the current working directory / project root and also accumulates the same pattern in %TEMP%. These temp files are never cleaned up.
- Project working directory: 100+ files appeared while running Codex shell commands.
%TEMP%: 7000+ files of the sameQ*.tmpformat accumulated (mostly from 2026-08-03/04 while using Codex CLI).
The files match the Rust tempfile crate naming style (Q prefix + random hex + .tmp), and codex.exe embeds nix_tempfile::handle::Writable plus sandbox tmpdir/slash_tmp path concepts.
Reproduction / Evidence
- Control experiment: while no shell command was executed for 60 s, the tmp count stayed constant (
118 -> 118). As soon as Codex shell commands ran, the count grew (105 -> 118 -> 123). - Not caused by a version update: this issue was already observed the day before this report, independent of any
codex-command-runnerupdate on the reporting day. The temp files are written to the working directory instead of%TEMP%. - File contents share a common template (magic bytes
scz+ shared prefix), i.e. they are produced by the same writer. - Files are ignored by
.gitignore(*.tmp) so they do not pollute git status, but they still pollute the workspace.
Expected behavior
- Temp files should be written to the OS temp directory (
%TEMP%), not the current working directory / project root. - Temp files should be cleaned up automatically after the command/process exits (or at least bounded retry/cleanup), instead of accumulating unboundedly.
Related issues
- #36428 (feature request: clean up temp files created by codex under /tmp on exit)
- #33311 (Windows Codex Desktop repeatedly leaves thousands of temp files in %TEMP%)
Environment
- Windows 10/11, Codex CLI / Desktop (API-key session)
4 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
To clarify the relationship with #36428: they are related but address different problems.
/tmpon exit (cleanup lifecycle).%TEMP%in the first place? #36428 does not cover this aspect.On this machine the temp files are created in the project root (the current working directory) and accumulate there, polluting the workspace. Even a proper cleanup-on-exit would not fix the wrong placement. This report is specifically about:
%TEMP%), andBoth are needed to fully address the issue.
I implemented a candidate fix for the Windows temporary-file leak:
%TEMP%.TEMP,TMP, andTMPDIRare rewritten case-insensitively so child processes cannot fall back to the project working directory.4c9440e8dMy account cannot create the upstream PR because it has read-only permissions on
openai/codex. Please review the fork PR or cherry-pick the commit.The fork PR above (and #36428's cleanup-on-exit) is the right endgame — I won't argue that a fix isn't the real answer, and nothing I'm sharing is meant as a replacement for that work.
I'm commenting because the project-root part of this is the exact gap I work on from the outside: the working directory is the one thing every tool and every future agent session shares, and once
Q*.tmpfiles land there, nothing in the workspace distinguishes them from real work. I maintain workspace-metabolism, a zero-dependency Python CLI where one policy file decides what each path is worth; cleanup moves items to a recycle area instead of deleting (dry-run by default), and every action lands in a hash-chained journal with exactrollback.For the 100+ files already in the project root, the read-only
auditis a ~30-second check on a copy of a workspace — no writes unless you explicitly ask:It's early days (v0.2, no external users yet), so I'm specifically looking for feedback on whether audit → recycle → rollback is a useful middle step for residue that's already accumulated and unreferenced, or whether a plain delete-all is the only honest answer until the upstream fix ships. Either answer is useful.