Running several AI coding sessions on one repo (worktrees, locks, fresh memory)
gitworktreeclaude-codeconcurrencyflockmemoryworkflow
Justin regularly has several Claude sessions working on the TLDR repo at once: interactive
terminals plus headless ProcrastinAI runs. On a shared checkout they clobber each other's
uncommitted files, the shared build/ directory and pushes. Since July 2026 the repo enforces one
git worktree per session, a lock around deploys, and a habit of re-reading project memory right
before acting.
Per-session worktrees
./worktree.sh new <name>creates../tldr-<name>on branchfeature/<name>from a freshly fetchedorigin/main. All edits happen there; the main checkout is never edited../worktree.sh done <name>merges to main, pushes and removes the worktree, guarded byflockon a lock file and runninggit merge --aborton conflict. Run it from the main checkout: from inside the feature worktree it fails with "'main' is already used by worktree".- Deploys run only from the main checkout, and the deploy script holds its own
flock. - Worktrees lack untracked files the build needs (e.g. Android's
google-services.json, a local stub of a server-only config); copy them in. ./worktree.sh listis the first thing to check when picking up a retried or interrupted task: a previous attempt may have left a complete, uncommitted diff behind.
Code is fresh, memory is not
Worktrees start from origin/main, so code freshness is automatic. Notes are not: on 2026-07-10 an
entire release shipped from another session between one session's start and its first edit,
changing the deploy rules. So:
- Re-read the project's MEMORY.md (and topic files you will touch) from disk at the moment work
begins, especially after a long pause or /clear.
- Also skim the project's headless activity log (ai-activity.jsonl) for changes made by
unattended runs since your last look.
Parallel agents inside one session
Splitting work across subagents works when they own disjoint files (one on a screen layout, one on server PHP, one on the router). Commit after each task, split commits by category, and run a review pass (architect plus pedant) before deploying. More in Multi-agent development workflows with Claude Code.
See also
- Running long jobs so they survive the AI session that started them
- Release-directory deploys with an atomic symlink swap