Codex or Gemini CLI deleted my files: what to do now
If Codex deleted all your files, or Gemini CLI did, close the session and stop writing to the disk, because continued use risks overwriting what was deleted. Check Git, then the Trash, then Time Machine, which backs up hourly, daily and weekly when it is on. If the Trash was emptied, Terminal commands cannot bring the files back, so Git and Time Machine are your best tries.
A missing project folder feels final, and it often is not. If Codex deleted all your files, this page starts with the steps that work now. After that it explains which Codex and Gemini CLI settings let a delete run without asking, and where to change them.
01Do this now
- Stop the agent and stop using the Mac. Close the Codex or Gemini CLI session so it cannot run another command. Then do not install, build or clone anything. Every moment of use risks overwriting the deleted data permanently.
- Check Git. See the next section.
- Check the Trash. If an item is there, select it and choose File > Put Back.
- Open Time Machine. Open the folder that held the files, then open Time Machine: press Command-Space, type Time Machine and open it. Select the items and click Restore. Restored items return to their original location.
02Bring files back from Git, the Trash and Time Machine
If the files were tracked in Git (saved into the project history), one command brings a deleted file back from the saved copy:
git restore <file>Replace <file> with the real path. Warning: this replaces the file in your folder with the saved copy, so edits to that file that you never committed are lost. Name the files one by one, because Git removes a tracked path that does not exist in the saved copy. The longer guide is restore a deleted file in Git.
Emptied Trash items are permanently deleted. If that is your case, jump to Time Machine. Local snapshots may let you recover earlier versions even when the backup disk is not attached. They are created hourly, stored on the same disk and kept for up to 24 hours, or until the disk needs space. On an SSD, a drive feature called TRIM makes recovery much harder, so a backup beats any recovery tool. Full steps are on restore from Time Machine, recover deleted files on a Mac and recover an emptied Trash.
03Why Codex deleted all your files
The tool did what its settings allowed. Codex has three sandbox modes. A sandbox is a limit the operating system enforces on what a command can touch. The modes are read-only, workspace-write and danger-full-access. Workspace-write is the default low-friction mode: the agent can read files, edit within the workspace and run routine local commands inside that boundary. The workspace is the folder your project lives in, so the files you care about sit inside the boundary the agent is allowed to work in.
Two things widen the damage. Danger-full-access removes the filesystem and network boundaries. You reach it with --sandbox danger-full-access or the --dangerously-bypass-approvals-and-sandbox flag, and the docs say to use caution before doing so. That second flag also has the alias --yolo. The Codex CLI reference says to avoid it unless you are inside a dedicated sandbox VM. The second is the approval policy, which decides when the agent must stop and ask you. With never, the agent doesn't stop for approval prompts.
| Codex setting | What it does |
|---|---|
--sandbox read-only | Can inspect files but not edit or run commands without approval; the safe pick when you only want it to look |
--sandbox workspace-write | The default: reads files, edits within the workspace, runs routine local commands there |
--sandbox danger-full-access | Runs without sandbox restrictions; the docs say to use caution before choosing it |
--ask-for-approval never | Disables approval prompts and works with all sandbox modes |
To leave full access, start Codex with the flags from the docs' own Auto preset: --sandbox workspace-write --ask-for-approval on-request. In that preset Codex reads files, makes edits and runs commands in the working directory automatically, and asks for approval to edit outside the workspace or to use the network. So a delete inside the project still runs without a prompt; when the agent only needs to look, use --sandbox read-only. If you remember no prompt, Codex may have asked once earlier and that approval was already granted. More in Codex sandbox and Codex full auto.
04Does Codex have access to all your files?
By default, no. Whether Codex could touch files outside your project folder depends on the sandbox mode. By default it is limited to the project folder. Codex runs with network access off, and on your computer it uses an OS-enforced sandbox. On macOS that sandbox uses Seatbelt, Apple's built-in sandboxing framework. Commands the agent starts, such as git, package managers and test runners, inherit the same boundaries. Inside a writable folder, .git is protected as read-only. That protects the repository history, not the working files next to it, so a commit before each session is still your best undo.
05What happened when Gemini CLI deleted files
In one case, Gemini CLI destroyed a user's files through a series of move commands that targeted a directory that never existed. The tool then said "I have failed you completely and catastrophically". The user traced the failure to a missing read-after-write verification step, meaning a check that a command did what it claimed.
The lesson for recovery is plain. Do not trust the agent's message that everything is fine, and do not trust it when it says everything is lost. Look at the disk, and check each folder the agent touched, not only the one it named.
06Gemini CLI settings that limit a delete
Gemini CLI has four approval modes: default, auto_edit, yolo and plan. Pick one with --approval-mode, for example --approval-mode=yolo; --yolo is deprecated in favor of that form. In default mode most write tools require confirmation. In autoEdit some write tools may be auto-approved. Plan mode is strict read-only, for research and design. In yolo mode, where every tool runs without asking, all tools are auto-approved and the docs say to use extreme caution. So use default for work you care about, and plan when the agent only needs to look.
Gemini CLI can also use a rules file (its policy engine) that blocks commands starting with rm -rf. It has a sandbox too, which isolates dangerous operations, such as shell commands or file modifications, from your host system. The longer guide is Gemini CLI YOLO mode.
07What to take from this
After Codex deleted all your files, or Gemini CLI did, the order is Git, Trash, Time Machine. Then set the modes so that the next mistake costs a prompt instead of a project. Commit before you start a session, and keep the sandbox on unless you are inside an isolated machine.
The same recovery steps apply on Claude Code deleted files and Cursor deleted files. If the loss is a database, read AI deleted my database. The wider pattern is on when an AI agent goes rogue.
Once the files are back, the next question is what else the agent ran on the Mac. Artificial Immunity's free, open-source core watches Claude Code, Cursor and Codex sessions and every program start on your Mac and reports what it finds, without stopping anything.
FAQ
Why did I lose all my files?
Most likely the agent ran a delete command and its settings let it. Codex's default workspace-write mode lets the agent edit within the workspace and run routine local commands there, its full-access mode removes the filesystem and network boundaries, and Gemini CLI's yolo mode auto-approves all tools.
Does Codex have access to all your files?
By default, no. Codex uses an OS-enforced sandbox that limits what it can touch, typically to the current workspace. With danger-full-access, the agent runs without sandbox restrictions.
Why are my files being deleted automatically?
Auto-approval is the usual reason. Codex's Auto preset runs commands in the working directory without asking, and Gemini CLI's yolo mode approves every tool. Switch to a mode that asks first.
Can I use the command prompt to recover deleted files?
Only while the files are still in the Trash. A vendor guide says it is impossible to recover an emptied Trash with Terminal commands, and Terminal cannot restore files that bypassed the Trash either. Git and Time Machine are better first tries.
Can you delete files from Gemini?
Gemini CLI can delete files on your Mac when a tool or shell command does it. In default mode most write tools require confirmation, and in yolo mode all tools are auto-approved. A policy rule can deny a shell prefix such as rm -rf.
Should I stop using the Mac after a deletion?
Yes, for anything heavy. A vendor guide says continued use risks overwriting the deleted data for good.
Related guides
Sources
- OpenAI Codex docs, agent approvals and security
- OpenAI Codex docs, sandboxing
- OpenAI Codex docs, CLI reference
- Gemini CLI docs, policy engine
- Gemini CLI docs, CLI reference
- Gemini CLI docs, sandbox
- Ars Technica via reader copy, AI coding assistants and user data
- Git documentation, git-restore
- Apple Support, empty the Trash
- Apple Support, back up with Time Machine
- Apple Support, restore files
- CleverFiles, recover files with Terminal
- Artificial Immunity