-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Status Quo
Worktrees are created at <repo-root>/.architect/<name> via buildCreateWorktreeCommand() in src/app/worktree.zig. This nests worktrees inside the repository directory tree. When an agent (e.g., Claude Code) runs in a worktree and walks up the directory tree to discover project configuration, it finds the root repository's CLAUDE.md in addition to the worktree's own copy, resulting in duplicate instructions.
There is currently no configuration option for the worktree location. The .architect/ path is hardcoded in worktree.zig (lines 46-48) and runtime.zig (line 1761). Discovery of existing worktrees uses collectFromGitMetadata() in worktree_overlay.zig, which reads from git's internal worktree tracking — this is already location-agnostic.
Additionally, new worktrees lack project-local state that is typically gitignored: .env, .envrc.local, tool trust files, etc. Users must manually copy these files and run setup commands (e.g., direnv allow) in every new worktree. There is no post-creation initialization mechanism.
Objectives
Agents running in worktrees should not encounter the parent repository's configuration files. By creating worktrees outside the repo directory tree, the upward directory walk stops before reaching the root repo, eliminating duplicate CLAUDE.md (or similar) discovery. The location should be configurable, with a sensible default that works without user intervention.
New worktrees should also be bootstrapped automatically — running project setup scripts to install dependencies, copy local config files, or approve tools like direnv — so they are ready to use immediately after creation.
User Flow
Trigger: User presses Cmd+0 in the worktree overlay and enters a worktree name.
- Architect resolves the worktree target directory from configuration (default:
~/.architect-worktrees/<repo-name>/<worktree-name>). git worktree add <target> -b <name>runs, creating the worktree outside the repo tree.- The shell
cds into the new worktree directory. - If
init_commandis configured, it runs. Otherwise, if a well-known init script exists in the new worktree (script/setupor.architect-init.sh), it runs automatically. - Existing worktrees (including legacy ones under
.architect/) continue to appear in theCmd+Tdropdown via git metadata discovery.
Result: New worktrees are filesystem-independent from the parent repo, fully bootstrapped, and ready for use. Agents running in them see only the worktree's own project files when traversing upward.
Scope
In scope:
- New
[worktree]section inconfig.tomlwithdirectoryandinit_commandoptions - Default worktree path:
~/.architect-worktrees/<repo-name>/<worktree-name> - Post-creation init: run configured
init_command, or auto-detectscript/setup/.architect-init.sh - Update
buildCreateWorktreeCommand()to use an absolute target path and append the init command - Update
runtime.zigCreateWorktree handler to compute the correctnew_path - Backwards compatibility: existing worktrees under
.architect/remain visible and switchable
Out of scope:
- Migrating existing
.architect/worktrees to the new location - Changing worktree discovery logic (already location-agnostic via git metadata)
- Changing worktree removal logic (already uses absolute paths)
- Changes to
.architect/diff_comments.jsonor other.architect/state storage - Symlink management for individual files (users can handle this in their init script)
Implementation Plan
Affected Modules
src/config.zig: AddWorktreeConfigstruct withdirectoryandinit_commandfieldssrc/app/worktree.zig: UpdatebuildCreateWorktreeCommand()to accept an absolute target path and append init command logicsrc/app/runtime.zig: Resolve the worktree target directory and init command from config when handlingCreateWorktree, pass them to the build function, and compute the correctnew_pathsrc/ui/types.zig: ExtendCreateWorktreeActionto carry the resolved target pathdocs/configuration.md: Document the new[worktree]section
Tasks
- Add
WorktreeConfigstruct tosrc/config.zigwithdirectory: ?[]const u8 = nullandinit_command: ?[]const u8 = null; wire it intoConfig—src/config.zig - Add a helper that resolves the effective worktree base directory: if
config.worktree.directoryis set, use it (expanding~); otherwise derive~/.architect-worktrees/<repo-name>/from the repo root —src/app/worktree.zig - Update
buildCreateWorktreeCommand()to accept a full absolute target path instead of constructing.architect/<name>—src/app/worktree.zig - Add init command logic to
buildCreateWorktreeCommand(): ifinit_commandis provided, append&& <init_command>; otherwise append a shell snippet that runsscript/setupor.architect-init.shif either exists —src/app/worktree.zig - Update
CreateWorktreehandler inruntime.zigto resolve the target directory and init command from config, pass them to the command builder, and computenew_pathcorrectly —src/app/runtime.zig - Add
[worktree]section to the default config template comment —src/config.zig - Update
docs/configuration.mdwith the new[worktree]section - Update
docs/ARCHITECTURE.mdif the worktree creation flow description changes - Update
README.mdto mention configurable worktree location and init scripts
New Dependencies
None
Acceptance Criteria
- New worktrees are created at
~/.architect-worktrees/<repo-name>/<worktree-name>by default - Setting
[worktree] directory = "/custom/path"overrides the base location - Setting
[worktree] init_command = "script/setup"runs that command after worktree creation - When no
init_commandis configured,script/setupor.architect-init.shruns automatically if present in the new worktree - Existing worktrees under
.architect/still appear in the dropdown and can be switched to / removed -
zig buildandzig build testpass -
just lintpasses - Documentation updated