Ctx worktree

From ActiveMemory/ctx · View interactive version

Ctx worktree is an AI agent skill from the GitHub repository ActiveMemory/ctx. Manage git worktrees for parallel agent development. Use when splitting work across independent task tracks.

How to use this skill

Skill file

Manage git worktrees to parallelize agent work across independent

task tracks. Supports creating, listing, and tearing down worktrees

with ctx-aware guardrails.

When to Use

When NOT to Use

Operations

`create <name>`

Create a new worktree as a sibling directory with a work/ branch.

Process:

  1. Check count: refuse if 4 worktrees already exist:

```bash

git worktree list

```

Count lines. If >= 5 (1 main + 4 worktrees), stop and explain

the limit.

  1. Determine project name from the current directory basename:

```bash

basename "$(git rev-parse --show-toplevel)"

```

  1. Create the worktree as a sibling directory:

```bash

git worktree add "../<project>-<name>" -b "work/<name>"

```

  1. Verify the worktree was created:

```bash

ls "../<project>-<name>"

```

  1. Remind the user:

> Do NOT run ctx init in the worktree. The context

> directory is already tracked in git and will be present.

> Launch a separate Claude Code session there and work

> normally.

`list`

Show all active worktrees:

git worktree list

`teardown <name>`

Merge a completed worktree back and clean up.

Process:

  1. Check for uncommitted changes in the worktree:

```bash

git -C "../<project>-<name>" status --porcelain

```

If output is non-empty, warn and stop. The user must commit or

discard changes first.

  1. Merge the work branch into the current branch:

```bash

git merge "work/<name>"

```

If there are conflicts, stop and help the user resolve them.

TASKS.md conflicts are common: see guidance below.

  1. Remove the worktree:

```bash

git worktree remove "../<project>-<name>"

```

  1. Delete the branch:

```bash

git branch -d "work/<name>"

```

  1. Verify cleanup:

```bash

git worktree list

git branch | grep "work/<name>"

```

Guardrails

complexity outweigh productivity gains

never inside the project tree

for easy identification and cleanup

in git; running init would overwrite shared context files

from the main working tree, not from inside a worktree

often conflict because multiple agents marked different tasks as

complete. Resolution: accept all [x] completions from both sides.

No task should go from [x] back to [ ].

What Works Differently in Worktrees

The encryption key lives at ~/.ctx/.ctx.key (user-level, outside

the project). All worktrees on the same machine share this path, so

ctx pad and ctx hook notify work in worktrees automatically.

One thing to watch:

resolve paths relative to the current working directory. Files

created in a worktree stay in that worktree and are discarded on

teardown. Enrich journals on the main branch after merging: the

JSONL session logs are intact regardless.

Task Grouping Guidance

Before creating worktrees, analyze the backlog to group tasks into

non-overlapping tracks:

  1. Read TASKS.md and identify all pending tasks
  2. Estimate blast radius: which files/directories does each

task touch?

  1. Group by non-overlapping directories: tasks that touch the

same package or file must go in the same track

  1. Present the grouping to the user before creating worktrees:
Proposed worktree groups:

  work/docs     : recipe updates, blog post, getting started guide
                  (touches: docs/)
  work/crypto   : P3.1-P3.3 encrypted scratchpad infra
                  (touches: internal/crypto/, internal/config/)
  work/pad-cli  : P3.4-P3.9 pad CLI commands
                  (touches: internal/cli/pad/)

Let the user approve or adjust before proceeding.

Quality Checklist

Before any operation, verify:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.