openclaw - ✅(Solved) Fix CLI does not respect OPENCLAW_GATEWAY_TOKEN env var [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#70365Fetched 2026-04-23 07:25:37
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Participants
Timeline (top)
cross-referenced ×1

Root Cause

Two related issues:

  1. Env var not propagated: The CLI subprocess call does not pass --token "\$OPENCLAW_GATEWAY_TOKEN" to the gateway connection, even though the env var is set in the environment. The internal agent code correctly reads this env var, but the CLI does not.

  2. TLS detection is fragile: An empty {} object for gateway.tls in the config is treated as "attempt TLS" rather than "disabled". This causes connection failures when TLS is not configured.

Fix Action

Workaround

Pass --token explicitly on every command:

openclaw status --token "\$OPENCLAW_GATEWAY_TOKEN"

PR fix notes

PR #70378: fix(cli): respect OPENCLAW_GATEWAY_TOKEN env var in gateway RPC calls

Description (problem / solution / changelog)

Summary

Fixes #70365 (part 1: env-var propagation). The CLI's `callGatewayFromCliRuntime` passed the `--token` flag value through to `callGateway` verbatim, with no fallback to the `OPENCLAW_GATEWAY_TOKEN` env var that the embedded agent and much of the rest of the runtime already read (`src/pairing/setup-code.ts`, `src/cli/qr-cli.ts`, `src/cli/gateway-cli/run.ts`).

Result: when the token lives in env, `openclaw status` and friends hang for ~16s before failing. The documented workaround is to append `--token "$OPENCLAW_GATEWAY_TOKEN"` to every command.

Fix

Add `resolveCliGatewayToken(flagToken)` that falls back to the env var:

  1. explicit `--token` flag (unchanged behavior when passed)
  2. `OPENCLAW_GATEWAY_TOKEN` env var (new fallback)
  3. undefined (unchanged behavior when nothing is set)

Empty-string `--token` is treated as unset so the env fallback still applies — matches how other token-resolver sites in the codebase handle missing values.

Test

4 new regression tests in `src/cli/gateway-rpc.runtime.test.ts` cover: env used when flag absent, flag preferred over env, empty-string flag falls through, both absent ⇒ undefined.

oxlint clean.

Scope note

Part 2 of #70365 (TLS detection for empty `gateway.tls: {}`) is a separate concern in a different file — deliberately scoped out of this PR to keep the diff surgical. Happy to follow up if you'd like both fixed in one land.

Closes #70365 (partial — env propagation only).

Changed files

  • src/cli/gateway-rpc.runtime.test.ts (added, +56/-0)
  • src/cli/gateway-rpc.runtime.ts (modified, +18/-1)

Code Example

openclaw status --token "\$OPENCLAW_GATEWAY_TOKEN"
RAW_BUFFERClick to expand / collapse

Problem

The OpenClaw CLI (openclaw status, openclaw config validate, etc.) does not read the OPENCLAW_GATEWAY_TOKEN environment variable, even though the internal agent code does. This means commands that need gateway RPC connectivity hang for ~16 seconds before failing, unless you manually pass --token.

Root Cause

Two related issues:

  1. Env var not propagated: The CLI subprocess call does not pass --token "\$OPENCLAW_GATEWAY_TOKEN" to the gateway connection, even though the env var is set in the environment. The internal agent code correctly reads this env var, but the CLI does not.

  2. TLS detection is fragile: An empty {} object for gateway.tls in the config is treated as "attempt TLS" rather than "disabled". This causes connection failures when TLS is not configured.

Expected Behavior

  • openclaw status should respect OPENCLAW_GATEWAY_TOKEN the same way the embedded agent does
  • An empty gateway.tls: {} object should mean "TLS disabled" not "try TLS and fail"
  • Connection should succeed in ~50ms instead of ~16s when token is present in env

Workaround

Pass --token explicitly on every command:

openclaw status --token "\$OPENCLAW_GATEWAY_TOKEN"

Environment

  • OpenClaw 2026.4.21
  • Node.js 24.14.0
  • Platform: Linux (WSL2)

extent analysis

TL;DR

Pass the --token option with the OPENCLAW_GATEWAY_TOKEN environment variable to the OpenClaw CLI commands as a temporary workaround.

Guidance

  • Verify that the OPENCLAW_GATEWAY_TOKEN environment variable is set correctly in your environment before running the OpenClaw CLI commands.
  • Use the provided workaround by passing --token "\$OPENCLAW_GATEWAY_TOKEN" to each command, such as openclaw status --token "\$OPENCLAW_GATEWAY_TOKEN".
  • Check the OpenClaw configuration to ensure that gateway.tls is properly configured or explicitly set to disabled if not needed.
  • Consider updating the OpenClaw CLI to a version that may address the issue of not propagating the OPENCLAW_GATEWAY_TOKEN environment variable, if available.

Example

openclaw status --token "\$OPENCLAW_GATEWAY_TOKEN"

Notes

The provided workaround requires manually passing the token with each command, which may be inconvenient. A more permanent solution would involve fixing the OpenClaw CLI to properly read and use the OPENCLAW_GATEWAY_TOKEN environment variable.

Recommendation

Apply the workaround by passing --token "\$OPENCLAW_GATEWAY_TOKEN" to each OpenClaw CLI command, as this is the most straightforward way to address the issue given the current version of OpenClaw.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix CLI does not respect OPENCLAW_GATEWAY_TOKEN env var [1 pull requests, 1 participants]