Skip to content

Rehydrating with sync

hlock sync turns a lock back into a working setup: on a new laptop, in a fresh VM, in an isolated directory, or in a Docker image. It works on any lock, and gets the most out of one written by hlock pin.

By default sync writes into an isolated config root in .hlock/env/, so your own config (~/.claude, ~/.pi, …) is never changed unless you pass --in-place.

Installing everything automatically across package managers, operating systems, GUI apps and model stores isn't realistic, so sync builds a plan in which every step is one of:

Status Meaning
✓ satisfied Already true here: the version or digest matches
● automatic hlock does it: restore a config file, copy a skill, install a plugin through the harness's own CLI (claude plugin install, pi install)
○ manual It needs you, and hlock prints the exact command or link and why

On a new machine

Clone the repo that holds harness.lock and .hlock/, then:

$ hlock sync --yes
Sync plan for Claude Code 2.1.0 → .hlock/env/claude-code/config
✓  harness       Claude Code 2.1.0
✓  mcp           `npx` for MCP servers: github
●  config        Write .hlock/env/claude-code/config/settings.json
●  config        Write .hlock/env/claude-code/config/.claude.json /mcpServers
●  skill         Copy skill review-pr → .hlock/env/claude-code/config/skills/review-pr
●  skill         Copy skill write-tests → .hlock/env/claude-code/config/skills/write-tests
●  instructions  Write .hlock/env/claude-code/config/CLAUDE.md
○  secret        HLOCK_SECRET_GITHUB_GITHUB_TOKEN (mcp github GITHUB_TOKEN)  not set
✓ Write .hlock/env/claude-code/config/settings.json
✓ Write .hlock/env/claude-code/config/.claude.json /mcpServers  placeholders for missing secrets
✓ Copy skill review-pr → .hlock/env/claude-code/config/skills/review-pr
✓ Copy skill write-tests → .hlock/env/claude-code/config/skills/write-tests
✓ Write .hlock/env/claude-code/config/CLAUDE.md

1 step needs you:
  1. Store 1 secret in your keychain, then re-run hlock sync (values stay out of the lock)
     hlock secret set GITHUB_GITHUB_TOKEN  # mcp github GITHUB_TOKEN
     or export each variable, or reference it in ~/.config/hlock/secrets.toml
next → hlock sync --skill (let your agent do it)

Without --yes, sync shows the plan and asks before it runs the automatic steps. Set the secret (here from the environment; see Secrets for the keychain and password managers) and run it again. Re-running is always safe: satisfied steps are skipped, and sync exits 3 while manual steps remain and 0 once everything matches.

$ export HLOCK_SECRET_GITHUB_GITHUB_TOKEN=ghp_…
$ hlock sync --yes
…
✓ in sync at .hlock/env/claude-code/config  your own config wasn't touched
use it: CLAUDE_CONFIG_DIR=.hlock/env/claude-code/config claude
to restore into your own config instead: hlock sync --in-place

Start the harness with that command, or with hlock launch, which uses the same directory. hlock check --prefix .hlock/env confirms the setup there matches the pin:

$ hlock check --prefix .hlock/env
✓ the claude-code setup in .hlock/env matches harness.lock

Like a .venv, the isolated root isn't for version control: it's restored from the lock, and it holds filled-in secrets and the harness's own state. hlock writes a .gitignore of * into each harness's directory there (.hlock/env/claude-code/.gitignore), so git add skips it. Commit harness.lock and .hlock/vendor/ instead.

To start from someone else's setup instead, hlock sync github:OWNER/REPO pulls their lock first, and hlock sync NAME syncs one you've already pulled; see Pulling someone else's lock.

What hlock does, and what it leaves to you

By default sync only does things that are local and reversible: it writes config files into the isolated root (keeping the old one as <file>.hlock-bak), copies skills and instruction files, fetches declared dependencies at their locked commits (checking each digest), and runs the harness's own plugin commands against that root. It won't place a file with characters that hide text, and it won't install an MCP server, plugin, hook, other setting that runs a command, or skill script you haven't approved on this machine, in its harness or in the ones [target] also names: --yes doesn't approve them; hlock trust or --trust does. With --plan or --json, --trust shows the plan as if they were approved, recording nothing. A --docker image leaves out what isn't trusted too. These steps need you to opt in:

Flag Lets hlock… Otherwise the step is manual, with
--in-place write into your own config root (~/.claude, …) instead of .hlock/env/ (no manual step: the setup goes into .hlock/env/)
--apps write a desktop app's own config (Claude Desktop, VS Code) the step that writes it, with "hlock sync --apps writes it"
--install run package managers: npm install -g, brew install, uv tool install, install scripts the exact command, e.g. npm install -g @earendil-works/pi-coding-agent@1.0.0
--install-cross-os install a cross-os step with this machine's native installer (needs --install too) the native command, with "Cross-os installs run only with --install --install-cross-os"
--pull download model weights through an installed runtime (ollama pull, lms get, hf download) the pull command and the download size

