Available Variables
Default server host for CLI commandsWhen set, all Surge CLI commands will connect to this server instead of starting a local instance. This is equivalent to passing Format:
--host on every command.Usage:host:port or ip:portCommand-line
--host flag overrides this environment variable.Bearer token for API authenticationSets the default authentication token for API requests. This is useful when connecting to headless servers or remote instances.Usage:Alternatively, retrieve your token using:
XDG Base Directory Variables (Linux)
On Linux, Surge respects the XDG Base Directory specification for organizing configuration, state, and runtime files.Base directory for configuration filesSurge stores
settings.json in $XDG_CONFIG_HOME/surge/.Default: ~/.config/surge/Base directory for state filesSurge stores the database (
surge.db), authentication token, and logs in $XDG_STATE_HOME/surge/.Default: ~/.local/state/surge/Base directory for runtime filesSurge stores PID file, port file, and lock file in
$XDG_RUNTIME_DIR/surge/.Fallback: If not set (e.g., in Docker or headless environments), falls back to $XDG_STATE_HOME/surge/.This directory is typically cleared on system reboot and should be located on a tmpfs filesystem.
Default downloads directoryIf set and the directory exists, Surge will use this as the default download location when
default_download_dir in settings.json is empty.Fallback: ~/Downloads or current directoryPlatform-Specific Variables
Windows
Application data directorySurge stores all configuration, state, and log files in
%APPDATA%\surge\.Temporary files directoryUsed for runtime files (PID, port, lock) in
%TEMP%\surge\.macOS
Temporary files directoryUsed for runtime files in
$TMPDIR/surge-runtime/.Default: Typically /var/folders/...Priority Order
Configuration values are resolved in the following priority order (highest to lowest):- Command-line flags (e.g.,
--host,--token) - Environment variables (e.g.,
SURGE_HOST,SURGE_TOKEN) - Configuration file (
settings.json) - Default values
Examples
Permanent Remote Connection
Set environment variables in your shell profile:Custom Configuration Location (Linux)
Session-Specific Token
Security Considerations
The token file in the state directory has
0600 permissions (read/write for owner only) for security.