Every time Agentastic creates a new worktree for an agent, you can run a setup script to bring that worktree to a working state automatically. Use setup scripts to install dependencies, copy environment files, run database migrations, or perform any other initialization your project needs. This page covers both the worktree setup script (per-repository) and the container setup script (per-machine).Documentation Index
Fetch the complete documentation index at: https://docs.agentastic.dev/llms.txt
Use this file to discover all available pages before exploring further.
Worktree setup script
The worktree setup script runs inside each new worktree directory immediately after Agentastic creates it. It is defined per repository, so different projects can have different setup routines.Location and permissions
Create the script in your repository at:Environment variables
Agentastic injects the following variables into your script at runtime:| Variable | Description | Example |
|---|---|---|
AGENTASTIC_BRANCH | New branch name | feature-auth |
AGENTASTIC_BASE_BRANCH | Base branch, if specified | main |
AGENTASTIC_WORKTREE_PATH | Absolute path to the new worktree | /Users/dev/repo-worktrees/feature-auth |
AGENTASTIC_MAIN_REPO_PATH | Absolute path to the main repository | /Users/dev/repo |
AGENTASTIC_COMMIT | Commit SHA the worktree is based on | abc123def456... |
AGENTASTIC_REPO_NAME | Repository folder name | my-project |
Basic example
Advanced example
This script detects the package manager, copies all.env files, and handles Ruby, Python, and Rails projects in addition to Node.js:
Behavior notes
- The script runs from the new worktree directory as its working directory.
- Execution is non-blocking — worktree creation succeeds even if the script exits with an error.
- Script output appears in the Worktree Setup task panel.
- You can re-run the setup script at any time from the task panel.
Container setup script
The container setup script runs on your host machine before Agentastic creates a container. Instead of performing setup actions directly, it outputs a JSON object that Agentastic uses to configure the container.Location
How it works
Agentastic runs your script
Agentastic executes the script with environment variables describing the worktree being containerized.
Your script prints JSON to stdout
The JSON object tells Agentastic which paths to mount, which environment variables to inject, and how to configure the container.
Output format
Your script must print a JSON object to stdout with the following structure:Default script
Agentastic creates a default script the first time you use containers. To open it for editing:Example customization
Add a shared npm cache mount and a custom environment variable to the default script:Environment variables
Agentastic passes these variables to the container setup script:| Variable | Description |
|---|---|
AGENTASTIC_WORKTREE_PATH | Path to the worktree being containerized |
AGENTASTIC_REPO_NAME | Repository name |
AGENTASTIC_BRANCH | Branch name |
AGENTASTIC_MOUNT_SSH_KEYS | true or false |
AGENTASTIC_MOUNT_GIT_CONFIG | true or false |
AGENTASTIC_COPY_SHELL_CONFIG | true or false |
AGENTASTIC_NETWORK_MODE | bridge, restricted, or none |
Resetting the container setup script
If your container setup script produces invalid output or you want to start fresh:- Open Settings > Agents
- Click Reset Setup Script
Teardown scripts
Agentastic does not currently run teardown scripts automatically. To clean up a worktree when you are done:- Stop any running processes in the worktree
- Remove the worktree via Settings > Agents or by running
git worktree remove <path> - Containers are stopped and removed automatically when you close the associated worktree
Best practices
Write idempotent scripts
Your script may be run more than once — for example, if you trigger it manually from the task panel. Make each step safe to repeat:Handle errors gracefully
Useset -euo pipefail to catch errors early, or handle individual failures explicitly:
Log progress
Print messages at each stage so you can follow along in the task panel:Test your script manually
Before committing, run the script yourself with the expected environment variables to catch any issues:Troubleshooting
Script is not running
Script is not running
Check three things:
- The file exists at
.agentastic/setup.sh - It is executable:
chmod +x .agentastic/setup.sh - It has no syntax errors:
bash -n .agentastic/setup.sh
Script fails silently
Script fails silently
Add shell debugging flags at the top of your script:The output appears in the Worktree Setup task panel.
Environment variables are missing
Environment variables are missing
Print them at the start of your script to verify they are being injected:
Container setup script outputs invalid JSON
Container setup script outputs invalid JSON
Test the script directly and pipe its output through If
jq to find syntax errors:jq reports a parse error, fix the JSON syntax in your script and test again.