---
title: "Environment variables"
url: "/docs/reference/environment-variables"
description: "The TNX_* variables 10nx sets in terminals, agents and scripts, and how to add your own"
---

# Environment variables

10nx tells every terminal, agent and script which worktree it's in through `TNX_*` environment variables. You can add your own with `environment_variables` in your user settings file or the repo's gitignored `.10nx/settings.local.toml`.

Use this page when a script or server needs to know its worktree's folder, name or ports.

## The variables 10nx sets

| Variable | Value | Example |
| --- | --- | --- |
| `TNX_WORKSPACE_NAME` | The worktree's folder name, or the repo's for the main checkout | `fix-login` |
| `TNX_WORKSPACE_PATH` | The worktree's folder, which is also the scripts' working folder | `/Users/you/code/app/.claude/worktrees/fix-login` |
| `TNX_ROOT_PATH` | The main checkout | `/Users/you/code/app` |
| `TNX_DEFAULT_BRANCH` | The repo's base branch | `main` |
| `TNX_PORT` | The first of the worktree's 10 ports. Only set when it has some | `41020` |
| `TNX_SESSION_ID` | The terminal tab's session id. Terminal and agent tabs only | `a1b2c3…` |
| `TNX_AGENT_NAME` | The tab's name when it was opened with one (`tnx agent open --name`). Agent tabs only | `pi-worker` |

`TNX` stands for 10nx: a variable name can't start with a digit.

## Ports

Each worktree 10nx creates gets a block of 10 ports, `TNX_PORT` to `TNX_PORT + 9`:

```bash
npm run dev -- --port "$TNX_PORT"
api --port "$((TNX_PORT + 1))"
```

Blocks start at 41000 and go up to 44999. 10nx skips a block another worktree holds or one with a port already in use on your Mac. A worktree keeps its block until 10nx removes it. The main checkout has no block, so `TNX_PORT` isn't set there.

## Where they're set

| | `TNX_*` | `TNX_SESSION_ID` | `environment_variables` |
| --- | --- | --- | --- |
| Terminal and agent tabs | Yes | Yes | Yes |
| Run menu tabs | Yes | Yes | Yes |
| Setup and archive scripts | Yes | No | Yes |

## Your own variables

Put them in `~/.10nx/settings.toml` (every repo) or the repo's `.10nx/settings.local.toml` (this repo only, gitignored):

```toml
# .10nx/settings.local.toml
[environment_variables]
DATABASE_URL = "postgres://localhost:5432/app_${TNX_WORKSPACE_NAME}"
API_BASE = "http://localhost:$TNX_PORT"
```

- Values may use `$TNX_X` or `${TNX_X}`, which 10nx fills in. Any other `$VAR` is left for the shell.
- The table merges across the two files, so your local file can add or override one variable from your user file.
- They're applied after the `TNX_*` variables, so a name you set wins.
- **A committed `.10nx/settings.toml` can't set them.** A copy there is ignored, and Settings says so. Otherwise anyone whose repo you clone could choose your shell's startup files, git's config or where Claude sends your credentials. A `settings.local.toml` that git tracks is ignored for the same reason.
- **Not for secrets.** Keep secrets in a gitignored `.env` that your app reads.

## Next steps

- [Scripts](scripts.md)
- [Set up a repo for worktrees](../guides/set-up-worktrees.md)
- [Settings reference](settings.md#worktrees)
