OpenClaw init-hooks for Openclaw

OpenClaw init-hooks turns container startup into a persistent, ordered automation pipeline that survives restarts, rebuilds, and gateway refreshes.

songhonglei
v1.0.0
Jul 13, 2026
0
203
0

Install & Download

1. ClawHub CLI

The fastest way to install a skill directly from the registry.

npx clawhub@latest install init-hooks

2. Manual Installation

Copy the skill folder to one of these locations

Global
~/.openclaw/skills/
Workspace
<project>/skills/

Priority: Workspace > Local > Bundled

3. Prompt Installation

Copy this prompt to OpenClaw to install it automatically.

Help me install init-hooks using Clawhub. If Clawhub is not installed, install it first (npm i -g clawhub).

Prefer to download?

Get the raw skill files in a ZIP archive.

What is OpenClaw init-hooks?

OpenClaw init-hooks is a startup-hook manager for OpenClaw containers and hosts. It lets you register actions that run automatically during boot, restart, or pod rebuild, while keeping the hook registry persisted in workspace/.init-hooks/ so Openclaw Skills can reuse the same automation state across lifecycles.

It supports three primary hook sources: inline shell commands, local shell/Python scripts, and CDN-hosted zip or tar.gz bundles that are downloaded and extracted on demand. The skill also includes a config sync companion for openclaw.json and gateway updates, making it a practical way to keep startup automation, runtime configuration, and execution logs aligned.

OpenClaw init-hooks Use Cases

  • Bootstrap environment variables, directories, and runtime settings on every OpenClaw startup.
  • Restore credentials, session state, or account setup after container or pod recreation.
  • Run local shell scripts or Python setup code as part of a repeatable boot sequence.
  • Pull remote initialization bundles from a CDN and execute them without manual unpacking.
  • Test a hook immediately with run and inspect execution output in last-run.log.
  • Manage startup order for multiple hooks with explicit order values.
  • Sync openclaw.json and gateway configuration after edits so runtime and persisted config stay aligned.
  • Build reliable Openclaw Skills bootstrap flows for containerized agent environments.

How OpenClaw init-hooks Works

  1. Install the skill with manage.py install, which creates ~/.openclaw/workspace/.init-hooks/, initializes hooks.json, generates dispatcher.sh, and injects the dispatcher into post-init.sh or the container startup script when possible.
  2. Add hooks using one of the supported source types: inline for shell commands, script for local shell files, python for local Python files, or URL-backed script packages for CDN downloads.
  3. Persist every change in hooks.json, the source of truth, and let the CLI regenerate dispatcher.sh automatically after add, edit, enable, disable, or delete operations.
  4. Execute hooks on startup or on demand with run or run <id>; enabled hooks run in ascending order, and a failure in one hook does not stop the rest.
  5. Log each run to ~/.openclaw/workspace/.init-hooks/last-run.log while also teeing output to stdout and printing a success/failure summary at the end.
  6. Sync config changes with sync_openclaw_config.py after editing openclaw.json or gateway settings, using --patch, --run, --run-inline, or --check to keep runtime and persisted paths consistent.

OpenClaw init-hooks Setup

  1. Install the hook runtime and verify the current status.
SCRIPT="$HOME/.openclaw/workspace/skills/init-hooks/scripts/manage.py"
python3 "$SCRIPT" install
python3 "$SCRIPT" status
  1. Add a startup hook. Inline commands are the fastest way to bootstrap a container.
python3 "$SCRIPT" add --name "Initialize log directory" --type inline --content "mkdir -p ~/logs && echo started >> ~/logs/boot.log"
  1. Add a local script or Python hook when the startup logic is more complex.
python3 "$SCRIPT" add --name "Restore credentials" --type script --path "$HOME/.openclaw/workspace/scripts/restore-credentials.sh"
python3 "$SCRIPT" add --name "Agent workspace config" --type python --path "$HOME/.openclaw/workspace/scripts/set-agents.py"
  1. Sync OpenClaw config changes after modifying openclaw.json or gateway settings.
SYNC="$HOME/.openclaw/workspace/skills/init-hooks/scripts/sync_openclaw_config.py"
python3 "$SYNC" --check
  1. Optional: configure extra persistence paths or a custom startup script for container environments.
export INIT_HOOKS_SYNC_PATHS="/app/clawconfig/openclaw.json:/app/k8s-config/clawconfig/openclaw.json"
export INIT_HOOKS_START_SH="/app/start.sh"

OpenClaw init-hooks Data Schema & Taxonomy

Storage layout

Path Purpose Notes
~/.openclaw/workspace/.init-hooks/hooks.json Hook registry Source of truth for all hooks and their enabled/order state.
~/.openclaw/workspace/.init-hooks/dispatcher.sh Generated dispatcher Auto-generated runner; manual edits are overwritten by the next operation.
~/.openclaw/workspace/.init-hooks/last-run.log Execution log Append-only log for each startup/run invocation, also tee'd to stdout.
~/.openclaw/workspace/.init-hooks/downloads/ CDN cache Stores extracted remote hook bundles as hook_<id>.*.
~/.openclaw/workspace/skills/init-hooks/scripts/manage.py CLI entry point Handles install, CRUD, status, and execution operations.
~/.openclaw/workspace/skills/init-hooks/scripts/sync_openclaw_config.py Config sync utility Reconciles openclaw.json and any extra persistence targets.

Hook metadata taxonomy

  • id: Stable numeric identifier used for show, edit, enable, disable, and delete.
  • name: Human-readable hook label.
  • type: Hook source type, such as inline, script, or python.
  • enabled: Whether the hook participates in startup execution.
  • order: Ascending execution order; default step is 10.
  • content: Inline shell content for inline hooks.
  • path: Local filesystem path for script and python hooks.
  • url: CDN archive URL for remotely hosted hook bundles.
  • entry: Entry file inside a downloaded archive when one is not auto-detected.

Data and generation rules

  • hooks.json is the truth and should be edited only through the CLI.
  • dispatcher.sh is generated from hooks.json and regenerated after every CRUD change.
  • Remote URL hooks are cached under downloads/; deleting the cache forces a fresh download on the next run.
  • openclaw.json is synchronized through sync_openclaw_config.py, with optional extra paths controlled by INIT_HOOKS_SYNC_PATHS.

OpenClaw init-hooks Advanced Features

  • Persistent startup automation that survives gateway restarts, container restarts, and pod rebuilds.
  • Automatic dispatcher regeneration after every add, edit, enable, disable, or delete action.
  • Support for inline shell commands, local shell scripts, local Python scripts, and CDN-hosted zip/tar.gz packages.
  • Ordered execution with --order so bootstrapping can be staged deterministically.
  • Broad failure isolation: one failing hook does not stop the rest of the startup sequence.
  • One-command test execution with run and run <id>, plus append-only logging in last-run.log.
  • Config synchronization workflows for openclaw.json and gateway changes via sync_openclaw_config.py.
  • Safe, idempotent installation that injects into post-init.sh or the container startup script when available.
  • Clean Openclaw Skills bootstrap for repeatable developer, agent, and container environments.

SKILL.md


Loading

Related Openclaw Skills

METADATA

Github Stars: 0
forks: 0

Featured*