Windows codex-retention.ps1 hardcodes repository path for git worktree prune
Nobody has claimed this yet.
- 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
- Run
powershell -NoProfile -File C:\Users\User\Scripts\codex-retention.ps1on a Windows machine where the hardcoded path is not the current repo. - If cleanup deletes old files, script reaches
git worktree prunephase. - 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
.gitbefore runninggit worktree prune. - Keep behavior opt-in / no-op if no valid repo root is detected.
- Optionally accept an explicit
-WorktreePruneRootparameter.
I implemented this safely in local workaround and can share patch details if useful. The rest of cleanup logic was unchanged.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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