Script Types
Termpad supports three types of scripts:| Type | When It Runs | Use For |
|---|---|---|
| Setup | When creating a new worktree | Installing dependencies, building assets |
| Run | When you click “Run” | Starting dev server, running tests |
| Cleanup | When deleting a worktree | Stopping processes, cleaning artifacts |
Configuring Scripts
Setup Scripts
Setup scripts run automatically when you create a new worktree. Use them for:- Installing dependencies
- Setting up environment files
- Building initial assets
- Starting background services
Scripts run in the default shell/terminal you configured in your settings. Write your commands using the syntax for that shell.
Creating worktrees by default doesn’t include any files in your
.gitignore. If you have .env variables in your main branch and want them brought over to the worktree, add that to your setup script.Examples
- Node.js
- Python
- Rust
- Go
Run Scripts
Run scripts are manually triggered commands for common tasks. You can have multiple run scripts per project.Creating run scripts
Common run scripts
| Name | Command | Purpose |
|---|---|---|
| Dev Server | npm run dev | Start development server |
| Tests | npm test | Run test suite |
| Build | npm run build | Build for production |
| Lint | npm run lint | Check code style |
| Format | npm run format | Format code |
Running a script
Exclusive mode
Some scripts can’t run in multiple worktrees (e.g., dev servers that need a specific port). Enable exclusive mode for these scripts. When you run an exclusive script:- Termpad checks if it’s running elsewhere
- If yes, it stops the other instance
- Then starts the script in your current worktree
Exclusive mode only detects scripts run using the Run Script feature. It won’t detect if you manually run the same command in your terminal.
Cleanup Scripts
Cleanup scripts run when you delete a worktree. When deleting a worktree, Termpad automatically removes the entire worktree directory. Cleanup scripts are useful for doing operations outside the working tree, for example removing build artifacts if applicable.Example
Environment Variables
Scripts have access to Termpad-provided environment variables:| Variable | Description |
|---|---|
TERMPAD_WORKSPACE_NAME | Workspace name |
TERMPAD_WORKSPACE_PATH | Workspace path |
TERMPAD_ROOT_PATH | Repository root directory path |
TERMPAD_PORT | Unique port for this worktree (100 ports available per repository) |
Using environment variables
Smart Port Management
Avoid port conflicts when running dev servers across worktrees:Script Tips
Chain commands
Run multiple commands in sequence:Handle failures gracefully
Use|| true to prevent script failure from blocking: