Two Codex tasks can use different branches and still damage each other's work if they share one checkout. A Git worktree gives each task its own files and index without downloading the repository history again. It does not give either task its own server, credentials or network.
We treat a worktree as a temporary workspace with an owner and an exit condition. This guide covers that workspace lifecycle on a Linux VPS, not how to split a feature between agents; our parallel workflow guide covers the latter.
Codex Git worktrees: what is actually separate?
The official Codex worktree guide describes desktop-managed checkouts, Handoff and cleanup. Those application features are not the same as manually creating a linked Git worktree over SSH. Here we use ordinary Git commands and run Codex inside the directory we chose. We are not claiming Office Claws implements Codex's desktop Handoff or automatic worktree restoration.
| State | Separate in a linked worktree? | Operator responsibility |
|---|---|---|
| Working files, index and HEAD | Yes | Assign one task to each checkout |
| Git objects, branch refs and repository configuration | Shared | Coordinate fetches and branch-changing operations |
| Dependencies and ignored files | Not copied by ordinary Git worktree creation | Recreate reviewed development setup |
| Unix user, home and credentials | No | Use stronger isolation for different trust levels |
| Ports, databases, CPU and RAM | No | Allocate resources and test services explicitly |
A different directory is not a sandbox. Two processes running as the same Unix user can generally reach each other's files and home directory, subject to any additional sandbox controls. Use separate users, suitably configured containers or separate VPS hosts when the trust boundary requires it. Keep Codex sandbox and approval settings in place independently.
Run your first agent in about 3 minutes
Install the Office Claws CLI, connect your Contabo account and Codex subscription, and your agent gets its own VPS and a desk in the office.
curl -fsSL https://officeclaws.com/downloads/install.sh | sh$4.99/mo + your own Contabo VPS · keys stay in your keychain
Create a pinned workspace before starting Codex
Start in an existing clone that you own. Check its remote and working state first. The example creates a new branch and sibling directory from the fetched main commit. Run it once per task, changing both names; it deliberately does not reset or reuse an existing task directory.
git remote -v
git status --short
git fetch origin
base=$(git rev-parse --verify origin/main)
git worktree add -b task/docs-audit ../codex-docs-audit "$base"
git worktree list
cd ../codex-docs-audit
pwd
git rev-parse HEAD
git status --short
codex --version
codexStop if the remote is wrong, the starting clone contains unexplained changes, or any command fails. Record the base commit, absolute worktree path, task branch and Codex session identity in an operator-owned run record outside the checkout. Avoid --force when Git says the branch is already checked out elsewhere: inspect git worktree list and choose a new branch or finish the existing task.
Review dependency-install scripts before executing them. Ordinary git worktree add does not copy an ignored .env, dependency directory or local database from the main checkout. Do not fix missing configuration by copying production credentials. Prefer dummy development values and a task-specific test database. Codex desktop's documented .worktreeinclude behavior is application-specific; do not assume it applies to this SSH workflow.
Give the task a file boundary and a concrete validation command. For example, a docs audit can inspect source and update documentation but must not change runtime code or deploy anything. Capture failures as failures, not as permission to expand scope.
Validate the workspace, not just the branch name
Before a second task starts, reserve its own development port and database or schema. Different worktrees can still connect to the same database, overwrite a shared output directory or contend for memory during builds. A worktree does not add ChatGPT-plan capacity or bypass usage limits; see our subscription cost guide.
Inside each task directory, inspect the candidate before accepting it:
git status --short
git diff --stat
git diff --check
git diffThese commands inspect uncommitted changes. After changes are committed, compare the recorded base commit with the candidate commit as well; an empty working-tree diff is not evidence that the branch has no changes. Also inspect untracked files: ordinary git diff does not show their contents. Run the repository's actual tests or build in this worktree and record the commands, exit results and candidate commit. Install dependencies separately if required; do not claim tests ran just because they passed yesterday in the main checkout.
Keep one owner for integration. Agents should not concurrently rebase shared branches, change repository-wide Git settings or delete each other's workspaces. Review and merge the candidate through your normal human gate. For a stable review target, use the base and head commit identities described in our Codex code review guide.
Retire the worktree without losing the handoff
Completion is not the moment Codex stops typing. Before removing a workspace, we check:
- No agent, test watcher or development server still owns the directory.
- Intended changes are committed, reviewed and retained in an approved remote branch or merged history; local commits alone are not an off-host backup.
- Untracked and ignored files have been inspected, including local configuration and test artifacts that Git status may omit.
- Required reports and logs are retained outside the directory with appropriate access controls, and the task's base and candidate commit IDs are recorded.
Only after those checks, return to the original clone and use Git's normal removal command:
git worktree remove ../codex-docs-audit
git worktree listThis removes the worktree directory; it does not delete the task branch. Do not add --force if removal refuses: find out what remains and preserve it deliberately. Do not rely on refusal as a backup mechanism—ignored files can still be lost. git worktree prune cleans stale administrative records; it is not a substitute for reviewing or backing up task output. Deleting a branch is a separate, reviewed housekeeping step.
Our recommendation: begin with one temporary worktree for a bounded task and prove the setup, validation and retirement process before increasing concurrency. Office Claws provisions and helps you monitor Codex agents on your own VPS; the Git lifecycle above remains an operator-managed practice, not a promised automatic feature. An always-on VPS keeps the machine available, not the model working without limits or human review. For host setup, follow running Codex on a VPS; for runner visibility, see monitoring Codex agents.
Sources: OpenAI's Codex worktree documentation and the Git worktree manual. The examples above describe manually managed Git worktrees, not the desktop app's managed-worktree retention policy.