feat: setup/teardown commands and configurable symlink dirs in project settings
Add per-project setup and teardown commands that run automatically when worktrees are created or removed. This lets users configure things
like npm install, environment setup, or cleanup scripts that execute in the context of each task's worktree.
Setup/teardown commands:
- Configurable in Edit Project dialog via a reusable
CommandListEditorcomponent $PROJECT_ROOTand$WORKTREEvariable substitution in commands- Setup runs after worktree creation, before the agent starts; teardown runs before worktree removal
- Live output displayed in a
SetupBannerabove the terminal with retry/skip on failure - Initial prompt is stashed during setup to prevent the agent from acting before setup completes
Configurable symlink directories:
- Replace hardcoded symlink candidate list with per-project
defaultSymlinkDirssetting - New
PathSelectorcomponent with autocomplete backed byListProjectEntriesIPC (Tab to navigate into subdirectories, supports nested
paths) - New-task dialog pre-fills symlink dirs from project defaults instead of scanning gitignored entries
Security: shell metacharacter injection via $PROJECT_ROOT/$WORKTREE substitution
setup.ts substitutes projectRoot and worktreePath into the command string, then passes the result to spawn(cmd, { shell: true }). If either path contains shell metacharacters (spaces, $, backticks, semicolons, etc.), the shell will interpret them. Example: a project path of /home/user/my project; echo pwned would result in two shell commands being executed.
// setup.ts – the substituted string is passed directly to a shell
const cmd = expandVars(raw); // e.g. "npm install --prefix /home/user/my project; echo pwned"
spawn(cmd, { shell: true, ... });
Fix options:
- Shell-quote the substituted values when inserting them (e.g. wrap in single-quotes, escaping any single-quote inside with
'\''). - Pass commands as an argument array to
spawnand handle variable substitution at the array level (though this prevents users from using pipes/redirects in their commands, which may be intentional).
The simplest safe fix is to quote the values:
const shellQuote = (s: string) => `'${s.replace(/'/g, "'\\''")}'`;
const expandVars = (cmd: string): string =>
cmd
.replace(/\$\{PROJECT_ROOT\}|\$PROJECT_ROOT\b/g, () => shellQuote(projectRoot))
.replace(/\$\{WORKTREE\}|\$WORKTREE\b/g, () => shellQuote(worktreePath));
In practice, project roots set by the user on their own machine make this low-severity, but it's worth closing if paths can ever contain spaces (common on macOS).
This is a new finding not covered by the existing review — all other items I checked were already thoroughly addressed by @johannesjo.
Thank you very much! <3
@linniksa Thank you very much for this! Sorry for the delay. I took the liberty to make some adjustments. Could you maybe have a look if the updated version fits your vision?
@linniksa thank you for submitting this. I haven't seen any further updates from you so I'll close this out in the next few days if you are not available to move this forward. Of course you are welcome to re-open this or submit a new PR anytime.