Problem
global_setup_script runs when a worktree is created, which is great for provisioning per-worktree resources (databases, dependencies, etc.). But when an issue reaches terminal state and Cyrus deletes the worktree, there's no hook to clean up those resources.
In our case, the setup script creates 8 isolated Postgres databases per worktree for a Rails multi-database app (primary, queue, cache, cable × dev + test). When Cyrus cleans up the worktree directory, the databases are orphaned.
Proposed Solution
Add global_teardown_script (matching the existing global_setup_script pattern) that runs before the worktree directory is deleted. The script should:
- Run in the worktree directory (so it can read .env.local or other config)
- Receive the same environment variables as the setup script (
LINEAR_ISSUE_ID, LINEAR_ISSUE_IDENTIFIER, LINEAR_ISSUE_TITLE)
- Be non-blocking on failure (log a warning but still delete the worktree)
Example Config
{
"global_setup_script": "~/.cyrus/scripts/worktree-setup.sh",
"global_teardown_script": "~/.cyrus/scripts/worktree-teardown.sh"
}
Workaround
Currently running a manual cleanup script that finds orphaned wt* databases and drops them. Works, but easy to forget.
Problem
global_setup_scriptruns when a worktree is created, which is great for provisioning per-worktree resources (databases, dependencies, etc.). But when an issue reaches terminal state and Cyrus deletes the worktree, there's no hook to clean up those resources.In our case, the setup script creates 8 isolated Postgres databases per worktree for a Rails multi-database app (primary, queue, cache, cable × dev + test). When Cyrus cleans up the worktree directory, the databases are orphaned.
Proposed Solution
Add
global_teardown_script(matching the existingglobal_setup_scriptpattern) that runs before the worktree directory is deleted. The script should:LINEAR_ISSUE_ID,LINEAR_ISSUE_IDENTIFIER,LINEAR_ISSUE_TITLE)Example Config
{ "global_setup_script": "~/.cyrus/scripts/worktree-setup.sh", "global_teardown_script": "~/.cyrus/scripts/worktree-teardown.sh" }Workaround
Currently running a manual cleanup script that finds orphaned wt* databases and drops them. Works, but easy to forget.