Give each coding agent its own working folder
Running two coding agents in the same project folder can get confusing. One agent edits a file while the other reads it. A checkout changes underneath an active task. Uncommitted changes become difficult to attribute.
A Git worktree gives you another working folder for the same repository, with its own checked-out branch. Your agents share repository history, but each gets separate project files to edit. Think of two desks connected to the same filing cabinet.
This first run uses one agent to implement a small feature and another to write supporting documentation. You stay responsible for reviewing and combining their work.
Create two branches in two sibling folders
Start in your existing repository. Run git status and commit or safely set aside unfinished changes before continuing. These instructions assume your current commit is the starting point you want both agents to use.
Create a branch for reviewing the combined result:
git switch -c integrate/agent-run
Then create two worktrees on new branches:
git worktree add -b agent/feature ../project-feature HEAD
git worktree add -b agent/docs ../project-docs HEAD
The folder names are examples; choose names that do not already exist. Both branches start at the same commit. Your original folder stays on integrate/agent-run, while the two sibling folders hold the agents' branches.
Run git worktree list to check the paths and branches. Normally, Git will not let the same branch be checked out in two worktrees at once. Separate branches are part of the setup, not an optional extra.
Assign tasks with explicit file boundaries
Open one terminal in each new folder, then launch your coding tool there. For example, run Claude Code in project-feature and Codex in project-docs. Check each terminal's current directory before starting.
Give each agent a narrow assignment and clear limits:
- Feature agent: Add input validation to the settings form. Edit application code and relevant tests only. Run the relevant tests, report the results, and commit your changes. Do not merge branches.
- Documentation agent: Document the planned validation rules from the supplied requirements. Edit documentation only. Report any assumptions and commit your changes. Do not merge branches.
Provide the same requirements to both agents. The documentation agent cannot automatically see uncommitted implementation changes in the other folder, so ask it to flag details that need confirmation rather than invent behavior.
Keep dependencies and running services separate
Worktrees separate tracked files, not everything your tools touch. Each folder may need its own dependency installation. Ignored files, such as local environment settings, are not automatically copied from your original folder.
Supply required configuration securely rather than committing secrets. If both agents start development servers, give them different ports. For tests that modify data, use separate test databases or other isolated resources.
You can also use SwiftRelay with compatible coding tools to manage model access through a pay-as-you-go relay. It works with Claude Code, Codex, and Gemini CLI, with billing per token. Sign up for SwiftRelay if you want to try this setup with the small gift credit provided to new accounts. The worktree workflow itself remains the same regardless of your model provider.
Review and merge one agent branch at a time
Wait until both agents have finished and committed their intended changes. Ask each for a short handoff covering changed files, checks run, and unresolved questions.
Back in your original folder, inspect each contribution:
git diff HEAD...agent/feature
git diff HEAD...agent/docs
Merge the feature first with git merge --no-ff agent/feature, then merge the documentation with git merge --no-ff agent/docs. If conflicts appear, resolve them deliberately. Separate worktrees prevent shared-folder interference; they do not guarantee conflict-free changes.
Run the relevant checks again on the combined branch. Confirm that the documentation describes the actual implementation, not just the original plan.
Remove worktrees after the handoff is complete
Once you have verified the combined result, check each worktree for uncommitted or untracked files you still need. Stop any processes running there, then use git worktree remove ../project-feature and git worktree remove ../project-docs.
Your integration branch now contains the combined work for your normal review process. The repeatable pattern is simple: separate folders, bounded tasks, individual commits, and one human-reviewed merge at a time.