Skip to content

feat: add auto_create worktree config option#369

Open
naps62 wants to merge 4 commits intoasheshgoplani:mainfrom
naps62:feature/auto-create-worktree
Open

feat: add auto_create worktree config option#369
naps62 wants to merge 4 commits intoasheshgoplani:mainfrom
naps62:feature/auto-create-worktree

Conversation

@naps62
Copy link
Contributor

@naps62 naps62 commented Mar 18, 2026

Creates the [worktree] auto_create = true config option, which automatically enables the worktree for new sessions created in the TUI

Coupled with my other proposal #368 , this makes it possible to optionally press n -> Enter without having to repeat steps

I know N exists for quick creation, but it still seems useful to be able to setup defaults such as "I always want a worktree by default"

Copilot AI review requested due to automatic review settings March 18, 2026 14:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new worktree.auto_create user-config option to automatically create git worktrees/branches for new sessions (and to default the UI/CLI into worktree mode when applicable).

Changes:

  • Introduces WorktreeSettings.AutoCreate in user config (toml:"auto_create").
  • Enables auto-worktree behavior in CLI commands (add, launch, session fork) by generating a branch name when --worktree isn’t provided.
  • Defaults the TUI “New Session” dialog to worktree-enabled when auto_create is set.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
internal/ui/newdialog.go Defaults the new-session dialog into worktree mode when auto_create is enabled.
internal/session/userconfig.go Adds the auto_create config field and documents intended behavior.
cmd/agent-deck/main.go Adds auto-worktree branch selection during agent-deck add.
cmd/agent-deck/launch_cmd.go Adds auto-worktree branch selection during agent-deck launch.
cmd/agent-deck/session_cmd.go Adds auto-worktree branch selection during agent-deck session fork.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 251 to +254
d.branchPrefix = userConfig.Worktree.Prefix()
if userConfig.Worktree.AutoCreate {
d.worktreeEnabled = true
}
type WorktreeSettings struct {
// AutoCreate: automatically create a worktree for every new session in a git repo.
// When true, sessions created without an explicit -w flag will get an auto-generated
// branch and worktree. Can be skipped per-session with --no-worktree.
Comment on lines +1017 to +1038
// Resolve title before worktree creation (auto-create needs title for branch name)
if sessionTitle == "" {
sessionTitle = filepath.Base(path)
}

// Track if user provided explicit title or we auto-generated from folder name
userProvidedTitle := (mergeFlags(*title, *titleShort) != "")
isQuick := *quickCreate || *quickCreateShort

if isQuick && !userProvidedTitle {
// Quick mode: use auto-generated adjective-noun name
sessionTitle = session.GenerateUniqueSessionName(instances, sessionGroup)
} else if !userProvidedTitle {
// User didn't provide title - auto-generate unique title for this path
sessionTitle = generateUniqueTitle(instances, sessionTitle, path)
} else {
// User provided explicit title - check for exact duplicate (same title AND path)
if isDupe, existingInst := isDuplicateSession(instances, sessionTitle, path); isDupe {
fmt.Printf("Session already exists with same title and path: %s (%s)\n", existingInst.Title, existingInst.ID)
os.Exit(0)
}
}
Comment on lines +174 to +200
// Resolve title before worktree creation (auto-create needs title for branch name)
if sessionTitle == "" {
sessionTitle = filepath.Base(path)
}

// Check for duplicate and generate unique title
userProvidedTitle := (mergeFlags(*title, *titleShort) != "")
if !userProvidedTitle {
sessionTitle = generateUniqueTitle(instances, sessionTitle, path)
} else {
if isDupe, existingInst := isDuplicateSession(instances, sessionTitle, path); isDupe {
out.Error(
fmt.Sprintf("session already exists: %s (%s)", existingInst.Title, existingInst.ID),
ErrCodeAlreadyExists,
)
os.Exit(1)
}
}

// Auto-create worktree if configured or requested via CLI flag
if wtBranch == "" {
wtSettings := session.GetWorktreeSettings()
if wtSettings.AutoCreate && git.IsGitRepo(path) {
wtBranch = wtSettings.Prefix() + git.SanitizeBranchName(sessionTitle)
createNewBranch = true
}
}
Comment on lines +478 to +485
// Auto-create worktree if configured or requested via CLI flag
if wtBranch == "" {
wtSettings := session.GetWorktreeSettings()
if wtSettings.AutoCreate && git.IsGitRepo(inst.ProjectPath) {
wtBranch = wtSettings.Prefix() + git.SanitizeBranchName(forkTitle)
createNewBranch = true
}
}
@asheshgoplani
Copy link
Owner

Nice feature! A couple of things needed before merge:

  1. Missing tests: Please add a unit test for GetWorktreeSettings with auto_create = true and a test verifying the branch name generation pattern
  2. Missing escape hatch: The code comments reference --no-worktree but it's not implemented. Users with auto_create = true need a way to skip worktree creation per-session
  3. Cleanup: Remove spurious blank line changes in launch_cmd.go and main.go

Otherwise the implementation looks clean and is properly opt-in. Looking forward to the update!

naps62 and others added 2 commits March 19, 2026 17:26
When [worktree] auto_create = true is set in config.toml, new sessions
automatically get a git worktree without needing the -w flag. The TUI
dialog also defaults the worktree checkbox to checked. Only triggers
when the session path is inside a git repo.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Re-add --no-worktree/--no-wt flag to skip auto-creation per-session
- TUI: only enable worktree checkbox when path is a git repo, set
  branchAutoSet so branch auto-tracks name edits
- Move duplicate detection after worktree creation so it uses the final
  session path instead of the pre-worktree path
- Fork: add branch-exists check when createNewBranch is true to prevent
  silently reusing an existing branch

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@naps62 naps62 force-pushed the feature/auto-create-worktree branch from ee93653 to af8fbdf Compare March 19, 2026 17:28
naps62 and others added 2 commits March 19, 2026 17:30
The auto-name PR merged upstream changed createNewBranch to _ since
it's not used in launch or new-session commands (only in fork).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

3 participants