openai / openai/codex

Windows codex-retention.ps1 hardcodes repository path for git worktree prune

Open
#43,483 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug session windows-os
Dominant language
Rust
Stars
125k
Forks
19.4k
PR merge metrics
PR metrics pending

Description

Summary

I use codex-retention.ps1 to prevent local .codex/sessions growth. On my machine this helper grew to +100GB until I started pruning monthly. During cleanup I found a safety issue: the script hardcodes the prune target to C:\Users\User\Projects\agenthost-internal.

If the script is shared across machines (or users), this can:

  • run prune against a nonexistent or wrong repo,
  • silently do nothing in setups where that path differs,
  • or, worse, prune the wrong repo if another checkout exists at that hardcoded path.

This is risky on machines with multiple Codex worktrees and can lead to unexpected git state drift.

Repro

  1. Run powershell -NoProfile -File C:\Users\User\Scripts\codex-retention.ps1 on a Windows machine where the hardcoded path is not the current repo.
  2. If cleanup deletes old files, script reaches git worktree prune phase.
  3. It still executes against the hardcoded root path rather than the active repo.

Expected

Retention utility should prune worktrees only for the repo it actually operated on (or an explicitly passed repo root), not a fixed absolute path.

Observed

Prune root is hardcoded:

  • git -C C:\Users\User\Projects\agenthost-internal ... (older behavior)
  • not derived from active location or invocation context.

Impact

  • Inconsistent cleanup behavior across users/machines
  • Potential wrong-repo prune operations
  • Increased operational risk after long sessions where retention script is used manually (exactly when disk pressure is highest)

Fix (suggested)

  • Resolve repo root from current location (git rev-parse --show-toplevel) with safe fallback.
  • Validate detected root contains .git before running git worktree prune.
  • Keep behavior opt-in / no-op if no valid repo root is detected.
  • Optionally accept an explicit -WorktreePruneRoot parameter.

I implemented this safely in local workaround and can share patch details if useful. The rest of cleanup logic was unchanged.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate codex-retention.ps1 and trace the git worktree prune command reached after cleanup. Start by checking how the script determines its active location, then verify the prune target is derived safely or explicitly supplied and that invalid roots become a no-op. Reproduce with the documented PowerShell invocation on a machine without the hardcoded path.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, powershell
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
70/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.