Dunea Code
Worktrees, ports and scripts
How each task gets its own branch, its own ports and its own running copy of your app.
One worktree per task
A git worktree is a second working folder for the same repository, checked out on a different branch. Dunea creates one for every task, next to your project, so agents never edit the same files. All worktrees share one .git history, so nothing is cloned again.
When a task is done and merged, Archive removes its folder. The branch, its commits and its chats are kept, and you can restore it from Home → Show archived. See Undo, history and archive.
Ports: $DUNEA_PORT
Two worktrees running the same app both want port 3000, so the second dev server fails with address already in use. Dunea leases every worktree its own block of ports and passes them to your scripts:
| Variable | Meaning |
|---|---|
DUNEA_PORT | The first port of this worktree's block |
DUNEA_PORT_COUNT | How many ports are in the block |
Use the first one for your dev server and count up for anything else that listens, such as an API server, a worker or a debugger. Your main checkout doesn't get DUNEA_PORT, so always give a default:
PORT="${DUNEA_PORT:-3000}"
API_PORT="$((PORT + 1))"Setup and run scripts
Put two scripts in a .dunea folder at the root of your repository:
| File | When it runs |
|---|---|
.dunea/setup.sh | Once, when a worktree is created: install dependencies, run migrations |
.dunea/run.sh | When you press Run: start your dev server on $DUNEA_PORT |
.dunea/archive.sh | Before a worktree is removed: stop anything it started |
A small example for a Next.js app:
#!/usr/bin/env bash
set -euo pipefail
pnpm install#!/usr/bin/env bash
set -euo pipefail
pnpm dev --port "${DUNEA_PORT:-3000}"Let an agent write them
Ask any agent in Dunea Code to "set up this repository for Dunea". It reads your project and writes setup.sh, run.sh and archive.sh for you, including extra ports for every service.
Your .env files come along
Worktrees start without your gitignored files. Dunea copies your .env files into every new worktree before setup runs, so secrets and local settings are in place before the agent starts.
Setup runs on new worktrees only if Run setup on new worktrees is on in Settings → General; otherwise press Run setup in the Setup tab.
Watching it run
Press Run in the worktree header (or ⌘R) to start run.sh. Its tab under the chat shows the output, and the Run menu offers Open in your browser. See Run, terminal and problems.
You can also edit these scripts per project in Settings → Project → Scripts, and Share to repo saves them for your team.