Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# unity-worktree-cow

A Claude Code skill, unity-worktree-cow (`uwt` for short), for running many
concurrent Unity git worktrees without paying full disk for each one.
An [Agent Skill](https://agentskills.io), unity-worktree-cow (`uwt` for short),
for running many concurrent Unity git worktrees without paying full disk for
each one. It works with any agent that reads `SKILL.md` skills (Claude Code,
Codex, Copilot, Cursor, Gemini CLI, ...), and the script runs fine by hand.

One golden snapshot of the project (working tree + `Library/`) is taken while
the editor is closed. Every new worktree is a block-clone of that snapshot,
Expand Down Expand Up @@ -33,14 +35,39 @@ to fixed per project and the saving grows with project size. After the first
open it grows slowly, except that on Unity 6.6+ a texture or model reimport
can turn a whole `DataStore` segment private (0.1–0.5 GiB); see `SKILL.md`.

## Install

Copy `skills/unity-worktree-cow/` into the Unity project's repo, in the folder
your agent reads skills from, and commit it: `uwt new` resets every worktree to
its branch, so an uncommitted skill does not reach the worktrees it creates.

| agent | folder in the repo |
|---|---|
| Codex, Cursor, Gemini CLI, GitHub Copilot | `.agents/skills/` |
| Claude Code | `.claude/skills/` |
| Copilot in VS Code | `.github/skills/` |

Cursor and the Copilot coding agent also read `.claude/skills/`, so a repo
used only with those and Claude Code needs just that one. A repo shared with
Codex or Gemini as well needs both folders; keep the full skill in one and, in
the other, a `SKILL.md` that repeats the frontmatter and points at the first, so
there is only one script to update.

`npx skills add Unity-Technologies/unity-worktree-cow` (the `skills` CLI) does the copy for most agents.

An agent without skill support can be pointed at it from `AGENTS.md`:

```markdown
For Unity worktrees, or a worktree whose Library/ needs populating without a
reimport, read .agents/skills/unity-worktree-cow/SKILL.md and use its script.
```

## Use it

Copy `.claude/skills/unity-worktree-cow/` into the target repo and commit it, so
the worktrees it creates carry it too. Then, in a
checkout whose `Library/` is imported and whose editor is **closed**:
In a checkout whose `Library/` is imported and whose editor is **closed**:

```bash
uwt=.claude/skills/unity-worktree-cow/scripts/unity-worktree-cow.sh
uwt=<skill folder>/scripts/unity-worktree-cow.sh
$uwt doctor # proves this volume block-clones; run first
$uwt seed # snapshot project + Library into .git/uwt/golden
$uwt new feature/x # git worktree add + clone + hydrate, ~seconds
Expand Down Expand Up @@ -83,7 +110,7 @@ Windows, a `/proc` scan on Linux, `lsof` on macOS.

## Documentation

`.claude/skills/unity-worktree-cow/SKILL.md` is the full reference: commands, what
`skills/unity-worktree-cow/SKILL.md` is the full reference: commands, what
is and is not cloned and why, the cost model, how to measure sharing, and
troubleshooting.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,23 @@ assets.

## Quick start

Commit `.claude/skills/unity-worktree-cow/` to the repo. `new` resets every
Commit this skill folder to the repo, wherever the agent reads skills from
(`.agents/skills/`, `.claude/skills/`, ...). `new` resets every
worktree to its branch and cleans untracked files, so an uncommitted skill is
not in the worktrees it creates, and agents working there cannot reach uwt
(`new` warns, and its JSON carries the script's absolute path as `uwt`).

In a checkout whose `Library/` is imported and whose editor is **closed**:

```bash
uwt=.claude/skills/unity-worktree-cow/scripts/unity-worktree-cow.sh # Git Bash on Windows
uwt=<skill folder>/scripts/unity-worktree-cow.sh # Git Bash on Windows
$uwt doctor # ALWAYS first: a live clone probe, not a capability flag
$uwt seed # snapshot project + Library into .git/uwt/golden
$uwt new feature/my-thing # git worktree add + clone + hydrate
```

Hydrating a worktree created some other way (including Claude Code's own
`isolation: worktree`):
Hydrating a worktree created some other way (by hand, or by an agent's own
worktree isolation, such as Claude Code's `isolation: worktree`):

```bash
$uwt hydrate path/to/that/worktree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ stamp(){ date -u +%Y-%m-%dT%H:%M:%SZ; }
# ------------------------------------------------------------------ paths
wpath() { if [ "$OS" = windows ]; then cygpath -w "$1"; else printf '%s' "$1"; fi; }

# The skill folder holding this script, wherever an agent installed it
# (.claude/skills/, .agents/skills/, ...): the parent of scripts/.
skill_dir() {
local d; d="$(dirname "$1")"
[ "$(basename "$d")" = scripts ] && d="$(dirname "$d")"
wpath "$d"
}

# Absolute path against the CALLER's directory, for a path that may not exist
# yet (its parent must). Accepts C:\ style on Windows.
abs_path() {
Expand Down Expand Up @@ -773,7 +781,7 @@ new_plastic() {
say " remove it later with: $(wpath "$self") remove $(wpath "$path")"
case "$self" in
"$m"/*) [ -n "$(cm_ ls "$(wpath "$self")" --format='{hash}' 2>/dev/null | tr -d '\r[:space:]')" ] \
|| warn "the uwt skill is not checked in, so the new workspace has no copy of it; check in .claude/skills/unity-worktree-cow/" ;;
|| warn "the uwt skill is not checked in, so the new workspace has no copy of it; check in $(skill_dir "$self")" ;;
esac
local jpath="$path" jproj="$pdir" # in git's form: E:/x on Windows
[ "$OS" = windows ] && { self="$(cygpath -m "$self")"; jpath="$(cygpath -m "$path")"; jproj="$(cygpath -m "$pdir")"; }
Expand Down Expand Up @@ -937,7 +945,7 @@ cmd_new() {
say ""; good "worktree ready in ${secs}s: $path"
say " remove it later with: $(wpath "$self") remove $(wpath "$path")"
if [ "$(common_dir "$sd")" = "$(common_dir "$m")" ] && ! git -C "$sd" ls-files --error-unmatch "$(basename "$self")" >/dev/null 2>&1; then
warn "the uwt skill is not committed, so the new worktree has no copy of it; commit .claude/skills/unity-worktree-cow/"
warn "the uwt skill is not committed, so the new worktree has no copy of it; commit $(skill_dir "$self")"
fi
[ "$OS" = windows ] && self="$(cygpath -m "$self")"
json_ok new "{\"path\":$(json_str "$reg"),\"uwt\":$(json_str "$self"),\"project\":$(json_str "$reg${pre:+/$pre}"),\"branch\":$(json_str "$branch"),\"head\":$(json_str "$(git -C "$path" rev-parse HEAD)"),\"seconds\":$secs,\"verified\":$([ "${OPT_VERIFY:-0}" = 1 ] && echo true || echo false),\"submodules_uninitialized\":$subs}"
Expand Down
2 changes: 1 addition & 1 deletion tests/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

set -uo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
UWT="$HERE/../.claude/skills/unity-worktree-cow/scripts/unity-worktree-cow.sh"
UWT="$HERE/../skills/unity-worktree-cow/scripts/unity-worktree-cow.sh"
[ -f "$UWT" ] || { echo "missing $UWT"; exit 2; }

ROOT="${1:-$(mktemp -d "${TMPDIR:-/tmp}/uwt-tests-XXXXXX")}"
Expand Down
Loading