--worktree starts M31A in a fresh git worktree so the agent can make changes without touching your current checkout.
Enable the feature
Worktrees are experimental and disabled by default. Set:
json
{
"experimental": {"worktrees": true}
}Then start with:
bash
m31a --worktree
m31a --worktree my-featureWithout a name, M31A generates one automatically. Using --worktree while the setting is disabled is rejected during argument validation.
Lifecycle
The implementation lives in packages/cli/src/utils/worktreeSetup.ts and packages/core/src/services/worktreeService.ts:
- Resolve the project root and verify it is a git repository.
- Create a new worktree and record the base commit SHA.
- Track the worktree so it can be cleaned up.
- Run the session inside the worktree directory.
Keep the worktree when you want to review or merge the result; remove it with the normal git worktree remove command once finished.
Good use cases
- Let the agent prototype a change while you keep working in the main checkout.
- Run parallel agent tasks on independent branches.
- Try a risky refactor with a clear rollback point.
Next steps
See Sessions and context for resume and rewind behavior inside a worktree.