openclaw - 💡(How to fix) Fix doctor --repair / gateway install silently wipes custom EnvironmentVariables from LaunchAgent plist [4 comments, 5 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#49311Fetched 2026-04-08 00:56:40
View on GitHub
Comments
4
Participants
5
Timeline
10
Reactions
0
Timeline (top)
cross-referenced ×6commented ×4

openclaw doctor --repair and openclaw gateway install regenerate the LaunchAgent plist from scratch, silently dropping any custom EnvironmentVariables that were previously set (e.g., ANTHROPIC_API_KEY). This causes the gateway to restart without the API key, breaking all LLM calls until the user manually re-injects it.

Error Message

  • Warn the user that custom env vars will be wiped before overwriting

Root Cause

openclaw doctor --repair and openclaw gateway install regenerate the LaunchAgent plist from scratch, silently dropping any custom EnvironmentVariables that were previously set (e.g., ANTHROPIC_API_KEY). This causes the gateway to restart without the API key, breaking all LLM calls until the user manually re-injects it.

Fix Action

Workaround

Set apiKey directly in openclaw.json under models.providers.anthropic instead of relying on the env var. The config value takes precedence and survives plist regeneration.

RAW_BUFFERClick to expand / collapse

Summary

openclaw doctor --repair and openclaw gateway install regenerate the LaunchAgent plist from scratch, silently dropping any custom EnvironmentVariables that were previously set (e.g., ANTHROPIC_API_KEY). This causes the gateway to restart without the API key, breaking all LLM calls until the user manually re-injects it.

Environment

  • OpenClaw: 2026.3.13 (61d171a)
  • macOS 15 (arm64)
  • LaunchAgent: ~/Library/LaunchAgents/ai.openclaw.gateway.plist

Steps to Reproduce

  1. Set ANTHROPIC_API_KEY in the plist EnvironmentVariables (e.g., via PlistBuddy or manually)
  2. Run openclaw doctor --repair or openclaw gateway install
  3. The plist is regenerated without the custom env var
  4. Gateway restarts, cannot find Anthropic API key, all agent calls fail

Expected Behavior

Either:

  • Preserve existing EnvironmentVariables entries when regenerating the plist (merge, not replace)
  • Warn the user that custom env vars will be wiped before overwriting
  • Read from auth-profiles.json at startup if no env var or config apiKey is found (the auth store already has the token)

Workaround

Set apiKey directly in openclaw.json under models.providers.anthropic instead of relying on the env var. The config value takes precedence and survives plist regeneration.

Context

Users who configured Anthropic via secrets.source: env or the onboarding wizard (which sets up auth-profiles but not necessarily the config apiKey) are affected. The auth-profiles store at agents/main/agent/auth-profiles.json has the token, but the gateway startup path does not fall through to it when the env var is missing and no config apiKey is set.

This creates a frustrating loop: user runs doctor to fix an issue -> doctor wipes the key -> gateway breaks -> user runs doctor again.

extent analysis

Fix Plan

To address the issue, we need to modify the openclaw doctor --repair and openclaw gateway install commands to preserve existing EnvironmentVariables in the LaunchAgent plist.

Here are the steps:

  • Modify the plist generation code to read the existing plist and merge the new settings with the existing EnvironmentVariables.
  • Add a warning to inform the user that custom env vars will be overwritten if they are not preserved.

Example Code

import plistlib

def merge_env_vars(new_plist, existing_plist):
    """Merge new env vars with existing ones"""
    if 'EnvironmentVariables' in existing_plist:
        new_plist['EnvironmentVariables'] = existing_plist['EnvironmentVariables']
    return new_plist

def generate_plist(new_settings, existing_plist_path):
    """Generate new plist with merged env vars"""
    existing_plist = plistlib.load(open(existing_plist_path, 'rb'))
    new_plist = merge_env_vars(new_settings, existing_plist)
    return new_plist

def write_plist(plist, path):
    """Write plist to file"""
    plistlib.dump(plist, open(path, 'wb'))

# Example usage
new_settings = {'Label': 'ai.openclaw.gateway', 'ProgramArguments': ['openclaw', 'gateway']}
existing_plist_path = '~/Library/LaunchAgents/ai.openclaw.gateway.plist'
new_plist = generate_plist(new_settings, existing_plist_path)
write_plist(new_plist, existing_plist_path)

Verification

To verify the fix, follow these steps:

  • Set a custom EnvironmentVariable in the LaunchAgent plist.
  • Run openclaw doctor --repair or openclaw gateway install.
  • Check the LaunchAgent plist to ensure the custom EnvironmentVariable is still present.
  • Verify that the gateway starts correctly and can find the Anthropic API key.

Extra Tips

  • Consider adding a fallback to read the auth-profiles.json file if no EnvironmentVariable or config apiKey is found.
  • Document the importance of preserving custom EnvironmentVariables when regenerating the LaunchAgent plist.

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 - 💡(How to fix) Fix doctor --repair / gateway install silently wipes custom EnvironmentVariables from LaunchAgent plist [4 comments, 5 participants]