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
# ~/.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:
zgrok http
# Equivalent to: zgrok http 3000 --subdomain myapp
# and served at https://myapp--acme-shop.zgrok.iodefault_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:
--tokenflag:zgrok ai 1234 --token my-long-secret-tokenai_tokenin the config file: a stable token, so you can save it once in your client (or phone app) and reuse it across sessions- 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:
# ~/.zgrok/config.yaml
ai_token: "my-stable-ai-token"zgrok ai # uses ai_token from configThe 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:
# ~/.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
| Variable | Description |
|---|---|
ZGROK_API_KEY | API key (overrides config file) |
Priority order
For the API key, zgrok checks in this order:
- CLI flag (
--api-key KEY) - Environment variable (
ZGROK_API_KEY) - Config file (
~/.zgrok/config.yaml)
For other settings (port, subdomain, log_requests, inspect, inspect_port):
- CLI flag (always wins)
- Config file (fallback)
Managing your config
Save API key
zgrok loginOr, on a machine with no browser, save a key you already have:
zgrok config add-authtoken YOUR_API_KEYView config file
cat ~/.zgrok/config.yamlReset config
rm ~/.zgrok/config.yamlSee also
- CLI Reference: all commands and flags
- Request Inspector: what
inspectandinspect_portcontrol - Local AI: expose Ollama / LM Studio with
zgrok ai - Installation: initial setup