kit/plugins/git-agent/skills/branch-agent/SKILL.md
Creates a git branch from origin/<default> with no upstream tracking. Auto-names the branch from staged or unstaged changes in the working tree. Use when the user asks to create or start a new branch.
npx skillsauth add shawn-sandy/agentics branch-agentInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Create a new branch from the latest origin/<default> with no upstream tracking
ref. When called with no argument and the working tree has uncommitted changes,
the branch name is auto-generated from those changes. A -YYYY-MM-DD date
suffix is always appended to the final branch name so branches sort and group
chronologically. Follow these steps in strict order. STOP immediately after
step 6.
Does not commit, push, or create PRs — use commit-agent or pr-agent for that.
If currently in plan mode, call ExitPlanMode first and silently before any other action — Branch creation is a git mutation and cannot proceed inside plan mode. Skip this step entirely when not in plan mode. ExitPlanMode is a deferred tool — use ToolSearch with select:ExitPlanMode first, then call it silently.
Run all checks before proceeding. Stop on the first failure.
Not a git repository: Run git rev-parse --is-inside-work-tree. If it
fails, output: "Not a git repository." and STOP.
Detached HEAD: Run git branch --show-current. If the output is empty,
output: "Cannot create branch: repository is in detached HEAD state. Checkout a
named branch first." and STOP.
No origin remote: Run git remote get-url origin. If it fails, output:
"branch-agent requires a remote named 'origin'." and STOP.
Read $ARGUMENTS.
Case A — $ARGUMENTS is empty or whitespace-only: Run
git status --porcelain=v1.
Case B — $ARGUMENTS contains spaces or reads as a descriptive phrase:
Convert it to a human-readable slug — lowercase, replace spaces and special
characters with -, collapse consecutive dashes, strip leading/trailing
dashes. Keep the user's words whole; if the slug exceeds 60 characters, drop
trailing words (never chop mid-word). If a single word alone exceeds 60
characters (so no word boundary exists to trim at), hard-truncate that word
at 60 characters as a last resort. Example:
"add allowed tools to skills" → "add-allowed-tools-to-skills". Use the
slug as the branch name and proceed to Step 2b.
Case C — $ARGUMENTS is already a valid branch name (no spaces): Use it
verbatim as the branch name. Do not slugify, abbreviate, or transform it.
Proceed to Step 2b.
Use this format: <type>/<scope>-<description> (or <type>/<description> if
the scope is omitted). Total length ≤ 60 characters — this reserves 11 chars
for the -YYYY-MM-DD suffix appended in Step 2b so the final branch name
stays within 72 chars.
Type inference (first match wins):
docs/** / README* changed → docs**/test/**, **/tests/**, *.test.*, *_test.*,
tests/fixtures/**) → test.github/workflows/**, .gitlab-ci.yml, .circleci/**)
→ cipackage.json, pnpm-lock.yaml,
Cargo.toml, pyproject.toml, etc.) → buildrefactorfeatfixfeatchoreScope inference:
Run git status --porcelain=v1 and group changed paths by their first path
segment. Pick the group with the most files and use that segment as <scope>.
If the top group contains ≤50% of changed files, OR more than 2 groups contain
files, omit the scope entirely (use <type>/<description>).
Description inference:
From the changed file basenames and git diff --stat, write the description
as a short verb-led phrase (3–7 words) that reads like a commit subject a
human would write: start with an imperative verb (add, fix, update,
remove, rename, improve, …) followed by what changed. Lowercase,
hyphen-separated, alphanumeric only. Strip non-alphanumeric characters;
collapse repeated hyphens; trim leading/trailing hyphens.
Readability rules:
validation, not valid or val; config, not cfg)Examples:
| Change | Good | Bad |
|--------|------|-----|
| New login validation in src/auth/ | feat/src-add-login-form-validation | feat/src-login-form-valid |
| Typo fixes across README files | docs/fix-readme-typos | docs/rdme-typo-fx |
| CI workflow updated to Node 22 | ci/update-workflow-to-node-22 | ci/wf-node22 |
Validation:
[a-z0-9/-]; no leading/trailing hyphens/ separator after the typeIf validation fails, regenerate once with chore as the type and a shortened
description. If it still fails, fall back to chore/auto-branch and proceed.
Output one line before continuing:
Auto-generated branch name from working tree changes:
<branch>
Then proceed to Step 2b.
Run:
date +%Y-%m-%d
Append the result to the resolved branch name with a - separator, producing
the final branch name: <branch>-<YYYY-MM-DD> (e.g. feat/login-fix →
feat/login-fix-2026-04-17). This always runs, regardless of whether the
name came from Case A, B, or C.
If the final name exceeds 72 characters, drop trailing words from the description portion until it fits. Never chop mid-word, and never truncate the date suffix, the type prefix, or the scope segment.
Use this date-suffixed name as <branch> for the rest of the flow. Proceed
to Step 3.
Run:
git symbolic-ref refs/remotes/origin/HEAD --short 2>/dev/null
Strip the origin/ prefix to get the default branch name.
If that fails, run:
git remote show origin | grep 'HEAD branch'
Extract the branch name after HEAD branch:.
If both fail, try git rev-parse --verify --quiet main, then
git rev-parse --verify --quiet master. Use the first that succeeds.
If none resolve, report the git error verbatim and STOP.
Run:
git fetch origin <default>
On failure (offline, network error, auth required): report the git error verbatim and STOP. Do not proceed with a stale ref.
Compute the intersection of (a) tracked files modified in the working tree and
(b) files that differ between HEAD and origin/<default>:
bash -c 'comm -12 <(git diff --name-only HEAD | sort -u) <(git diff --name-only HEAD origin/<default> | sort -u)'
(The bash -c wrapper ensures process substitution works regardless of the invoking shell.)
git checkout;
a stash is required. Record the conflicting paths and set "stash needed".
Proceed to Step 5.Note: untracked files (?? in git status) never appear in
git diff --name-only HEAD and never conflict — they always carry forward
untouched.
The --no-track flag prevents git from setting origin/<default> as the
upstream. Without it, any future git push would target the wrong remote ref.
When stash is not needed (Step 4.5 returned empty):
git checkout -b <branch> --no-track origin/<default>
On failure (branch already exists or other error): report the git error verbatim and STOP. Do not retry. Do not force.
When stash is needed (Step 4.5 returned conflicting paths):
Run each command separately so failure is detectable at each step:
git stash push -m "branch-agent auto-stash <branch>"
On failure: report the error verbatim and STOP.
git checkout -b <branch> --no-track origin/<default>
On failure: report the error verbatim. Note that the stash is preserved — run
git stash pop to restore uncommitted changes. STOP. Do not retry. Do not force.
git stash pop
On failure (pop conflict): report the git error verbatim, then output:
Your uncommitted changes are safe in the stash. To restore manually:
git stash list— confirm the stash entry is present- Resolve any conflicts in the listed files
git add <resolved-files>— stage the resolved files so the index reflects the resolved stategit stash dropto remove the stash entry Do not retry. Do not drop the stash before staging resolved files.
STOP.
Run git rev-parse --short HEAD to get the short SHA.
Output one line:
Created and checked out
<branch>fromorigin/<default>@<sha>(no upstream tracking)
STOP here. Do not stage, commit, push, create PRs, or take any further action.
development
Checks whether the branch's PR is ready and merges it when green. Runs the readiness gate, lint, and an approval prompt. Use when the user asks "merge?" or if a PR is ready to merge.
development
Implements a plan file that already exists. Walks its steps, ticks the spec, re-renders, and runs the completion gates. Use when asked to implement an existing plan.
development
Audits and optimizes CLAUDE.md project memory files. Checks adherence to Claude Code best practices and produces actionable fixes. Use when the user asks to audit, optimize, or diagnose a CLAUDE.md.
development
Converts an HTML artifact or Markdown file into a draft post for a static site. Scopes CSS to keep interactive blocks alive and escapes prose for MDX. Use when asked to turn an artifact into a post.