A Main Repo and Git Worktrees for Multi-Repository Coding Agents
掘金 · 人工智能 describes an AI-SDLC engineering structure for letting coding agents work across existing Git repositories without consolidating them into a monorepo. The author’s team starts agents in a shared main repository, uses a manifest to define repository access and commands, and creates isolated worktrees for writable repositories. The account also covers disk-usage and unmerged-change risks, unified commands for Claude Code and Codex, and stricter cleanup rules for worktrees.
The account provides a concrete practitioner design for coordinating coding agents across multiple repositories while preserving per-repository permissions, baselines, and isolated development environments.
完成一个需求,常常要同时改好几个仓库:
- 全栈项目:前端、后端服务、接口定义各在一个仓库,有时还有配置仓库;
- 移动端组件化:壳工程、业务组件、基础组件库分在不同仓库,一个功能经常同时改业务组件和基础库;
- 同一个功能要在几个端各实现一遍,每个端一个仓库。
而 Agent 每次只在一个目录里启动,只看得到这个目录里的代码。
常见的做法是用 MonoRepo:把所有代码合进一个仓库,Agent 在一个目录下就能看到全部代码。但这解决不了存量项目的问题。存量项目早就分散在多个 git 仓库里,完成一个需求,还是要跨几个仓库改代码。
所以开发阶段先要解决的是:不合并仓库,怎么让 Agent 跨仓库写代码。具体是三个问题:Agent 在哪里启动,仓库放在哪里,代码写在哪里。