Lifecycle scripts are commands the app runs automatically at key moments in a worktree's life — when it's created, when you run your app, and when it's deleted. You can also add your own custom scripts. This article covers each and where to set them up.
The three lifecycle scripts
- Setup — runs when a worktree is created, to prepare the checkout (for example, installing dependencies). A good setup script means a new worktree is ready to work in without any manual steps.
- Launch — defines how to run your app, so you can start it for testing and preview it in the in-app browser.
- Teardown — runs when you delete a worktree, to clean up after it so nothing is left behind.
Custom scripts
Beyond the three lifecycle scripts, you can define your own custom scripts for a workspace and run them whenever you need them — anything you'd otherwise run by hand.
Where they're configured
Set these up in your workspace's script settings. Each worktree also exposes its scripts, so you can see and run them from the worktree itself.
Next steps
- Create your first worktree — where the setup and launch scripts first come into play.
- Dev-server detection & the in-app browser — use your launch script to preview the app.
- Environments & runtimes — the variables your scripts and agents run with.