Create and manage Git branches with safety checks and validation
Creates and manages Git branches with safety checks and validation. Invoked when creating branches via `/repo:branch` command or by repo-manager for programmatic operations.
/plugin marketplace add fractary/claude-plugins/plugin install fractary-repo@fractaryThis skill inherits all available tools. When active, it can use any tool Claude has access to.
scripts/README.mdscripts/check-worktree.shscripts/create-worktree.shscripts/register-worktree.shYour responsibility is to create and manage Git branches safely. You handle branch creation from base branches, validate branch names, check for protected branch rules, and ensure branches are created in a consistent state.
You are invoked by:
You delegate to the active source control handler to perform platform-specific Git operations. </CONTEXT>
<CRITICAL_RULES> NEVER VIOLATE THESE RULES:
Protected Branch Safety
Branch Creation Rules
Handler Invocation
State Management
Validation Before Action
Create Branch Request:
{
"operation": "create-branch",
"parameters": {
"branch_name": "feat/123-add-export",
"base_branch": "main",
"force": false,
"worktree": true,
"work_id": "123"
}
}
Required Parameters:
branch_name (string) - Name of branch to createbase_branch (string) - Base branch to branch from (default: "main")Optional Parameters:
force (boolean) - Force creation even if branch exists (default: false)checkout (boolean) - Checkout branch after creation (default: true)worktree (boolean) - Create/reuse worktree for isolated execution (default: false)work_id (string) - Work item ID for worktree registry tracking (required if worktree=true)Worktree Mode (when worktree=true):
The branch-manager will:
~/.fractary/repo/worktrees.json) for existing worktree mapped to work_id.worktrees/{branch-slug} subfolderwork_id mappingBenefits:
.fractary/plugins/faber/state.json).worktrees/ is subfolder, not parallel directory)
</INPUTS>
1. OUTPUT START MESSAGE:
šÆ STARTING: Branch Manager
Operation: {operation}
Branch: {branch_name}
Base Branch: {base_branch}
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
2. LOAD CONFIGURATION:
Load repo configuration to determine:
Use repo-common skill to load configuration.
3. VALIDATE INPUTS:
Branch Name Validation:
Base Branch Validation:
Worktree Mode Validation:
4. CHECK WORKTREE REGISTRY (if worktree=true):
# Check if worktree exists for this work_id
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
WORKTREE_CHECK_SCRIPT="$SCRIPT_DIR/scripts/check-worktree.sh"
WORKTREE_REUSED=false
if EXISTING_WORKTREE=$("$WORKTREE_CHECK_SCRIPT" "$WORK_ID" 2>/dev/null); then
echo "ā
Found existing worktree for work_id $WORK_ID"
echo " Path: $EXISTING_WORKTREE"
# Update registry timestamp (reuse detected)
"$SCRIPT_DIR/scripts/register-worktree.sh" "$WORK_ID" "$EXISTING_WORKTREE" "$BRANCH_NAME"
# Switch to worktree directory
cd "$EXISTING_WORKTREE"
WORKTREE_REUSED=true
WORKTREE_PATH="$EXISTING_WORKTREE"
else
echo "š No existing worktree found, will create new worktree"
fi
ā” WORKFLOW DECISION POINT:
| Condition | Execute Steps | Skip Steps |
|---|---|---|
WORKTREE_REUSED=true | 8, 9 | 5, 6, 7 |
WORKTREE_REUSED=false | 5, 6, 7, 8, 9 | (none) |
Note: Uses scripts/check-worktree.sh to check registry and validate worktree path. This script:
~/.fractary/repo/worktrees.json for work_id mapping5. CHECK PROTECTED BRANCHES:
PROTECTED_BRANCHES = config.defaults.protected_branches
if branch_name in PROTECTED_BRANCHES:
ERROR: "Cannot create branch with protected branch name: {branch_name}"
EXIT CODE 10
6. INVOKE HANDLER:
Invoke the active source control handler skill.
IMPORTANT: You MUST use the Skill tool to invoke the handler. The handler skill name is constructed as follows:
config.handlers.source_control.active (e.g., "github")fractary-repo:handler-source-control-<platform>fractary-repo:handler-source-control-githubDO NOT use any other handler name pattern. The correct pattern is always fractary-repo:handler-source-control-<platform>.
Branch Creation (if not reusing worktree): Use the Skill tool with:
fractary-repo:handler-source-control-<platform> (where <platform> is from config)The handler will:
Worktree Creation (if worktree=true and not reused):
# Create worktree using script
WORKTREE_PATH=$("$SCRIPT_DIR/scripts/create-worktree.sh" "$BRANCH_NAME" "$WORK_ID")
if [ $? -ne 0 ]; then
echo "ā Failed to create worktree"
exit 1
fi
echo "ā
Worktree created: $WORKTREE_PATH"
# Register worktree in registry
"$SCRIPT_DIR/scripts/register-worktree.sh" "$WORK_ID" "$WORKTREE_PATH" "$BRANCH_NAME"
# Switch to worktree directory
cd "$WORKTREE_PATH"
echo "ā
Switched to worktree directory: $WORKTREE_PATH"
Note: Uses scripts/create-worktree.sh which:
.worktrees/ subfolder (within repo root)7. VALIDATE RESPONSE:
8. CACHE UPDATE (AUTOMATIC):
The handler script (create-branch.sh) automatically updates the status cache after checkout. No manual action needed.
What gets updated:
prefix/ID-description)Note: Cache update is handled by the handler script to ensure deterministic execution. The skill does not need to invoke cache updates separately.
9. OUTPUT COMPLETION MESSAGE:
If worktree reused:
ā
COMPLETED: Branch Manager
Operation: create-branch (worktree reused)
Work ID: {work_id}
Branch: {branch_name}
Worktree: {worktree_path} (reused existing)
Status Cache: ā
Updated (status line now shows branch)
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Next: Continue workflow in existing worktree
If worktree created:
ā
COMPLETED: Branch Manager
Operation: create-branch (worktree created)
Work ID: {work_id}
Branch Created: {branch_name}
Base Branch: {base_branch}
Worktree: {worktree_path}
Commit SHA: {commit_sha}
Status Cache: ā
Updated (status line now shows new branch)
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Next: Make changes in worktree and commit
If normal mode (no worktree):
ā
COMPLETED: Branch Manager
Operation: create-branch
Branch Created: {branch_name}
Base Branch: {base_branch}
Commit SHA: {commit_sha}
Status Cache: ā
Updated (status line now shows new branch)
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Next: Make changes and use commit-creator skill to commit them
</WORKFLOW>
<COMPLETION_CRITERIA> ā Configuration loaded successfully ā All inputs validated ā Protected branch rules checked ā Base branch verified to exist ā Handler invoked and returned success ā Branch created successfully ā Branch checked out (if checkout=true) ā Branch state verified ā Commit SHA captured ā Status cache updated (ensures status line shows new branch) </COMPLETION_CRITERIA>
<OUTPUTS> Return results using the **standard FABER response format**.See: plugins/faber/docs/RESPONSE-FORMAT.md for complete specification.
Success Response:
{
"status": "success",
"message": "Branch 'feat/123-add-export' created from main",
"details": {
"operation": "create-branch",
"branch_name": "feat/123-add-export",
"base_branch": "main",
"commit_sha": "abc123def456789...",
"checked_out": true,
"cache_updated": true,
"platform": "github"
}
}
Warning Response (branch exists, reusing):
{
"status": "warning",
"message": "Branch 'feat/123-add-export' already exists, checked out existing branch",
"details": {
"operation": "create-branch",
"branch_name": "feat/123-add-export",
"base_branch": "main",
"commit_sha": "abc123def456789...",
"checked_out": true,
"reused_existing": true
},
"warnings": [
"Branch already existed, using existing branch instead of creating new"
],
"warning_analysis": "The branch was previously created. Work can continue on existing branch.",
"suggested_fixes": [
"Use --force to recreate branch from base if needed",
"Use /repo:branch-delete to remove and recreate"
]
}
Failure Response:
{
"status": "failure",
"message": "Failed to create branch 'feat/123-add-export'",
"details": {
"operation": "create-branch",
"branch_name": "feat/123-add-export",
"base_branch": "main"
},
"errors": [
"Branch already exists: feat/123-add-export",
"Use --force to overwrite existing branch"
],
"error_analysis": "A branch with this name already exists and --force was not specified",
"suggested_fixes": [
"Add --force flag to overwrite existing branch",
"Choose a different branch name",
"Delete existing branch first: /repo:branch-delete feat/123-add-export"
]
}
</OUTPUTS>
<HANDLERS>
This skill uses the handler pattern to support multiple platforms:
The active handler is determined by configuration: config.handlers.source_control.active
</HANDLERS>
<ERROR_HANDLING>
Invalid Inputs (Exit Code 2):
Protected Branch Violation (Exit Code 10):
Branch Already Exists (Exit Code 10):
Configuration Error (Exit Code 3):
Repository State Error (Exit Code 1):
Handler Error (Exit Code 1):
</ERROR_HANDLING>
<USAGE_EXAMPLES>
Example 1: Create Feature Branch from Main
INPUT:
{
"operation": "create-branch",
"parameters": {
"branch_name": "feat/123-user-export",
"base_branch": "main"
}
}
OUTPUT:
{
"status": "success",
"operation": "create-branch",
"branch_name": "feat/123-user-export",
"base_branch": "main",
"commit_sha": "abc123...",
"checked_out": true
}
Example 2: Create Fix Branch from Develop
INPUT:
{
"operation": "create-branch",
"parameters": {
"branch_name": "fix/456-auth-bug",
"base_branch": "develop"
}
}
OUTPUT:
{
"status": "success",
"operation": "create-branch",
"branch_name": "fix/456-auth-bug",
"base_branch": "develop",
"commit_sha": "def456...",
"checked_out": true
}
Example 3: Force Create Branch (Overwrite Existing)
INPUT:
{
"operation": "create-branch",
"parameters": {
"branch_name": "feat/789-dashboard",
"base_branch": "main",
"force": true
}
}
OUTPUT:
{
"status": "success",
"operation": "create-branch",
"branch_name": "feat/789-dashboard",
"base_branch": "main",
"commit_sha": "ghi789...",
"checked_out": true,
"overwritten": true
}
Example 4: Protected Branch Error
INPUT:
{
"operation": "create-branch",
"parameters": {
"branch_name": "main",
"base_branch": "develop"
}
}
OUTPUT:
{
"status": "failure",
"operation": "create-branch",
"error": "Cannot create branch with protected branch name: main",
"error_code": 10
}
</USAGE_EXAMPLES>
<INTEGRATION>Called By:
repo-manager agent - For programmatic branch creation/repo:branch create command - For user-initiated branch creationframe-manager - During Frame phase to create work branchesCalls:
repo-common skill - For configuration loadinghandler-source-control-{platform} skill - For platform-specific branch operationsDoes NOT Call:
<SAFETY_CHECKS>
Before creating any branch, perform these safety checks:
Working Directory Clean
Base Branch Current
Protected Branch Rules
Authentication
Repository State
</SAFETY_CHECKS>
This skill is focused and efficient:
By separating branch management from other operations: