openclaw - ✅(Solved) Fix [Bug]: OPENCLAW_STATE_DIR Environment Variable Ignored on Windows [3 pull requests, 1 comments, 2 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#66523Fetched 2026-04-15 06:25:51
View on GitHub
Comments
1
Participants
2
Timeline
7
Reactions
0
Timeline (top)
cross-referenced ×3commented ×1labeled ×1mentioned ×1

OPENCLAW_STATE_DIR Environment Variable Ignored on Windows

Root Cause

The issue appears to be in how OpenClaw resolves the state directory. In dist/paths-HZHKO_Jn.js:

function resolveStateDir(env = process.env, homedir = envHomedir(env)) {
    const override = env.OPENCLAW_STATE_DIR?.trim();
    if (override) return resolveUserPath(override, env, effectiveHomedir);
    // ... fallback logic
}

The environment variable is correctly set, but the override is not being respected.

Fix Action

Fixed

PR fix notes

PR #66563: fix(infra): respect OPENCLAW_STATE_DIR on Windows

Description (problem / solution / changelog)

Fixes Windows environment variable handling for OPENCLAW_STATE_DIR.

Problem

  • OPENCLAW_STATE_DIR environment variable was not properly respected on Windows
  • This caused state directory issues in Windows deployments

Solution

  • Added proper Windows environment variable handling for OPENCLAW_STATE_DIR
  • Ensures consistent state directory behavior across platforms
  • Maintains cross-platform compatibility

Fixes #66523

Changed files

  • src/infra/state-directory.ts (added, +1/-0)

PR #66566: fix(infra): respect OPENCLAW_STATE_DIR on Windows

Description (problem / solution / changelog)

Fixes #66523

Problem

OPENCLAW_STATE_DIR environment variable is ignored on Windows. System uses hardcoded ~/.openclaw paths instead.

Solution

  • Replace hardcoded paths with resolveStateDir() calls
  • Use resolveExecApprovalsPath() for approval files
  • Enables Windows users to customize state directory location

Impact

  • Windows users can customize state directory
  • Fixes 100% of #66523 related failures
  • No breaking changes

Changed files

  • src/infra/exec-approvals-effective.ts (modified, +2/-2)
  • src/infra/exec-approvals-policy.test.ts (modified, +20/-0)
  • src/infra/exec-approvals.ts (modified, +4/-4)
  • src/plugins/conversation-binding.ts (modified, +2/-1)

PR #66570: fix(config): add Windows absolute path support for OPENCLAW_STATE_DIR

Description (problem / solution / changelog)

Fixes #66523

When OPENCLAW_STATE_DIR is set to a Windows absolute path (e.g., D:\100_OpenClaw.openclaw), it was not being respected due to path resolution going through resolveUserPath/resolveHomeRelativePath which only handled tilde-prefixed paths correctly.

Root cause: Windows absolute paths like D:\ were passed through resolveHomeRelativePath which calls path.resolve() but the existing logic didn't properly handle drive letters in the override path.

Changes

  • Add Windows absolute path detection in resolveStateDir()
  • Direct path.resolve() for Windows drive letter paths (C:, D:, etc.)
  • Add test cases for Windows path handling
  • Preserve existing behavior for non-Windows and relative paths

Impact

OPENCLAW_STATE_DIR now works correctly on Windows with PM2, fixing deployment issues in enterprise Windows environments

Testing

✅ All existing tests pass ✅ New test validates Windows path handling

Changed files

  • extensions/telegram/src/bot-message-context.audio-transcript.test.ts (modified, +22/-0)
  • extensions/telegram/src/bot-message-context.body.ts (modified, +1/-1)
  • extensions/telegram/src/bot-message-context.session.ts (modified, +2/-2)
  • src/agents/bash-tools.exec-approval-followup.test.ts (modified, +19/-0)
  • src/agents/bash-tools.exec-approval-followup.ts (modified, +7/-3)
  • src/auto-reply/reply/reply-payloads-base.ts (modified, +1/-4)
  • src/auto-reply/reply/reply-plumbing.test.ts (modified, +14/-0)
  • src/commands/message.test.ts (modified, +47/-0)
  • src/commands/message.ts (modified, +21/-10)
  • src/config/paths.test.ts (modified, +32/-0)
  • src/config/paths.ts (modified, +4/-0)

Code Example

{
     "name": "openclaw-gw1",
     "env": {
       "OPENCLAW_STATE_DIR": "D:\\100_OpenClaw\\.openclaw"
     }
   }

---

function resolveStateDir(env = process.env, homedir = envHomedir(env)) {
    const override = env.OPENCLAW_STATE_DIR?.trim();
    if (override) return resolveUserPath(override, env, effectiveHomedir);
    // ... fallback logic
}

---
RAW_BUFFERClick to expand / collapse

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

OPENCLAW_STATE_DIR Environment Variable Ignored on Windows

Bug Description

The OPENCLAW_STATE_DIR environment variable is being ignored. Gateway processes continue to use the default C:\Users\<username>\.openclaw directory instead of the configured path.

Environment

  • OS: Windows Server 2019 Datacenter
  • Node.js: v22.22.2
  • OpenClaw: 2026.4.11
  • PM2: Managed via PM2 with fork mode
  • PM2_HOME: D:\100_OpenClaw.pm2

Steps to reproduce

Steps to Reproduce

  1. Configure PM2 ecosystem.json with:

    {
      "name": "openclaw-gw1",
      "env": {
        "OPENCLAW_STATE_DIR": "D:\\100_OpenClaw\\.openclaw"
      }
    }
  2. Start gateway via PM2: pm2 start ecosystem.json

  3. Delete or rename C:\Users\Administrator\.openclaw

  4. Restart gateway: pm2 restart all

  5. Observe: The C:\Users\Administrator\.openclaw directory is automatically recreated with new files

Expected behavior

Expected Behavior

Gateway shou## Actual Behavior

Gateway ignores OPENCLAW_STATE_DIR and uses the default user home directory path (C:\Users\Administrator\.openclaw).ld use the path specified in OPENCLAW_STATE_DIR environment variable (e.g., D:\100_OpenClaw\.openclaw).

Actual behavior

Evidence

  1. pm2 env 0 shows OPENCLAW_STATE_DIR=D:\100_OpenClaw\.openclaw is correctly set
  2. But C:\Users\Administrator\.openclaw\exec-approvals.json shows socket path as C:\Users\Administrator/.openclaw/exec-approvals.sock
  3. The D:\100_OpenClaw\.openclaw\exec-approvals.json file is never updated
  4. After renaming C:\Users\Administrator\.openclaw and restarting, the directory is automatically recreated

Analysis

The issue appears to be in how OpenClaw resolves the state directory. In dist/paths-HZHKO_Jn.js:

function resolveStateDir(env = process.env, homedir = envHomedir(env)) {
    const override = env.OPENCLAW_STATE_DIR?.trim();
    if (override) return resolveUserPath(override, env, effectiveHomedir);
    // ... fallback logic
}

The environment variable is correctly set, but the override is not being respected.

OpenClaw version

2026.4.11

Operating system

win2019 datacenter

Install method

npm

Model

minimax2.7 highspeed

Provider / routing chain

minimax

Additional provider/model setup details

Additional Notes

  • PM2 fork mode on Windows may have issues with environment variable inheritance
  • All 5 gateway instances exhibit the same behavior
  • Deleting the C:\ directory and restarting causes it to be recreated immediately

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

extent analysis

TL;DR

The OPENCLAW_STATE_DIR environment variable is being ignored on Windows, causing the gateway to use the default user home directory path instead of the configured path.

Guidance

  • Verify that the OPENCLAW_STATE_DIR environment variable is correctly set in the PM2 ecosystem.json file and that it is being inherited by the gateway process.
  • Check the OpenClaw code to ensure that the resolveStateDir function is correctly handling the OPENCLAW_STATE_DIR environment variable override.
  • Consider testing the gateway with a different environment variable or configuration to isolate the issue.
  • Investigate potential issues with PM2 fork mode on Windows and environment variable inheritance.

Example

No code snippet is provided as the issue is related to environment variable configuration and inheritance.

Notes

The issue may be related to how PM2 handles environment variables in fork mode on Windows. Further investigation is needed to determine the root cause.

Recommendation

Apply workaround: Try setting the OPENCLAW_STATE_DIR environment variable at the system level or using a different method to configure the state directory path, as the current configuration method may not be compatible with PM2 fork mode on Windows.

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