Bug Description
When running openclaw --profile hanyu gateway install, the generated LaunchAgent plist contains environment variables (OPENCLAW_STATE_DIR, OPENCLAW_CONFIG_PATH, OPENCLAW_GATEWAY_PORT) from the default profile instead of the specified profile.
Root Cause
In entry.js, applyCliProfileEnv uses conditional assignment:
if (!env.OPENCLAW_STATE_DIR?.trim()) env.OPENCLAW_STATE_DIR = stateDir;
if (!env.OPENCLAW_CONFIG_PATH?.trim()) env.OPENCLAW_CONFIG_PATH = path.join(stateDir, "openclaw.json");
When the shell already has OPENCLAW_STATE_DIR and OPENCLAW_CONFIG_PATH set (e.g., inherited from a running default gateway session or .zshrc), the --profile flag silently fails to override them.
Steps to Reproduce
- Have a default gateway running (which sets
OPENCLAW_STATE_DIR=~/.openclaw in the environment)
- Run:
openclaw --profile hanyu gateway install
- Inspect the generated plist:
cat ~/Library/LaunchAgents/ai.openclaw.hanyu.plist
- Observe that
OPENCLAW_STATE_DIR is ~/.openclaw instead of ~/.openclaw-hanyu
OPENCLAW_CONFIG_PATH, OPENCLAW_GATEWAY_PORT, --port, StandardOutPath, and StandardErrorPath are also wrong
Expected Behavior
--profile <name> should unconditionally override OPENCLAW_STATE_DIR, OPENCLAW_CONFIG_PATH, and related variables, since the user explicitly requested a different profile.
Suggested Fix
function applyCliProfileEnv(params) {
const env = params.env ?? process.env;
const homedir = params.homedir ?? os.homedir;
const profile = params.profile.trim();
if (!profile) return;
env.OPENCLAW_PROFILE = profile;
// Always override when --profile is explicitly provided
const stateDir = resolveProfileStateDir(profile, env, homedir);
env.OPENCLAW_STATE_DIR = stateDir;
env.OPENCLAW_CONFIG_PATH = path.join(stateDir, "openclaw.json");
if (profile === "dev" && !env.OPENCLAW_GATEWAY_PORT?.trim()) {
env.OPENCLAW_GATEWAY_PORT = "19001";
}
}
Impact
- Any multi-gateway / multi-profile deployment
- Any shell session that inherits
OPENCLAW_* env vars before running --profile
Environment
- OpenClaw: 2026.2.26
- Platform: macOS Darwin 25.2.0 (arm64)
- Node: v22.22.0
Workaround
Manually edit the generated plist file to correct the environment variables, paths, and port.
Bug Description
When running
openclaw --profile hanyu gateway install, the generated LaunchAgent plist contains environment variables (OPENCLAW_STATE_DIR,OPENCLAW_CONFIG_PATH,OPENCLAW_GATEWAY_PORT) from the default profile instead of the specified profile.Root Cause
In
entry.js,applyCliProfileEnvuses conditional assignment:When the shell already has
OPENCLAW_STATE_DIRandOPENCLAW_CONFIG_PATHset (e.g., inherited from a running default gateway session or.zshrc), the--profileflag silently fails to override them.Steps to Reproduce
OPENCLAW_STATE_DIR=~/.openclawin the environment)openclaw --profile hanyu gateway installcat ~/Library/LaunchAgents/ai.openclaw.hanyu.plistOPENCLAW_STATE_DIRis~/.openclawinstead of~/.openclaw-hanyuOPENCLAW_CONFIG_PATH,OPENCLAW_GATEWAY_PORT,--port,StandardOutPath, andStandardErrorPathare also wrongExpected Behavior
--profile <name>should unconditionally overrideOPENCLAW_STATE_DIR,OPENCLAW_CONFIG_PATH, and related variables, since the user explicitly requested a different profile.Suggested Fix
Impact
OPENCLAW_*env vars before running--profileEnvironment
Workaround
Manually edit the generated plist file to correct the environment variables, paths, and port.