Skip to content
Browse the docs
reference

Configuration

Config file, environment variables, and default settings

Config file

zgrok stores configuration in ~/.zgrok/config.yaml. This file is created automatically when you run zgrok login or zgrok config add-authtoken.

All fields

yaml
# ~/.zgrok/config.yaml
 
# API key (required for tunnel creation)
api_key: "zk_abc123def456"
 
# Default server address (optional, defaults to relay.zgrok.io:4433)
server: "relay.zgrok.io:4433"
 
# Active project: new tunnels open at <name>--acme-shop.zgrok.io. Set by
# `zgrok project acme-shop`; --project overrides it for one run.
project: "acme-shop"
 
# Default tunnel name, so you can skip --subdomain. Pro only: this is the same claim
# as --subdomain, and on Free the name cannot be claimed. See below.
default_subdomain: "myapp"
 
# Default local port (skip the port argument)
default_port: 3000
 
# Show request logs in terminal (default: true)
log_requests: true
 
# Auto-reconnect on connection drop (default: true)
auto_reconnect: true
 
# Run the local request inspector (default: true)
inspect: true
 
# Port for the local inspector (default: 4040)
inspect_port: 4040
 
# Stable token for `zgrok ai` (optional). See below.
ai_token: "my-stable-ai-token"

With config defaults

When default_port and default_subdomain are set, you can just run:

bash
zgrok http
# Equivalent to: zgrok http 3000 --subdomain myapp
# and served at https://myapp--acme-shop.zgrok.io

default_subdomain is a Pro setting

default_subdomain does exactly what --subdomain does, which is to claim a name, so it carries the same plan rule. Claiming a name is a Pro feature.

On the Free plan the server assigns you an address per session and rewrites it on the next fresh zgrok http, so a default_subdomain in your config names something you no longer hold. The CLI does not fail on that: it prints

→ `myapp` from `default_subdomain` in ~/.zgrok/config.yaml was not available — using the assigned address

and starts the tunnel on a new assigned address. Clearing the key is the fix: on Free there is nothing it can do for you.

AI tunnel token

zgrok ai requires an access token that clients send as Authorization: Bearer <token>. It is resolved in this order:

  1. --token flag: zgrok ai 1234 --token my-long-secret-token
  2. ai_token in the config file: a stable token, so you can save it once in your client (or phone app) and reuse it across sessions
  3. Auto-generated: if neither is set, zgrok mints a random zg_ai_… token and prints it in the banner each session

Set a stable one so the URL and token stay the same every time:

yaml
# ~/.zgrok/config.yaml
ai_token: "my-stable-ai-token"
bash
zgrok ai            # uses ai_token from config

The token is validated at zgrok's edge and never reaches your model. See the Local AI guide for the full workflow.

Request inspector

Every tunnel runs a request inspector on 127.0.0.1, on by default. Two keys control it:

yaml
# ~/.zgrok/config.yaml
inspect: false        # never run it (same as passing --no-inspect on every run)
inspect_port: 4100    # bind here instead of 4040

--no-inspect and --inspect-port override both, and an explicit --inspect-port 4040 beats a config value: the flag is honoured as typed, never treated as "unset" just because it matches the default.

The JSON export flags (--log-json, --log-file) have no config equivalent, deliberately: writing a file on every run is a decision worth making per invocation.

Environment variables

VariableDescription
ZGROK_API_KEYAPI key (overrides config file)

Priority order

For the API key, zgrok checks in this order:

  1. CLI flag (--api-key KEY)
  2. Environment variable (ZGROK_API_KEY)
  3. Config file (~/.zgrok/config.yaml)

For other settings (port, subdomain, log_requests, inspect, inspect_port):

  1. CLI flag (always wins)
  2. Config file (fallback)

Managing your config

Save API key

bash
zgrok login

Or, on a machine with no browser, save a key you already have:

bash
zgrok config add-authtoken YOUR_API_KEY

View config file

bash
cat ~/.zgrok/config.yaml

Reset config

bash
rm ~/.zgrok/config.yaml

See also