feat: Add automatic worktree name generation#381
Conversation
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
There was a problem hiding this comment.
💡 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
There was a problem hiding this comment.
💡 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 |
There was a problem hiding this comment.
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
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
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
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
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
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
…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>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
… 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>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
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.tsthat exportsgenerateUniqueName()functionhuman-idlibrary with hyphen separatorsvalidateWorktreeDirectoryExists) and branches (branchExists) to ensure uniquenessResult<string, Error>consistent with the codebase's error handling patternUpdated CLI handler: Modified
packages/cli/src/handlers/create.tsgenerateUniqueName()when no name is specifiedResultreturn type withisErrcheckDependencies: Added
human-idv4.1.3 topackages/core/package.jsonExports: Updated
packages/core/src/index.tsto export the newgenerateUniqueNamefunctionTests:
generate-name.test.jswith 5 test cases (success, worktree directory collision retry, branch collision retry, max retries error, branchExists failure handling)create.test.jsandcreate-postcreate.test.jsto matchResultreturn typeImplementation Details
validateWorktreeDirectoryExists(filesystem check) andbranchExists(git check), avoiding the overhead of listing all worktrees upfrontResultis returned