DEV Community

ILIA KARPENKO
ILIA KARPENKO

Posted on

Git Worktrees Give AI Agents Separate Files. What About Everything Else?

One agent is running tests. Another starts a dev server. A third needs the same database. Each has its own Git worktree, but they are still using the same machine.

What happens when two of them reach for the same resource?

I've been thinking about this while building agentgc, an open-source CLI for managing the environment around parallel coding tasks. Worktrees are a useful starting point: agents can edit separate working directories and branches. But the moment those agents run the code, there is more to coordinate.

I'd like to understand which parts of that coordination cause the most trouble in real projects. Here are a few places where I think the problems show up.

Separate directories, shared runtime

Ports and databases

If two tasks both try to start a server on port 3000, one may fail to start. The more confusing case is a test connecting to a server from a different task and giving you a result for the wrong code.

Task-specific ports help, as long as the application and its tests actually use the assigned address. And a port that appears free during a check can still be taken before the server binds to it.

Databases need attention too. Separate database names or instances can keep tests from changing each other's data. The setup still needs to create those databases, configure credentials, and decide when it's safe to remove them.

Builds and tests

More agents can mean more builds, package installs, and test suites running at once. Even when the tasks don't share files, they compete for CPU, memory, disk I/O, and sometimes a limited external resource.

One option is to queue heavy commands while letting agents do lighter work in parallel. That trades some concurrency for a more predictable machine. It doesn't make slow tests faster, but it can stop several of them from competing at the worst possible time.

Browser tests and Docker

Separate worktrees don't automatically give tasks separate browser profiles, test accounts, container names, ports, or volumes. A browser test may still depend on shared backend data even if each task starts its own browser.

For browser automation, I'd check the server URL, login state, test account, and data before assuming a failure is a code regression. With Docker, task-specific project names and explicit resource cleanup can help, but shared services and volumes still need deliberate handling.

The cost of a fresh task

A new worktree may be quick to create. Making it ready to run can take longer: install dependencies, generate files, build the project, and warm up caches. Multiply that by several tasks and setup time and disk usage become part of the workflow.

There are several different things people might try to reuse here. A pnpm store is different from a writable node_modules directory; build caches and generated files have their own invalidation rules. Sharing the wrong thing can make one task affect another or produce stale results.

I'm considering copy-on-write or another form of fast task materialization for a future version of agentgc. The idea is to make task setup faster by reusing suitable data while preserving task isolation. It isn't implemented yet, and I don't know which approach will make sense across different filesystems and project setups.

If you've experimented with this, I'd love to know what you reuse, what you keep separate, and what broke.

Finishing a task is a problem too

A completed task can leave behind a worktree, branch, running process, test database, container, and build artifacts. Removing them sounds easy until you find uncommitted work or a resource that another task still needs.

My preference is to inspect before deleting: identify what belongs to the task, check for unfinished work, and preserve anything uncertain. A cleanup command should make it clear what it plans to remove and should not silently destroy user data.

There's also work that runtime isolation doesn't solve: branches can conflict when merged, agents can work from stale context, and secrets need careful handling. A local worktree is not a security sandbox or a replacement for CI.

Where agentgc fits

I'm building agentgc as a runtime layer around parallel AI coding tasks. It can prepare a task worktree with ports, a database name and an env file, supervise configured services, queue commands, and help with cleanup. Database creation depends on configuration; a name alone doesn't provision one.

It does not yet solve all the problems in this article. In particular, copy-on-write task setup is a future idea, not a current feature. I want to use real reports from other developers to decide which gaps are worth tackling next.

What broke in your setup?

If you've run coding agents in parallel, what was the most frustrating thing that broke or slowed you down? Ports, databases, Playwright, Docker, node_modules, secrets, cleanup, merge conflicts, or something else?

A sentence is plenty. If you want to share more detail, this template would help:

Stack / OS:
Number of agents:
What happened:
Current workaround:
What you wish a tool would do:
Enter fullscreen mode Exit fullscreen mode

Please leave credentials and private project details out of your reply. I'll use recurring problems to inform the agentgc roadmap.

Top comments (0)