Worktree

From shenxingy/Clade · View interactive version

Worktree is an AI agent skill from the GitHub repository shenxingy/Clade. Create or inspect runtime-adaptive isolated Git workspaces with explicit ownership and delivery routing

How to use this skill

Skill file

Clade for Codex

This package composes the provider-neutral Clade core contract with the native

Codex surface adapter. Run the workflow directly in Codex; do not launch

another agent CLI or route it through Clade MCP.

Package provenance:

Canonical Clade workflow

You are the Worktree skill. Use the shared delivery context/state controller

and the current runtime surface overlay.

Invariants

worktrees.

snapshots and non-overlapping delivery units.

repository. Delivery ownership lives in Git-common state; shared task

ownership and dependencies live in the bound Beads service when /tasks is used.

merge every worktree into whichever branch happens to be active.

Create

  1. Run delivery context and inspect git worktree list --porcelain.
  2. Resolve the real base/default branch and ensure the source tree has no

unrelated dirty changes.

  1. Choose the runtime-native isolation:

preservation/publication;

  1. Create a delivery record containing task source, base SHA, owner, optional

stack parent, runtime, surface, and publication authorities.

For a shared task, verify the live claim first and pass --project-id,

--task-id and --session-id together. Worktrees share the Git-common task

binding; never initialize a separate task database inside each worktree.

  1. Pass the task through runtime-native context/handoff, not a tracked project

file.

Before filesystem creation, resolve an explicit safe destination outside the

repository root. Never derive a destructive target from an empty variable,

home directory, workspace root, or broad glob.

List

Combine:

base/head SHA, and last checkpoint.

Mark stale/prunable/unknown ownership; do not mutate it during list.

Preserve/handoff

Before runtime termination, context switch, compaction, or provider handoff:

No worktree may be auto-removed while its head is unreachable or dirty state

lacks a patch/blocker.

Integrate

Route the worktree's independently reviewable result through $clade:create-pr,

$clade:review-pr, and $clade:merge-pr. A throw-away integration worktree may test

several candidate heads, but durable work must never be based on it and it is

never itself merged as a product change.

For explicit stacks, record parent relationships, merge bottom-up, and restack

each child after parent ancestry changes.

Clean

  1. Re-probe worktrees and active delivery state.
  2. Require the target delivery to be merged/abandoned or explicitly preserved.
  3. Verify no dirty/unreachable work and no other live owner.
  4. Remove the exact worktree path.
  5. Delete only its exact owned local branch; delete remote only with authority.
  6. prune stale metadata and run delivery cleanup verification where applicable.

Never use broad --clean all, branch-prefix glob deletion, or force removal

without resolving every target and its recovery state.

Codex surface adapter

Codex surface adapter

$clade:delivery, and use $clade:<skill-name> for companion workflows.

AGENTS.override.md before AGENTS.md at each scope and does not merge

them, so where an override exists that scope's AGENTS.md is not in effect.

CLAUDE.md is Clade's legacy fallback rather than a filename Codex resolves;

read it only when it is trusted repository guidance.

is valid, but create/attach an owned branch or preserve a reachable Clade ref

before the runtime deletes the worktree.

one branch cannot be checked out by multiple worktrees.

not launch Claude Code or a nested Codex CLI to emulate the workflow.

connections remain user-scoped and cannot be donated by repository files.

Additional skill reference

Worktree

Create or manage isolated agent workspaces without assuming every runtime uses

a sibling directory plus immediate branch. Worktree ownership is recorded in

the shared $clade:delivery state; independently reviewable work integrates through

the target repository's PR/queue policy, not an arbitrary local merge.

Delivery completion

If this workflow changes files or external state:

repository task.

$clade:delivery and create a repository-compliant checkpoint or preserve

the work when committing is unavailable.

deployment, or live verification part of the task, do not silently downgrade

the result to local-only work.

or reachable external state, report BLOCKED or NEEDS_CONTEXT rather than

appending a "not committed/pushed/deployed" caveat after DONE.

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.