Skip to content

Run on a server

Use this page to run the daemon on a machine that stays on and log in to WeChat there. Pick one way. Each one owns the daemon process, so don’t combine them.

WayChoose it when
Docker ComposeYou want the daemon and its data kept apart from the rest of the host. Recommended.
wx daemonYou want a quick background run on any OS.
systemd user serviceYou run wx directly on Linux and want it to restart on failure.

Docker Compose

The image is ghcr.io/thisnick/agent-wechat-native (linux/amd64 and linux/arm64). It runs as user 10001 with a read-only filesystem and keeps its data in Docker volumes. Start from the example compose.yaml and server.toml.

  1. Put both files in a folder. In compose.yaml, set image: to ghcr.io/thisnick/agent-wechat-native:latest and delete the build: section.

  2. Create an API token: one copy for your CLI, one owned by the container user.

    Terminal window
    umask 077; mkdir -p ~/.config/agent-wechat secrets
    head -c 32 /dev/urandom | base64 > ~/.config/agent-wechat/box-token
    sudo install -m 600 -o 10001 -g 10001 ~/.config/agent-wechat/box-token secrets/api-token
  3. Start the container.

    Terminal window
    docker compose up -d
  4. Create an account and log in inside the container. The token is mounted at /run/secrets/wechat-api-token. Scan the QR code as described in Connect your account.

    Terminal window
    docker compose exec agent-wechat-native wx --token-file /run/secrets/wechat-api-token accounts create --alias me
    docker compose exec agent-wechat-native wx --token-file /run/secrets/wechat-api-token auth login
  5. To use the daemon from the host, save it as a server. The daemon listens on 127.0.0.1:6174 of the host.

    Terminal window
    wx config servers add box --url http://127.0.0.1:6174 \
    --token-file ~/.config/agent-wechat/box-token
    wx --server-name box accounts get

To use existing WeChat for Linux data, add its folder (the one that contains xwechat_files and .xwechat) under volumes: as /home/you:/profiles/wechat, then log in with --official=/profiles/wechat. The container user needs write access to that folder, and the WeChat app must be stopped.

On macOS and Windows, Docker Desktop runs the same image. The example uses host networking, so turn it on under Settings › Resources › Network.

wx daemon

wx daemon starts wx serve in the background for the current user. It works on any OS but does not restart after a failure or reboot.

Terminal window
wx daemon start
wx daemon status
wx daemon restart
wx daemon logs --follow
wx daemon stop

Then follow Connect your account to log in.

systemd

On Linux, a systemd user service restarts the daemon on failure and starts it with your user session. It needs wx installed (Install). Stop any running daemon first (wx daemon stop, or quit the desktop app).

  1. Preview the unit file without installing it.

    Terminal window
    wx daemon install --dry-run
  2. Install and start the service. It asks before writing the unit or calling systemctl; add --yes to skip the question.

    Terminal window
    wx daemon install

    This writes ~/.config/systemd/user/agent-wechat-native.service from the shipped user unit, with the path to wx, your data folder and server config, and write access to the folders of any --official profiles you have registered.

  3. On a headless server, let the service run without a login session.

    Terminal window
    loginctl enable-linger
  4. Log in as in Connect your account. Manage the service later with:

    Terminal window
    wx daemon status
    wx daemon restart
    wx daemon uninstall # removes the service unit; keeps your data

If you add an --official profile after installing, run wx daemon uninstall and wx daemon install again so the unit can write to WeChat’s folders.

Next steps