Skip to content

Start work in a copy

Work on Agents never happens on main. Each task gets a copy of the repo, a git worktree on a branch of its own off GitHub’s main, with its own node_modules. agents-git makes the copy and tracks it in a ledger, so several people and agents can work at once without touching each other’s files. This page is for anyone who changes the repo, by hand or through an agent.

  • Check out the repo, with .env and .env.test in the main checkout. The README’s “Set up a working copy” section writes both.
  • Put ~/.local/node/bin first on PATH.
  • Install the gh command. agents-git status and finish ask GitHub through it.
  • Have Docker running if you will run checks. Run the checks explains why.
  1. From the main checkout, run:

    Terminal window
    node daemon/agents-git/main.ts start <name> --note "<what you work on>"

    A name is 1 to 63 lowercase letters, digits and dashes, and cannot be main or HEAD. It becomes the branch, the folder and the ledger entry.

  2. Wait for npm ci. The command fetches GitHub’s main first, then makes the copy in <repo>-worktrees/<name>, beside the repo. It prints the path.

  3. Change into the copy and link the main checkout’s two env files into it. Git ignores both, so start does not carry them, and the checks and agentsctl read them from the copy.

    Terminal window
    ln -s <main checkout>/.env .env
    ln -s <main checkout>/.env.test .env.test
  4. Make every edit and commit in the copy.

start refuses, and changes nothing, when the ledger already has the name, the branch exists, the folder exists, or the main checkout has uncommitted files. If npm ci fails, it takes the copy back and you can run it again with the same name.

Run these once on a machine.

Terminal window
node daemon/agents-git/main.ts guard install
node daemon/agents-git/main.ts hooks install

guard install writes git’s reference-transaction hook into the repo’s shared .git, so it covers every copy and every tool that runs git. The hook refuses to move main to anything but origin/main, and refuses to make a stash entry. It also installs a post-commit hook that warns when a commit leaves the branch over the size cap, and a prepare-commit-msg hook that adds a Session: <id> trailer to a commit a Claude Code session makes with -m or -F. guard status says whether the hooks are there.

hooks install adds three hooks to Claude Code’s settings in ~/.claude/settings.json and Codex’s in ~/.codex/hooks.json. They run the scripts in the main checkout. Codex runs a hook only once you trust it in /hooks.

  • The session-start hook runs agents-git status as a session starts in a copy.
  • The before-tool hook refuses git stash, a push to main, gh pr merge, git add -A, git add --all, git add ., a bare sleep, and any command it crashes reading, and says what to run instead. Name the paths you stage, with git add <paths>.
  • The stop hook runs agents-git finish as each turn ends, when the copy is clean and ahead of origin/main.

agents-git sweep finishes every copy that is clean, ahead of origin/main, and idle for 15 minutes. It is meant to run every 5 minutes under launchd on the developer’s Mac, through ops/com.agents.sweeper.plist.

Run agents-git status from the copy. It prints the branch against origin/main, the size against the line cap, the branch’s pull request and its checks, every open pull request, and the next command to run. agents-git size prints the size alone, from what the machine last fetched, with no network.

Terminal window
node daemon/agents-git/main.ts session <name> --note "<text>" --job "<text>" --done "<check>"

This runs start, then a Claude session in the copy inside a herdr pane, with the playbook plugin loaded. How a session loads the playbooks explains the first message. The command prints how to attach, take over, and wait for the session to go idle.

  • agents-git list shows every worktree, tracked or not, and where the ledger and git disagree.
  • agents-git adopt <path> [--name <name>] [--note <text>] tracks a worktree that exists, without changing it.
  • agents-git save <name> keeps a copy’s uncommitted work in a ref and leaves the copy as it is.
  • agents-git sync <name> brings local main into the branch, by a rebase, or by a merge once the branch is submitted.
  • agents-git done <name> previews what it would remove. Add --yes to save the last commit, remove the copy, and delete the branch once main has it. It refuses when an ignored path would be lost, and --backup <path> copies one to ~/.agents-app/backups first.
  • agents-git prune runs done for each copy that is merged and clean, or whose folder is gone. It previews until you add --yes.