---
title: "Scripts"
url: "/docs/reference/scripts"
description: "The setup, run and archive scripts: when each runs, where, with what, and for how long"
---

# Scripts

A repo can give 10nx three kinds of script: **setup** runs when 10nx creates a worktree, **run** actions fill the Run menu, and **archive** runs before 10nx removes a worktree. All three live in the settings files, usually the repo's shared `.10nx/settings.toml`.

Use this page for the exact rules. For a walk-through, see [Set up a repo for worktrees](../guides/set-up-worktrees.md) and [Add actions to the Run menu](../guides/run-menu.md).

## At a glance

| | `scripts.setup` | `[scripts.run.<id>]` | `scripts.archive` |
| --- | --- | --- | --- |
| Runs | After 10nx creates a worktree, or on **Run setup** | When you pick it in the Run menu | Before 10nx removes a worktree |
| Folder | The new worktree | The repo root, or the worktree with `per_worktree`, plus `cwd` | The worktree being removed |
| Shown in | The Setup view | A tab in the terminal section | Nowhere; it runs in the background |
| Can read input | No | Yes | No |
| Time limit | 15 minutes | None | 5 minutes |
| On failure | The Setup view shows "failed" with the output | The tab shows the exit | The worktree is removed anyway |
| Gets `TNX_*` | Yes, without `TNX_SESSION_ID` | Yes | Yes, without `TNX_SESSION_ID` |

## How they run

Every script runs through your login shell as `$SHELL -i -c "<script>"`, so the `PATH`, aliases and tools from your shell setup are there. Setup and archive have no keyboard attached (input is empty), so a script that waits for an answer fails rather than hanging. When a time limit is reached, 10nx stops the script and everything it started, and the log ends with `[10nx] stopped after Ns`.

A slow shell startup file slows every script. If your rc file prompts for something, make it skip that when the shell has no terminal.

## Setup

```toml
[scripts]
setup = "./scripts/setup-worktree.sh"
```

The order, as the Setup view shows it:

1. Create the worktree from the base branch (fetched from `origin` first when there is one).
2. Copy gitignored files ([Files to copy](files-to-copy.md)).
3. Reserve 10 ports.
4. Run the setup script.

While it runs you can **Skip to Claude**. When it fails: **Rerun setup** or **Ask Claude to fix it**. When it succeeds, the default agent opens in the worktree, once.

For a worktree 10nx didn't create, right-click its pill › **Run setup** copies missing files, reserves ports if it has none, and runs the script.

## Run actions

```toml
[scripts.run.test]
command = "npm test"
label = "Tests"
per_worktree = true
```

| Field | Type | Does |
| --- | --- | --- |
| `command` | string | What to run. An entry without one is dropped |
| `label` | string | The menu name. Defaults to the id |
| `args` | array of strings | Added after `command`, each shell-quoted (no `$VAR` expansion) |
| `cwd` | string | Run from this folder, relative to the checkout |
| `per_worktree` | boolean | Run in the active worktree, one tab per worktree |
| `default` | boolean | Listed first. Only the first such entry counts |
| `hide` | boolean | Off the menu |
| `icon` | string | Saved, for a future menu icon |

`scripts.run_mode = "nonconcurrent"` makes starting one action stop the others. The default, `concurrent`, lets them run together.

Entries merge across layers by id, field by field, so a local file can hide or change one shared action. ▶ in a `Makefile` or `package.json` writes an entry to your local file.

## Archive

```toml
[scripts]
archive = "docker compose down -v"
```

Removing a worktree (from the **▾** list or its pill's menu) runs, in order: the archive script, `git worktree remove`, freeing its ports, and, with `git.delete_branch_on_remove = true`, deleting its branch when no other checkout uses it. A failed archive script doesn't stop the removal.

## Next steps

- [Environment variables](environment-variables.md)
- [Files to copy](files-to-copy.md)
- [Settings reference](settings.md#worktrees)
