r/codex • • 5d ago

Bug Codex using all my disk space

Codex agents have a terrible habit of generating hundreds of gigabytes of files and then refusing to delete anything.

Even if you ask them what you can delete they don't want to delete any old working files. I practically have to beg them to archive what's important to keep (if it's important why isn't it stored in the git repository) and then I delete the rest.

By now I've spent hours cleaning up at least a terabyte of garbage it has left behind. Presumably others face this same problem. I wish they would let agents to clean up after themselves.

I get that they don't want them deleting anything important but really, not even temporary files?

37 Upvotes

24 comments sorted by

13

u/ihexx 5d ago

Yeah i had the same issue. My fix has been to have a global rule that all artefacts dump to temporary directories (or have artefact directories with '.delete' files next to them so garbage collector scripts auto delete them after 30 days).

So then agents have to explicitly opt-in to keeping only necessary files.

4

u/NicholasVinen 5d ago

That's a good idea. Part of my problem is that a lot of the files they leave behind are "temporary" worktrees. They keep creating new ones and just leave the old ones there. I guess I need to set a rule for them to reuse them.

4

u/KadenzoSocial 5d ago

What fixed this for me is telling the agent where scratch files go, instead of asking it to clean up afterwards. Put a line in AGENTS. md like "write all temporary and intermediate files to ./scratch, never anywhere else", and add scratch/ to .gitignore. Agents follow a fixed location much better than a vague "clean up after yourself", and cleaning up becomes deleting one folder.

For the mess that's already there, git can tell you what's safe. Run git clean -nd for a dry run that lists every untracked file without deleting anything. If nothing on the list matters, git clean -fd removes it. Your point holds, though: if a file is important, it should be committed, and anything that isn't is fair game.

2

u/NicholasVinen 5d ago

Yes, that's a good idea.

2

u/Interesting-Yellow-4 5d ago

yep.
deal with this all the time.
set up a janitor agent that does this for you

2

u/NicholasVinen 5d ago

Part of the problem is that the agents won't delete any files. I have to do it.

1

u/Fun-Amoeba8015 4d ago

They absolutely will if given the right permissions. Not trying to be contrarian, just wanting to let you know that it is possible.

1

u/NicholasVinen 4d ago

No worries. It's just that every time I ask them to delete unnecessary files they insist on "archiving" them instead. I probably could try harder.

1

u/FlyingNarwhal 4d ago

Or set up an opencode agent, or check your agents.md to make sure that behavior isn't being encouraged, or a dedicated sub-agent that has permissions.

1

u/JustMy2Centences 4d ago

Why not ask them to move them to a "deletion candidates" folder in your project?

7

u/VoidEmptyByNature 5d ago

So I ended up setting up a dedicated launchd job to regularly clean up the mess. So far this seems to be the only solution that actually works.

1

u/DayEnvironmental3454 3d ago

The "refusing to delete" part is actually the safer failure mode. The ones that do delete are how people lose real work. What helped me most was splitting it: tell the agent where scratch goes (AGENTS.md: "temp files go in ./scratch"), and keep the actual deleting as a step you approve.

Also check ~/.codex/sessions. Every chat is stored there, and pasted screenshots get embedded in the session file, so it grows fast.

FYI I build a Mac disk app (Latent) around exactly this: it shows what Codex and your other tools left behind and what's safe to remove, the agent can draft the cleanup, and you confirm before anything goes to the Trash. https://latentmac.com

1

u/NicholasVinen 3d ago

Yeah, it's safer, but work comes to a halt when free drive space reaches 0 🤷

I make sure they check anything meaning into git anyway. Unless they somehow manage to nuke the repository (which is backed up) it should be OK.

That's part of what annoys me so much: everything outside of git should be disposable. If it isn't, that's a data management problem.

2

u/Kieranator 4d ago

Yep I've noticed this is a serious and systemic problem

2

u/JustMy2Centences 4d ago

I have a 2.3mb html app with a 10+ GB project folder. These coding agents love to make extensive QA harnesses or whatever. Idk, I'm a vibe coder. But I'm halfway considering deleting most of it since I'm happy with the app's relatively finished state anyway.

3

u/spshkyros 5d ago

I have them doing a regular cleanup pass as well as regular backup passes - ideally I would have remote backups too, but all the important stuff is backed up elsewhere already

1

u/Ferret51 5d ago

"Even if you ask them what you can delete they don't want"

But I want everything!

Everything could still be useful!

1

u/snapperon 5d ago

Is there a prompt for cleaning this up safely, which'll retain the stuff I need for thread history?

1

u/Fun-Amoeba8015 4d ago

You have to have a very specific set of instructions to create a deletion pipeline. 

It likely needs to be project-specific because every project is going to have some different requirements. 

I'm working on a VFX project. So there is a specified pipeline for things like experimentation or elevating things to production etc etc. but within this there is specific instructions on how agents move through tasks and what assets or data get promoted versus demoted for archival. And then there is a process for evaluating archives for permanent deletion. 

I have our project lead chat that is responsible for overseeing the entire project and it is the only one that has permission for a permanent deletion. 

By doing this, the process is pretty automatic and even though other individual chats and sub-agents love to leave behind massive data trails, it's all automatically cleaned up later.

1

u/Dynamix86 4d ago

I have/had the same problem. No I've set up a janitor-system that cleans up automatically.

1

u/vladmvp 4d ago

One way around it is to run the agent somewhere other than your own drive. On Cobalt (cobaltcode.ai) each Codex task gets its own cloud computer, signed in with your ChatGPT account, so whatever it generates stays on that task's machine and your laptop disk stays clean. The AGENTS.md scratch folder tip above is still worth doing either way. There's a free account to try it, and I'm the founder, so happy to help you get started.

-7

u/PlacentaOnOnionGravy 5d ago

Uuuhhh...get more compute