feat: add auto_create worktree config option#369
Open
naps62 wants to merge 4 commits intoasheshgoplani:mainfrom
Open
feat: add auto_create worktree config option#369naps62 wants to merge 4 commits intoasheshgoplani:mainfrom
naps62 wants to merge 4 commits intoasheshgoplani:mainfrom
Conversation
There was a problem hiding this comment.
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.AutoCreatein user config (toml:"auto_create"). - Enables auto-worktree behavior in CLI commands (
add,launch,session fork) by generating a branch name when--worktreeisn’t provided. - Defaults the TUI “New Session” dialog to worktree-enabled when
auto_createis 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. |
cmd/agent-deck/main.go
Outdated
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) | ||
| } | ||
| } |
cmd/agent-deck/launch_cmd.go
Outdated
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 | ||
| } | ||
| } |
cmd/agent-deck/session_cmd.go
Outdated
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 | ||
| } | ||
| } |
Owner
|
Nice feature! A couple of things needed before merge:
Otherwise the implementation looks clean and is properly opt-in. Looking forward to the update! |
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>
ee93653 to
af8fbdf
Compare
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Creates the
[worktree] auto_create = trueconfig option, which automatically enables the worktree for new sessions created in the TUICoupled with my other proposal #368 , this makes it possible to optionally press
n -> Enterwithout having to repeat stepsI know
Nexists for quick creation, but it still seems useful to be able to setup defaults such as "I always want a worktree by default"