NousResearch/hermes-agent · error

Branch name is required.

Error message

Branch name is required.

What it means

Thrown by addExistingBranchWorktree when sanitizeBranch(name) returns an empty string. sanitizeBranch strips characters invalid in git branch names, so the guard fires when the caller passes an empty, whitespace-only, or entirely-invalid branch name (e.g. '..' or '..only-punctuation') to the 'add existing branch worktree' IPC.

Source

Thrown at apps/desktop/electron/git-worktree-ops.ts:249

}

function uniqueDir(base) {
  let dir = base
  let n = 1

  while (fs.existsSync(dir)) {
    n += 1
    dir = `${base}-${n}`
  }

  return dir
}

async function addExistingBranchWorktree(gitBin, root, name) {
  const requested = sanitizeBranch(name)

  if (!requested) {
    throw new Error('Branch name is required.')
  }

  // "origin/feature" is a remote-tracking ref and not a branch that git can
  // check out. `git worktree add <dir> origin/feature` detaches HEAD. Make a
  // local branch with the same short name that tracks the remote ref. This is
  // what `git switch feature` does for a branch on exactly one remote.
  const remote = await remoteOfRef(gitBin, root, requested)
  const branch = remote ? requested.slice(remote.length + 1) : requested

  if (!remote && branch === (await defaultBranch(gitBin, root))) {
    await runGit(gitBin, ['switch', branch], root)

    return { path: root, branch, repoRoot: root }
  }

  const dir = uniqueDir(path.join(root, '.worktrees', slugify(branch)))

  if (remote) {

View on GitHub (pinned to c896c09c42)

Solutions

  1. Pass a non-empty branch name that survives sanitization (letters, digits, '-', '_', '/').
  2. Disable the UI's confirm/add button while the branch-name field is blank.
  3. If the name comes from a list selection, guard against null/undefined before calling the IPC.

Example fix

// before
await addExistingBranchWorktree(gitBin, root, name) // name may be ''

// after
const requested = sanitizeBranch(name || '')
if (!requested) throw new Error('Branch name is required.')
await addExistingBranchWorktree(gitBin, root, requested)
Defensive patterns

Strategy: validation

Validate before calling

const requested = sanitizeBranch(String(name || '').trim())
if (!requested) {
  return showDialog('Enter a branch name before adding the worktree.')
}

Type guard

function isNonEmptyBranchName(name) {
  return typeof name === 'string' && sanitizeBranch(name) !== ''
}

Prevention

When it happens

Trigger: IPC call to add a worktree for an existing branch with branch='' or undefined; a UI text field submitting before the user typed anything; a branch name composed solely of characters sanitizeBranch removes (leading/trailing dots, spaces, ~, ^, :, ?, *, [, \).

Common situations: A form dialog whose submit button isn't disabled on empty input; programmatically forwarding a selected value from a list where nothing was selected (null coerced to string).

Related errors


AI-assisted analysis of NousResearch/hermes-agent@c896c09c42 (2026-08-14). Data as JSON: /api/errors/2ac90d4726e87b21. Report an issue: GitHub.