Safe worktree slug validation

From ychampion/cskill-agents · View interactive version

Safe worktree slug validation is an AI agent skill from the GitHub repository ychampion/cskill-agents. Ensure Git worktree slugs can never escape the managed workspace or inject traversal.

How to use this skill

Skill file

SKILL: Safe Worktree Slug Validation

Domain: git-worktree

Trigger: Apply this when accepting user-provided prefixes for enter worktree and you need to guarantee no path traversal or invalid chars slip into the worktree directory.

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

Core Method

Split a slug on /, reject segments that are empty, . or .., or contain characters outside a za z0 9, and enforce a maximum combined length before joining the cleaned segments into a deterministic branch name and path. Perform this validation synchronously before invoking any git commands so the CLI never creates directories outside claude worktrees.

Key Rules

Example Application

Any agent producing a worktree name for a release hotfix can reuse this skill: call the validator on the proposed slug, surface a concise error message if it fails, and refuse to call git worktree add until the slug is safe.

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.