Skip to content

Feature request - Add global_teardown_script to run during worktree cleanup #1065

@matthewbjones

Description

@matthewbjones

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions