Fast worktree reuse with head pointer checks

From ychampion/cskill-agents · View interactive version

Fast worktree reuse with head pointer checks is an AI agent skill from the GitHub repository ychampion/cskill-agents. Resume existing worktrees quickly by checking stored HEAD pointers before fetching or recreating.

How to use this skill

Skill file

SKILL: Fast Worktree Reuse With Head Pointer Checks

Domain: git-worktree

Trigger: Apply when the user asks to enter or resume a named worktree and you want to avoid redundant git fetch/git worktree add calls if the worktree already exists.

Source Pattern: Distilled from reviewed permission, shell-safety, and worktree-management implementations.

Core Method

Before reaching for git worktree add, compute the worktree path and read its git head pointer directly (no subprocess). If the file exists and contains a SHA, treat the worktree as already created: return the path/branch, skip fetch, and let the CLI proceed immediately. Only when the HEAD file is missing do you fetch and git worktree add, knowing the directory is missing or corrupted.

Key Rules

Example Application

For a “worktree resume” command, call this skill each time by deriving the slug, invoking the head-read fast-path, and only running git fetch when head data is missing, so most resumes finish in the same tick regardless of external network speed.

Anti-Patterns (What NOT to do)

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.