Environment Variables
Tuna supports environment variables for configuration and customization.
Config Interpolation
These variables can be used in the forward field of your tuna config:
$USER
The current system username.
{
"tuna": {
"forward": "$USER-api.example.com"
}
}Source: process.env.USER
Fallback: unknown
# User "alice" runs:
tuna npm run dev
# → alice-api.example.com$TUNA_USER
Custom identifier that overrides $USER.
{
"tuna": {
"forward": "$TUNA_USER-api.example.com"
}
}Source: process.env.TUNA_USER
Fallback: $USER
# Override for a specific environment
TUNA_USER=staging tuna npm run dev
# → staging-api.example.com
# Without override, falls back to $USER
tuna npm run dev
# → alice-api.example.com$HOME
User's home directory. Rarely used in domains.
Source: process.env.HOME
Fallback: ~
Runtime Environment Variables
These variables affect tuna's behavior at runtime:
TUNA_API_TOKEN
Override Keychain credentials with an API token.
export TUNA_API_TOKEN=your_cloudflare_token
export TUNA_ACCOUNT_ID=your_account_id
tuna npm run devUse case: CI/CD environments where Keychain isn't available.
TUNA_ACCOUNT_ID
Cloudflare account ID (used with TUNA_API_TOKEN).
export TUNA_ACCOUNT_ID=699d98642c564d2e855e9661899b7252TUNA_CLOUDFLARED_PATH
Custom path to cloudflared binary.
export TUNA_CLOUDFLARED_PATH=/custom/path/cloudflared
tuna npm run devDefault behavior: Tuna looks for cloudflared in:
PATH~/.tuna/bin/cloudflared
TUNA_HOME
Override the tuna data directory.
export TUNA_HOME=/custom/tuna/data
tuna npm run devDefault: ~/.tuna
tunnels/- Tunnel credential filesconfig-*.yml- Cloudflared configsbin/- Downloaded cloudflared binary
Examples
Team Development
Each developer gets their own subdomain automatically:
{
"tuna": {
"forward": "$USER-dev.example.com",
"port": 3000
}
}Feature Branches
Use TUNA_USER for feature-specific tunnels:
# Feature branch
TUNA_USER=feature-auth tuna npm run dev
# → feature-auth-dev.example.com
# Main branch
TUNA_USER=main tuna npm run dev
# → main-dev.example.comCI/CD Pipeline
Use environment variables instead of Keychain:
# GitHub Actions
- name: Start tunnel
env:
TUNA_API_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }}
TUNA_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
TUNA_USER: ci-${{ github.run_id }}
run: tuna npm run dev &Custom cloudflared
Use a specific version of cloudflared:
export TUNA_CLOUDFLARED_PATH=/opt/cloudflared-2024.1.0
tuna npm run devPrecedence
For config interpolation:
$TUNA_USER(if set)$USER(system username)unknown(fallback)
For credentials:
TUNA_API_TOKEN+TUNA_ACCOUNT_ID(if both set)- macOS Keychain (default)