Skip to content

fix: support OPENCLAW_HOME for non-standard OpenClaw paths#275

Open
luoyanglang wants to merge 2 commits intocft0808:mainfrom
luoyanglang:wolf/fix-custom-openclaw-home
Open

fix: support OPENCLAW_HOME for non-standard OpenClaw paths#275
luoyanglang wants to merge 2 commits intocft0808:mainfrom
luoyanglang:wolf/fix-custom-openclaw-home

Conversation

@luoyanglang
Copy link
Copy Markdown

Summary

Issue: #271 - install scripts hardcode ~/.openclaw and fail in non-standard OpenClaw environments
Type: Bug Fix
Severity: Medium

This PR adds OPENCLAW_HOME support across the install flow and runtime scripts that read OpenClaw state. It preserves the existing default behavior when the environment variable is not set, while allowing NAS and other non-standard deployments to point Edict at a custom OpenClaw home directory.

Closes #271.


Root Cause

Several install and runtime entry points built OpenClaw paths directly from ~/.openclaw instead of using a shared resolution rule.

  • install.sh:8, install.sh:134, install.sh:159
  • install.ps1:9, install.ps1:122, install.ps1:148
  • scripts/apply_model_changes.py:12
  • scripts/skill_manager.py:31, scripts/skill_manager.py:232
  • scripts/sync_agent_config.py:16, scripts/sync_agent_config.py:142, scripts/sync_agent_config.py:160, scripts/sync_agent_config.py:270, scripts/sync_agent_config.py:305, scripts/sync_agent_config.py:318, scripts/sync_agent_config.py:327
  • scripts/sync_officials_stats.py:12
  • scripts/sync_from_openclaw_runtime.py:18

That meant the path flow was:

$HOME / Path.home() -> hardcoded .openclaw -> openclaw.json / workspace-* / agents/*

When OpenClaw was installed under a custom home, the install scripts failed early and some runtime scripts still pointed at the wrong directory even if the user manually worked around installation.

# Before
OC_HOME="$HOME/.openclaw"

# After
OC_HOME="${OPENCLAW_HOME:-$HOME/.openclaw}"
# Before
OPENCLAW_CFG = pathlib.Path.home() / '.openclaw' / 'openclaw.json'

# After
OPENCLAW_HOME = get_openclaw_home()
OPENCLAW_CFG = OPENCLAW_HOME / 'openclaw.json'

Fix Description

Changed files:

  • install.sh:8 - use OPENCLAW_HOME with fallback to ~/.openclaw
  • install.sh:134 - update the embedded Python registration snippet to resolve config/workspace paths from the same home directory
  • install.ps1:9 - add the same environment-variable fallback for Windows installs
  • install.ps1:122 - update the embedded Python registration snippet for Windows
  • scripts/utils.py:18 - add get_openclaw_home() as the shared path resolver
  • scripts/apply_model_changes.py:12 - read openclaw.json from the resolved OpenClaw home
  • scripts/skill_manager.py:31 - use the shared resolver for workspace and skills-hub-url
  • scripts/sync_agent_config.py:16 - use the shared resolver for config, workspaces, deployed SOUL files, and agent session directories
  • scripts/sync_officials_stats.py:12 - use the shared resolver for agent stats and config reads
  • scripts/sync_from_openclaw_runtime.py:18 - use the shared resolver for session scanning

Rationale:

  • The change keeps the existing default path untouched for current users.
  • Python path resolution is centralized in one helper so future scripts do not reintroduce the same hardcoded ~/.openclaw assumption.
  • I also updated two runtime scripts that were not part of the original install failure report but still hardcoded the same directory, to avoid partial fixes after installation succeeds.

Test Results

Test Description Status
python -m py_compile Compiled all modified Python scripts (utils.py, apply_model_changes.py, skill_manager.py, sync_agent_config.py, sync_officials_stats.py, sync_from_openclaw_runtime.py) ✅ PASS
Default path fallback Imported get_openclaw_home() with no env var set and confirmed fallback to C:\Users\Administrator\.openclaw ✅ PASS
Custom path resolution Set OPENCLAW_HOME=D:\tmp\custom-openclaw and confirmed apply_model_changes, sync_agent_config, sync_officials_stats, and sync_from_openclaw_runtime resolve to that directory ✅ PASS
install.ps1 syntax Parsed install.ps1 through the PowerShell parser after the path changes ✅ PASS

Manual notes:

  1. Environment: Windows / PowerShell / Python available in local dev workspace
  2. I could not run the full install.sh flow end-to-end here because bash is not installed in this environment and OpenClaw CLI initialization is not set up
  3. The shell-side fallback and embedded Python path handling in install.sh were reviewed directly in diff and kept equivalent to the PowerShell implementation

Disprove Analysis

Is this already fixed elsewhere?

I checked the current upstream/main before branching and did not find existing OPENCLAW_HOME handling in these install/runtime paths.

Impact range

The behavioral change is limited to OpenClaw home-directory resolution. If OPENCLAW_HOME is unset, all touched code paths still resolve to the original ~/.openclaw location.

Edge cases

  • OPENCLAW_HOME now works for both install scripts and Python runtime scripts, so installation and follow-up maintenance tasks stay aligned.
  • The shared Python helper uses expanduser(), which also handles values such as ~/custom-openclaw.
  • Existing explicit workspace values already stored in openclaw.json are still respected because sync_agent_config.py only uses the resolved home for fallback paths.

Known limitations

  • This PR does not migrate existing OpenClaw data between directories; it only resolves paths correctly.
  • install.sh was not executed end-to-end in this Windows workspace because bash was unavailable.

Checklist

  • 代码遵循项目现有风格
  • 相关 issue 编号已在 PR 描述中引用 (#271)
  • 有测试覆盖(静态检查 + 手动路径验证)
  • 无硬编码路径、密钥、调试输出新增

Found during routine bug-fix work. Happy to adjust the scope if you prefer limiting this PR strictly to the originally reported files.

@luoyanglang luoyanglang marked this pull request as ready for review April 8, 2026 20:17
@luoyanglang luoyanglang requested a review from cft0808 as a code owner April 8, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

建议支持 自定义openclaw.json目录

1 participant