Skip to content

fix: make worktree target subagent-friendly with NAME parameter#126

Merged
JacobCoffee merged 1 commit intomainfrom
feature/make-worktree-subagent-friendly
Nov 23, 2025
Merged

fix: make worktree target subagent-friendly with NAME parameter#126
JacobCoffee merged 1 commit intomainfrom
feature/make-worktree-subagent-friendly

Conversation

@JacobCoffee
Copy link
Owner

@JacobCoffee JacobCoffee commented Nov 23, 2025

Summary

  • Fixed make worktree to support non-interactive usage via NAME parameter
  • Maintains backward compatibility with interactive prompts for human developers
  • Adds validation to prevent empty branch names with helpful error messages

Problem

Subagents were unable to use make worktree because it relied on an interactive read prompt. When the prompt received no input, it created an invalid branch name feature/, causing git errors.

Solution

Modified the worktree target in the Makefile to:

  1. Accept optional NAME parameter: make worktree NAME=my-feature
  2. Fall back to interactive prompt if NAME not provided: make worktree
  3. Validate that the name is not empty before proceeding
  4. Display helpful error message with usage instructions if validation fails

Changes

  • Makefile: Updated worktree target with parameter support and validation
  • Documentation: Help text updated to show new usage pattern

Usage Examples

# Subagent/non-interactive usage
make worktree NAME=fix-integration-tests

# Human/interactive usage (backward compatible)
make worktree
# Prompts: "Feature name: "

Testing

  • ✅ Tested non-interactive usage with make worktree NAME=test-makefile-fix
  • ✅ Verified all prek hooks pass
  • ✅ Confirmed backward compatibility with interactive mode

🤖 Generated with Claude Code

Summary by Sourcery

Allow creating git worktrees non-interactively while preserving existing interactive workflow.

New Features:

  • Support creating git worktrees via a NAME parameter for non-interactive and scripted usage.

Bug Fixes:

  • Prevent creation of worktrees with empty feature branch names by validating input and failing with a clear error message.

Enhancements:

  • Improve Makefile worktree target help text to document the new NAME-based usage pattern.

Previously, `make worktree` used an interactive `read` prompt that failed
for subagents (resulting in invalid branch name `feature/`). Now supports:

- Non-interactive: `make worktree NAME=my-feature` (for subagents)
- Interactive: `make worktree` (prompts for name, backward compatible)
- Validation: Fails gracefully if name is empty with helpful error message

This allows subagents to create worktrees without manual intervention while
maintaining the interactive experience for human developers.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 23, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates the Makefile's worktree target to support a non-interactive NAME parameter while preserving interactive behavior and adding validation/error messaging for empty feature names.

Sequence diagram for updated make worktree target with NAME parameter

sequenceDiagram
  title "Sequence diagram for updated make worktree target with NAME parameter"
  actor "Developer"
  participant "make"
  participant "shell"
  participant "git"

  "Developer"->>"make": "Invoke 'make worktree [NAME=my-feature]'"
  "make"->>"shell": "Execute 'worktree' target commands"

  alt "NAME parameter is provided"
    "shell"->>"shell": "Set 'name' from '$(NAME)'"
  else "NAME parameter is not provided"
    "shell"->>"Developer": "Prompt 'Feature name: '"
    "Developer"-->>"shell": "Enter feature name"
  end

  "shell"->>"shell": "Check if 'name' is empty"

  alt "Name is empty"
    "shell"-->>"Developer": "Print 'ERROR: Feature name cannot be empty'"
    "shell"-->>"Developer": "Print 'Usage: make worktree NAME=my-feature'"
    "shell"->>"shell": "Exit with status 1"
  else "Name is not empty"
    "shell"->>"git": "git checkout main"
    "git"-->>"shell": "'main' checked out"
    "shell"->>"git": "git pull"
    "git"-->>"shell": "Repository updated"
    "shell"->>"git": "git worktree add 'worktrees/name' -b 'feature/name'"
    "git"-->>"shell": "Worktree created"
    "shell"->>"shell": "mkdir -p 'worktrees/name/.claude'"
  end
Loading

File-Level Changes

Change Details Files
Make the git worktree target usable non-interactively via a NAME parameter while preserving interactive usage and validating the feature name.
  • Extend the worktree target help text to document non-interactive usage with NAME parameter.
  • Introduce conditional logic to use the NAME make variable if provided, otherwise fall back to an interactive read prompt to capture the feature name.
  • Add validation to ensure the resolved feature name is not empty, printing an error and usage hint and exiting with a non-zero status when it is.
  • Keep the existing git workflow steps (checkout main, pull, create worktree/branch, mkdir .claude) but parameterize them with the validated feature name.
Makefile

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@railway-app
Copy link

railway-app bot commented Nov 23, 2025

🚅 Environment byte-pr-126 in byte has no services deployed.

@railway-app railway-app bot temporarily deployed to byte (byte / byte-pr-126) November 23, 2025 21:44 Destroyed
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • The empty-name validation currently treats a string of only spaces as valid; consider trimming whitespace from the input (both interactive and NAME-based) before the -z check to prevent creating branches like feature/ .
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The empty-name validation currently treats a string of only spaces as valid; consider trimming whitespace from the input (both interactive and NAME-based) before the -z check to prevent creating branches like `feature/   `.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@JacobCoffee JacobCoffee merged commit 484e795 into main Nov 23, 2025
5 checks passed
@JacobCoffee JacobCoffee deleted the feature/make-worktree-subagent-friendly branch November 23, 2025 21:48
@github-actions
Copy link

Documentation preview will be available shortly at https://jacobcoffee.github.io/byte-docs-preview/126

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.

1 participant