| name | safe-update |
| description | Update OpenClaw from source code. Supports custom project path and branch. Includes pulling latest branch, rebasing, building and installing, restarting service. Triggered when user asks to update OpenClaw, sync source, rebase branch, or rebuild. |
Safe Update
Update OpenClaw from source to the latest version while preserving local changes.
⚠️ Important Warnings
- This script performs git rebase and git push --force - may lose local changes if not properly committed
- Uses npm i -g . for global installation - may require sudo
- Uses systemctl --user restart - will restart the OpenClaw service
- Backup your config before running! (see below)
Requirements
Required binaries (must be installed):
git
npm / node
systemctl (for restarting gateway)
Configuration
Environment Variables (optional)
export OPENCLAW_PROJECT_DIR="/path/to/openclaw"
export OPENCLAW_BRANCH="your-feature-branch"
export DRY_RUN="true"
Or Pass as Arguments
./update.sh --dir /path/to/openclaw --branch your-branch
Workflow
Step 1: Analyze Current State (Must Run First)
Before executing any update, check:
- Whether the current branch has uncommitted changes
- Whether the current branch has local modifications
- Whether upstream has new commits
- Recommend the most appropriate update strategy based on the situation
Recommended Strategy:
| Scenario | Recommended Method | Rationale |
|---|
| Uncommitted local changes | Commit/stash first, then merge | Safe, no lost changes |
| Only clean local commits | merge or rebase | merge is safer, rebase keeps history clean |
| Preparing a PR | rebase recommended | Keeps history tidy |
| Routine dev update | merge recommended | Simple, less error-prone |
Step 2: Ask User for Confirmation
After presenting the recommended options, you must wait for user confirmation before executing.
Step 3: Execute Update
cd "${OPENCLAW_PROJECT_DIR:-$HOME/projects/openclaw}"
echo "=== Backing up config files ==="
mkdir -p ~/.openclaw/backups
BACKUP_SUFFIX=$(date +%Y%m%d-%H%M%S)
cp ~/.openclaw/openclaw.json ~/.openclaw/backups/openclaw.json.bak.$BACKUP_SUFFIX
echo "✅ Backed up: openclaw.json"
if [ -f ~/.openclaw/agents/main/agent/auth-profiles.json ]; then
cp ~/.openclaw/agents/main/agent/auth-profiles.json \
~/.openclaw/backups/auth-profiles.json.bak.$BACKUP_SUFFIX
echo "✅ Backed up: auth-profiles.json"
fi
echo "💡 Backups saved to: ~/.openclaw/backups/"
echo ""
git remote add upstream https://github.com/openclaw/openclaw.git 2>/dev/null || true
git fetch upstream
git checkout $BRANCH
echo "=== Full Changelog ==="
CURRENT_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v$(node -e 'console.log(require().version)')")
npm run build
npm i -g .
openclaw daemon install --force
NEW_VERSION=$(openclaw --version)
Quick Script
Run scripts/update.sh to automatically complete all steps above.
Command Line Options
./update.sh [OPTIONS]
Options:
--dir PATH OpenClaw project directory (default: $HOME/projects/openclaw)
--branch NAME Git branch to update (default: main)
--mode MODE Update mode: merge or rebase (if not specified, will analyze and recommend)
--dry-run Show what would be done without executing
--help Show this help message
Examples
./update.sh
./update.sh --branch feat/my-branch
./update.sh --mode merge
./update.sh --mode rebase
./update.sh --dry-run
./update.sh --dir /opt/openclaw --branch main
Notes
- Rebase may cause conflicts - if conflicts occur, resolve manually and continue
- Force push - after rebase, if pushing to fork, use
git push --force
- Service reinstall - will update version in systemd unit file
- User confirms restart - Gateway will not restart until you confirm
- Backup first - always backup before updating!
Troubleshooting
Git Conflicts During Rebase
git add .
git rebase --continue
Build Fails
rm -rf node_modules dist
npm install
npm run build
Gateway Won't Start
systemctl --user status openclaw-gateway
journalctl --user -u openclaw-gateway -n 50