Skip to content

feat: Add automatic worktree name generation#381

Merged
aku11i merged 8 commits intomainfrom
claude/research-word-generator-7z9QR
Feb 25, 2026
Merged

feat: Add automatic worktree name generation#381
aku11i merged 8 commits intomainfrom
claude/research-word-generator-7z9QR

Conversation

@aku11i
Copy link
Owner

@aku11i aku11i commented Feb 25, 2026

Summary

This PR adds the ability to automatically generate unique worktree names when creating a new worktree without explicitly specifying a name.

Key Changes

  • New module: Added packages/core/src/worktree/generate-name.ts that exports generateUniqueName() function

    • Generates human-readable names using the human-id library with hyphen separators
    • Checks existing worktree directories (validateWorktreeDirectoryExists) and branches (branchExists) to ensure uniqueness
    • Returns Result<string, Error> consistent with the codebase's error handling pattern
    • Implements retry logic (max 10 attempts) to handle collisions
  • Updated CLI handler: Modified packages/cli/src/handlers/create.ts

    • Removed validation error when worktree name is not provided
    • Now calls generateUniqueName() when no name is specified
    • Properly handles the Result return type with isErr check
  • Dependencies: Added human-id v4.1.3 to packages/core/package.json

  • Exports: Updated packages/core/src/index.ts to export the new generateUniqueName function

  • Tests:

    • Added generate-name.test.js with 5 test cases (success, worktree directory collision retry, branch collision retry, max retries error, branchExists failure handling)
    • Added 2 CLI handler tests for name-omitted path (auto-generate success, generation failure)
    • Updated test mocks in create.test.js and create-postcreate.test.js to match Result return type

Implementation Details

  • Name collision is checked per candidate using validateWorktreeDirectoryExists (filesystem check) and branchExists (git check), avoiding the overhead of listing all worktrees upfront
  • If name generation fails after max retries, a descriptive error Result is returned
  • The feature is backward compatible—users can still provide explicit names

When `phantom create` is called without a name argument, a unique
human-readable name (e.g. "floppy-pugs-kiss") is auto-generated using
the `human-id` package. A recursive retry function ensures no collision
with existing worktree names.

https://claude.ai/code/session_01Ba8Dbq4ydVHyXuPRcHZaME
@aku11i aku11i changed the title Add automatic worktree name generation feat: Add automatic worktree name generation Feb 25, 2026
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a207f183b3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

… in create

- Usage changed from `phantom create <name>` to `phantom create [name]`
- Added note that a random name is auto-generated when omitted
- Made zsh completion positional arg optional
- Updated README, README.ja, commands.md, getting-started.md, mcp.md

https://claude.ai/code/session_01Ba8Dbq4ydVHyXuPRcHZaME
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f70a75627d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

docs/mcp.md Outdated

**Parameters:**
- `name` (required): Name for the worktree (also used as the branch name)
- `name` (optional): Name for the worktree (also used as the branch name). If omitted, a random name is generated

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep MCP create-worktree name parameter required in docs

This line documents name as optional and says Phantom will auto-generate it, but the MCP tool schema still requires name (packages/mcp/src/tools/create-worktree.ts, z.object({ name: z.string() ... })). Any MCP client that follows this updated doc and omits name will fail schema validation before the handler runs, so the documented flow is currently broken for users of phantom_create_worktree.

Useful? React with 👍 / 👎.

Also check `branchExists` so that a generated name that collides with
an existing local branch (not currently a worktree) triggers a retry
instead of failing at `git worktree add -b`.

https://claude.ai/code/session_01Ba8Dbq4ydVHyXuPRcHZaME
@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

The MCP tool schema still required `name` while the docs and CLI
already treated it as optional. Update the zod schema to
`z.string().optional()` and call `generateUniqueName` when omitted.

https://claude.ai/code/session_01Ba8Dbq4ydVHyXuPRcHZaME
@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

LLMs should always provide a name, so the MCP tool schema keeps
name as required. Revert the optional change and restore the
original doc/test assertions.

https://claude.ai/code/session_01Ba8Dbq4ydVHyXuPRcHZaME
@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

…nerateUniqueName

- Return Result<string, Error> instead of throwing for consistency with codebase
- Replace listWorktrees + Set with branchExists + validateWorktreeDirectoryExists
- Add unit tests for generateUniqueName (5 cases)
- Add CLI handler tests for name-omitted path (2 cases)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

… Windows test paths

- Add validateWorktreeName check on generated names as defensive guard
- Propagate branchExists errors instead of silently accepting the name
- Use path.join() in test assertions for cross-platform compatibility

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@aku11i aku11i merged commit 58cd84d into main Feb 25, 2026
15 checks passed
@aku11i aku11i deleted the claude/research-word-generator-7z9QR branch February 25, 2026 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants