Home / Blog / How to clean up the worktrees Claude Code, Cursor and Codex…
Tech News

How to clean up the worktrees Claude Code, Cursor and Codex leave behind

Coding agents in Claude Code, Cursor, and Codex leave orphaned worktrees that amass up to 100 GB of isolated dependencies across local repositories.

By Dillip Chowdary • Nov 16, 2026 • Source: mopup.online

How to clean up the worktrees Claude Code, Cursor and Codex leave behind
Image: mopup.online

At a glance

Product
Coding agent worktrees
Affected tools
Claude Code, Cursor, Codex
Maximum disk usage
100 GB across 61 worktrees
Codex crash footprint
4.9 GB in pending reports
Cursor retention default
25 worktrees
Codex retention default
15 worktrees

Developer tooling teams across Anthropic, Cursor, and OpenAI rely on git worktrees to execute multiple coding agent sessions in parallel, but leftover environments quietly consume tens of gigabytes of disk space according to mopup.online's report. Each agent creates a complete local checkout with its own dependency folders and build artifacts, which persist long after automated tasks complete.

This guide details the exact filesystem paths where Claude Code, Cursor, and Codex store worktrees, the disk footprints recorded across real projects, and how developers can safely verify and prune orphaned environments. Understanding these storage patterns helps software teams maintain clean local repositories while running multi-agent workflows.

01Disk usage across agent worktrees

A single agent worktree duplicates the full storage footprint of a fresh project clone alongside its installed dependencies. Real-world measurements reveal that a Laravel checkout with 530 MB in node_modules and 350 MB in vendor files reached 9.9 GB across ten worktrees. In larger codebases, 61 Codex worktrees on a Rails application consumed roughly 100 GB, while a Claude Code user reported 27 abandoned worktrees occupying 80 GB.

ToolDefault worktree storage locationAutomatic cleanup policyMeasured project disk impact
Claude Code CLI.claude/worktrees/<name>Cleans unnamed clean sessions on exit; 30-day sweep for subagents80 GB across 27 worktrees (issue 63087)
Claude Desktop.claude/worktreesSweeps 30 days after session archive or final accessDepends on local node_modules size
Cursor~/.cursor/worktrees/<repository>/<name>Retains newest 25 worktrees; deletes 30 seconds after archiveProportional to project dependencies
OpenAI Codex~/.codex/worktreesRetains 15 most recent sessions; snapshot taken at archive100 GB across 61 worktrees (issue 35383)

Note: Automatic sweeps have deleted git-ignored image directories and unpushed submodule modifications, making manual commits or stashes essential before archiving agent sessions.

02Storage directories and automatic sweep policies

Different agent tools manage isolation through distinct filesystem locations and retention thresholds. Claude Code places worktree folders inside the repository under .claude/worktrees on dedicated branches, though older releases used ~/.claude-worktrees.

Cursor isolates checkouts globally in ~/.cursor/worktrees, pruning environments beyond its 25-item default cap. Codex maintains up to 15 checkouts under ~/.codex/worktrees on detached HEAD states instead of named branches.

To inspect existing worktrees and measure their storage consumption across local repositories, developers can query git and standard directory utilities directly.

Command
git worktree list
du -sh .claude/worktrees/* 2>/dev/null | sort -h
du -sh ~/.cursor/worktrees// 2>/dev/null | sort -h
du -sh ~/.codex/worktrees/* 2>/dev/null | sort -h

03Verification checks before removing checkouts

Removing a worktree permanently destroys git-ignored files such as local environment configurations, dependency trees, and compiled assets. Developers must verify that no uncommitted modifications or untracked assets remain in the target path before initiating deletion.

Advertisement

Tech Pulse Daily

Get tomorrow's pulse first

Join engineers who read Tech Pulse before stand-up. Free, weekday mornings.

  1. Working tree check run git -C <path> status --short to ensure the worktree has no uncommitted changes.
  2. Ignored file review run git -C <path> status --short --ignored to list untracked or ignored files before deletion.
  3. Branch integration check run git log --oneline main..<branch> or inspect pull request merges via the GitHub CLI.
  4. Detached commit audit run git -C <path> log --oneline HEAD --not --branches --remotes for Codex worktrees to verify no orphaned commits exist.

After verifying that every commit is integrated, checkouts associated with GitHub squash merges require validation using the gh tool.

Command
gh pr list --head <branch> --state merged --json number,headRefOid
git rev-parse <branch>

04Pruning commands and crash report cleanup

Once active sessions are terminated, checkouts can be removed directly through git porcelain commands. Git blocks deletion if uncommitted files are detected, preserving changes unless forced. Background runs like claude -p may leave a lock file, which developers must clear before removal.

Command
git worktree remove <path>
git worktree unlock <path>
git branch -d <branch>
git worktree prune -n
git worktree prune

In addition to worktree growth, specific Codex desktop builds generated runaway crash logs that accumulated 4.9 GB and 54,504 files within a single day. Developers can inspect and empty these directories when disk space degrades.

Command
du -sh ~/Library/Application\ Support/Codex/Crashpad/pending ~/Library/Application\ Support/com.openai.codex/web/Crashpad/pending 2>/dev/null

05Configuration parameters to control worktree growth

Preventing unbounded storage accumulation requires adjusting retention settings within each agent's configuration files. Claude Code users can reduce cleanupPeriodDays below its 30-day default and activate automatic archiving upon pull request merge inside the desktop application. Cursor users can decrease cursor.worktreeMaxCount below 25, while Codex users can lower its 15-worktree threshold in preferences.

Teams using pnpm can mitigate duplicate storage across multiple checkouts by configuring shared virtual store packages.

Command
virtualStoreType: global

By enforcing global dependency sharing, each agent checkout links to a central package cache rather than generating redundant local node_modules directories.

Frequently asked questions

Why do coding agent worktrees consume tens of gigabytes of disk space?

Each agent checkout replicates the repository along with distinct node_modules and vendor dependencies, causing cumulative disk growth across concurrent sessions.

How does git worktree removal handle ignored files like .env?

Removing a worktree deletes ignored and build files without prompting, requiring manual inspection with git status --ignored before running deletion commands.

How can teams prevent duplicate dependency installations across agent worktrees?

Projects using pnpm can set virtualStoreType to global, allowing all worktrees to reference a single shared package store.

Sources

Dillip Chowdary

Author

Dillip Chowdary

Writes Tech Bytes coverage of AI, engineering, and the tools that actually ship. Editor of Tech Pulse Daily.

Related on Tech Bytes

Advertisement

5-min tech signal

Weekday briefing for engineers who skip the noise.

No spam · Unsubscribe anytime

Advertisement

✈️ CareerPilot

Your AI job-search copilot

Match your resume against live Ashby, Greenhouse & Lever openings — fit scores, job-specific resume optimization and email alerts.

Find matching jobs →

Free Tools

Browse all tools →