Claude Code: Auto-naming workspace branches
Fri, Apr 24, 2026Claude Code’s --workspace / -w flag is a nice workflow. It creates a new
workspace and branch for the task without me having to think about the setup.
The part I don’t love is the branch name. Random names are cute once. After a
few parallel sessions, trying to remember what work lives on
drifting-jingling-bunny is not.
Claude Code has a UserPromptSubmit hook, and that turns out to be enough to
fix it.
On the first prompt in a workspace I run a small script that:
- only fires once per Claude Code session,
- only fires if the branch hasn’t been pushed to a remote,
- only runs inside a workspace backed by a git worktree,
- asks a small model to suggest a short kebab-case branch name from the prompt,
- creates and checks out that branch, adding a numeric suffix if needed.
That means I can start a workspace normally, type the task in plain English, and immediately land on a branch with a name that actually matches the work.
If you want to copy the setup, the relevant pieces are:
.claude/settings.jsonfor wiring theUserPromptSubmithook..claude/hooks/first-message-create-branch.shfor the fire-once logic and branch creation.scripts/gemmafor the tiny LM Studio wrapper I use to generate the branch name.
For the model, I’m using a script that curls LM Studio running locally with the Gemma 4 model, because branch naming is a perfect small-model task: it needs to be fast, cheap, and roughly right. I wrote a little more about that here: Running Gemma 4 locally for small joys at the shell.
You could swap that part out for Copilot, Claude Code, or anything else that can turn a prompt into a short git-safe branch name.