﻿---
title: "文件会冲突时用 worktree，不要用子代理"
summary: "子代理共享工作区和沙箱。独立提交历史、可丢弃实验、长任务不挡主工作区，用 git worktree。"
category: cloud
level: intermediate
surfaces: [cli, app]
tags: ["worktree", "并行", "隔离"]
canonical: /tips/worktree-not-subagent/
---

# 文件会冲突时用 worktree，不要用子代理

子代理共享工作区和沙箱。独立提交历史、可丢弃实验、长任务不挡主工作区，用 git worktree。

```bash
git worktree add ../repo-auth feature/auth
codex --cd ../repo-auth
```

桌面 App 原生支持 worktree：侧栏里能看见，线程建在各自树里。CLI 0.154 起也可以用实验性 `--worktree` / `/worktree`，见托管 worktree 那条。

注意：

- 每个 worktree 复制 `node_modules` / 构建缓存，磁盘会涨
- 合完就删：`git worktree remove ../repo-auth`
- 不要让两个会话在同一 checkout 上改同一批文件

决策：要 git 隔离 → worktree。只读并行探索 → 子代理。几分钟的跑题 → `/side`。

## 来源

- [Codex Knowledge Base · Session patterns](https://codex.danielvaughan.com/2026/05/22/codex-cli-session-patterns-threads-worktrees-side-goals-subagents-decision-framework/)