System and CLI tools: the declared [environment]

harness.toml's [environment] declares the system packages and CLI tools the agent relies on — the local tools and their dependencies that are "a Dockerfile kind of thing". Unlike most of the manifest it isn't found by pin; you declare it and hlock installs it:

harness.toml
[environment]
apt = ["ffmpeg"]                         # system packages (guided manual: needs root)
pip = ["yt-dlp"]                       # user-level installers run automatically
npm = ["@modelcontextprotocol/server-fetch"]
[[environment.binaries]]                # a pinned binary: url + sha256 + path
url = "https://github.com/…/tool"
sha256 = "0123…"
path = "/usr/local/bin/tool"

hlock sync turns each into an install step: pip, npm, brew, cargo and go packages install automatically once you pass --install (like any package manager step); apt packages (root) and pinned binary downloads — which hlock never writes to an absolute system path itself — are verified steps: a binary reports satisfied only when the file at path hashes to its pinned sha256, and the step gives you the exact curl+install command. Anything sync can't do deterministically (an installer that isn't available on this OS, a one-off installer script) stays manual and points at the agentic fallback: hlock meta run install.

A lock records how a harness or runtime was installed (e.g. brew-cask:claude-code on macOS). When you sync on another OS and that recorded method can't run here (Homebrew casks are macOS; winget/scoop/choco are Windows), sync falls back to the profile's installer that works on this machine — npm, pip, uv tool or an install script — and shows that command. Because it runs something other than what the lock recorded, it's gated behind an extra approval: it needs --install --install-cross-os (you could also edit the lock, or install it by hand). On the same OS as the lock, nothing changes.

Some steps are always manual: apps without a CLI installer (the LM Studio app), self-hosted inference servers on another machine (location = "network" in the lock: hlock lists the models the server should serve and a curl to check it), and secrets.

