Worktree files
Each thread works in a worktree: a second checkout of your repository on a branch of its own. A fresh worktree has only what git tracks. Your .env, local config and installed dependencies are missing. Three files in your repository fix that:
| File | Does |
|---|---|
.worktreeinclude |
Lists files from your checkout to copy into each new worktree |
.cohort-setup.sh |
Runs in each new worktree, before the agent starts |
.cohort-teardown.sh |
Runs in a worktree just before it is removed |
They are plain files in the repository, so they work for everyone who uses it with Cohort.
.worktreeinclude
Section titled “.worktreeinclude”Put it at the root of your checkout. One pattern per line, in the same syntax as .gitignore:
# local settings that git ignores.env.env.localapps/web/.envconfig/local.jsonWhen a new worktree is made, every file in your checkout that matches is copied into it, at the same path. A matched folder is copied whole. Files the worktree already has are left alone. The thread’s transcript says “Copied 3 file(s) listed in .worktreeinclude.”
Copying big folders (node_modules/) works, but it takes time on every new thread. Installing in the setup script is often faster.
.cohort-setup.sh
Section titled “.cohort-setup.sh”A bash script, run in the new worktree after the files are copied and before the agent’s first turn. Install dependencies, generate code, link a database:
#!/usr/bin/env bashset -epnpm install --frozen-lockfilecp "$COHORT_SOURCE_DIR/.env" .env 2>/dev/null || trueIt runs:
- in the worktree’s folder, with the same environment as the thread: its login, and the project’s environment and secrets;
- with
COHORT_SOURCE_DIRset to your checkout andCOHORT_WORKTREE_DIRto the new worktree; - for up to 30 minutes.
Its output shows in the thread’s transcript as “.cohort-setup.sh finished:” or “.cohort-setup.sh failed:”, followed by what it printed. A failing script doesn’t stop the thread: the agent starts anyway, and you can read why it failed.
The script is read from the worktree, so commit it (or list it in .worktreeinclude).
.cohort-teardown.sh
Section titled “.cohort-teardown.sh”A bash script, run in the worktree just before Cohort removes it: stop a dev server, drop a test database, clean up outside the folder. It gets the same environment and variables as the setup script, for up to 10 minutes. Its output shows in the transcript the same way.
When they run
Section titled “When they run”| What happens | .worktreeinclude and .cohort-setup.sh |
.cohort-teardown.sh |
|---|---|---|
| A new thread in a worktree | Yes | |
| Unarchiving a thread (its worktree is made again) | Yes | |
| Moving a thread from the checkout into a worktree | Yes | |
| Moving a thread to another project | Yes, in the new worktree | Yes, in the one it leaves |
| Archiving a thread | Yes, after its work is saved to its branch | |
| Moving a thread out of its own worktree to another folder | Yes |
Threads in your checkout itself, or in a folder shared with another thread, don’t run them.
Cohort keeps a spare worktree ready per project so a new thread starts at once. Only the checkout is prepared ahead: the copy and the setup script still run when the thread starts, under its login.