Secrets are filled from the HLOCK_SECRET_* environment variables, your secrets file, or your OS keychain, in that order (see Secrets). If none has a value but the target config already has a real value in that place (say, you're syncing on the machine you pinned), sync keeps it and never replaces a real secret with a placeholder. Files that receive secret values, and their backups, are readable only by you (0600).

Models a provider lists but no locked role uses are optional; --all-models includes them. --exact also moves aside skills in the target skill directory that aren't in the lock.

What a lock can't make hlock do

A lock may be someone else's (hlock pull), and launch runs the automatic steps without asking, so hlock checks what a lock asks for. A step that fails a check is manual, with the reason ending in "refusing to write it automatically"; hlock never does it for you:

  • Instruction files go only where the harness reads them (CLAUDE.md, {root}/CLAUDE.md, … as its profile lists). A lock entry named ~/.zshrc or {root}/settings.json is refused.
  • Skills go only under the harness's skill directories, and a skill's name must be a plain directory name (no / or ..).
  • Vendored copies must be relative paths inside the lock's directory.
  • Values that reach a command (a version, package, model id, revision or git ref) must be plain: letters, digits and ._:/@+-, not starting with -. They're quoted as well. A version like 1; curl x | sh is refused.
  • Skills from git come only from https://, http://, ssh://, git:// or user@host:path URLs, at a hash or a plain ref; hlock checks a full hash after checkout.
  • A decider's model is pulled only through a local runtime hlock knows (ollama, ollaya), with that runtime's own pull command.
  • Decider hooks are written only for the uses and events hlock decide hook answers; see Deciders.
  • Plugins, marketplaces and packages from a pulled lock (one with a [pulled] table) install only with --install, because a plugin runs code. From your own lock they install automatically, as before.

Installers run with the same environment as the rest of sync, and stop after four hours. Config files are written whole or not at all (through a temporary file and a rename).

Let your agent do the manual steps

$ hlock sync --skill
…
✓ wrote .agents/skills/hlock-rehydrate/SKILL.md

This writes an Agent Skill generated from the plan: the remaining steps in order, the command for each, a check for each, and rules (ask before installing system software or large downloads, never print secrets, finish with hlock sync and hlock check, with the same --prefix or --in-place as the plan). Open any agent in the directory, even a vanilla one, and ask it to rehydrate the harness with the hlock-rehydrate skill. Use --skill-dir to write it somewhere else, such as .claude/skills/hlock-rehydrate.

To have hlock run the agent and check its work, use the meta harness instead: hlock meta run install.

The isolated directory

The isolated root works like a virtual environment for the harness. It lives at .hlock/env/<harness>/ (for a lock named harness.<name>.lock, .hlock/env/harness.<name>/<harness>/). --prefix DIR puts it under DIR instead:

$ hlock sync --prefix .hlock/env2 --yes
…
✓ in sync at .hlock/env2/claude-code/config  your own config wasn't touched
use it: CLAUDE_CONFIG_DIR=.hlock/env2/claude-code/config claude

hlock points the harness at the directory through its config-root variable (CLAUDE_CONFIG_DIR, CODEX_HOME, PI_CODING_AGENT_DIR, HERMES_HOME, CURSOR_CONFIG_DIR, XDG_CONFIG_HOME), and plugin installs run against it too. Files that normally live outside the config root move inside it (Claude Code reads .claude.json from CLAUDE_CONFIG_DIR when it's set). Skills that lived outside the config root (for example ~/.agents/skills) are placed in the harness's own skill directory inside the prefix. If a secret isn't set in the environment, sync takes the value from your own config when it has one, without changing your config. Sign-in state isn't copied, so the first session in a new prefix may ask you to log in.

Into your own config

To restore the setup into your real config root, so a plain claude (or pi, …) picks it up, opt in with --in-place:

$ hlock sync --in-place --yes
Sync plan for Claude Code 2.1.0 → your config ~/.claude
✓  harness       Claude Code 2.1.0
✓  mcp           `npx` for MCP servers: github
✓  secret        HLOCK_SECRET_GITHUB_GITHUB_TOKEN (mcp github GITHUB_TOKEN)
●  config        Write ~/.claude/settings.json
●  config        Write ~/.claude.json /mcpServers
●  skill         Copy skill review-pr → ~/.claude/skills/review-pr
●  skill         Copy skill write-tests → ~/.claude/skills/write-tests
●  instructions  Write ~/.claude/CLAUDE.md
✓ Write ~/.claude/settings.json
✓ Write ~/.claude.json /mcpServers
✓ Copy skill review-pr → ~/.claude/skills/review-pr
✓ Copy skill write-tests → ~/.claude/skills/write-tests
✓ Write ~/.claude/CLAUDE.md
✓ in sync with harness.lock

$ hlock check
✓ your claude-code setup matches harness.lock

Each file it replaces is kept as <file>.hlock-bak. Only the parts the lock restores are written: for ~/.claude.json, only /mcpServers, so your sign-in and other state stay. --in-place doesn't combine with --prefix or --docker.

Desktop apps

A desktop app (Claude Desktop, VS Code) reads only its own config, so an isolated root is no use to it. For an app's lock, sync plans against the app's real config, and writes it only with --apps (--in-place implies it):

Without --apps With --apps
The lock's harness is an app Steps that write the app's config are manual (○, "hlock sync --apps writes it"); sync exits 3 Written, then "quit and reopen Claude Desktop" when the app needs a restart
An app in [target] also Its steps are optional: listed, but sync still exits 0 Written
Files in the project (.vscode/mcp.json, .github/skills/) Written, as for any harness Written

Interactively, sync asks before it leaves them out. While Claude Desktop runs, its config isn't written whatever the flags, because the app can overwrite the file: quit it, then run sync again. --prefix DIR writes a copy for you to inspect, which the app doesn't read, and --docker refuses an app. --apps doesn't combine with --prefix or --docker.

A missing app is installed by --install through Homebrew (brew install --cask claude) on macOS. Otherwise it's a manual step with the download link, which hlock meta run install can hand to an agent. An installed app at a different version than the lock pins is fine: apps update themselves, and installers only offer the current version.

Into a Docker image

$ hlock sync --docker
…
✓ wrote .hlock/docker/pi/Dockerfile
next →
  docker build -t hlock-pi:8f489e60629b .hlock/docker/pi
  docker run -it --rm -e HLOCK_SECRET_… -v "$PWD:/workspace" hlock-pi:8f489e60629b
  or run the lock in it as a sandbox: add to harness.toml, then re-pin
    [sandbox]
    runner = "docker"
    image = "hlock-pi:8f489e60629b"  # push it, and pin @sha256:, to share it
    (runner = "openshell" runs it on an OpenShell gateway instead)

--docker writes a build context to .hlock/docker/<harness>/. The restored config, skills and instruction files go into home/ and are copied to the image's home. The Dockerfile installs the harness with a method that works on Linux (Homebrew casks fall back to npm or the install script) and runs the plugin installs. Secrets are never baked into the image: the entrypoint fills ${HLOCK_SECRET_*} placeholders when the container starts, from -e variables or from secret files mounted at /run/secrets (Docker and Compose secrets; see Secrets). Model weights stay on the host. A local runtime is reached at http://host.docker.internal:<port>, which the Dockerfile notes. --build also runs docker build. The image is tagged with the lock's hash and labeled with the harness and its version, so it can be the lock's sandbox, on Docker or OpenShell (its /workspace is writable by uid 1000, which OpenShell runs as). --base IMAGE builds on your own Debian-based image instead of node:22-bookworm.

Reference

hlock sync [LOCK] [--plan | --json | --skill] [--yes] [--install] [--install-cross-os] [--pull] [--all-models]
           [--prefix DIR | --in-place | --docker [--build] [--base IMAGE]] [--apps] [--exact] [--verbose]

See the CLI reference for every option.