Skip to content

Latest commit

 

History

History
165 lines (110 loc) · 22.6 KB

INSTALL.md

File metadata and controls

165 lines (110 loc) · 22.6 KB

Installing hex

These steps are written for a coding agent (Claude Code, Codex, …) setting hex up for its user. Follow them in order. Steps marked (you) need the person: tell them exactly what to do, then wait for them to confirm.

hex runs wherever Claude Code does, on a machine that stays on: a home server, a Mac that doesn't sleep, a cloud VM. Run everything below on that machine, as the user hex will run as: a normal user, not root, since Claude Code refuses bypass permissions mode as root outside a sandbox.

1. Check what's there

git, curl, jq, unzip, python3 (for memory) and flock (part of Linux; brew install flock on macOS) must be on the PATH; install what's missing with the system package manager, after asking. Step 5 installs bun and Claude Code if they aren't there.

The person signs in to Claude Code by running claude once (you), now or after step 5.

2. Make their hex

A person's hex is a folder of their own, ~/hex unless they want another place. hex itself lives inside it, in .hex/: a clone of the repo they pointed you to, this one or their fork, and updates pull from there. If the folder already exists, stop and ask.

git clone https://github.com/AVGVSTVS96/hex ~/hex/.hex   # or their fork
~/hex/.hex/bin/hex init

init writes their AGENTS.md, SOUL.md, PROACTIVE.md, schedules.json, .env and .claude/settings.json, sets skipDangerousModePermissionPrompt in their Claude Code user settings, since hex's background sessions run in bypass permissions mode (that setting applies to all their Claude Code sessions, so tell them), sets up their memory in memory/ with OptMem, and makes the folder a private git repo. Updates pull into .hex/, and bin/migrate adds new default files to their folder and updates the ones they never edited.

3. Make the Telegram bot and group (you)

Ask them: "What's the most convenient place to reach you?" Its main chat becomes home, where reminders and anything hex brings up on its own land; they can still talk to hex from any app it's in. Home is Telegram's General for now, so if they name another app (texts, iMessage, Slack), tell them hex reaches them on Telegram until it can live there.

  1. In Telegram, open @BotFather, send /newbot, and copy the token it gives you.
  2. Create a new group, open its settings, and turn on Topics.
  3. Add the bot to the group and make it an admin with Manage Topics. hex opens a topic for each piece of work it starts.
  4. Send any message in the group's General topic.

4. Connect hex to the group

Write the token to TELEGRAM_BOT_TOKEN in ~/hex/.env.

Find the group and the person with the bot's recent updates. hex isn't running yet, so nothing else is reading them:

. ~/hex/.env
curl -s "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/getUpdates" \
  | jq '.result[].message | select(.chat.is_forum) | { chat: .chat.id, title: .chat.title, from: .from.id, name: .from.first_name }'
  • Set HEX_MAIN_THREAD in .env to the group's chat id. It starts with -100.
  • Only the person may talk to hex. Write their from id to ~/hex/state/telegram/access.json as { "allowFrom": ["<from id>"] }.

If nothing shows up, the bot isn't an admin yet or the message was sent before it joined. Ask them to send another one.

5. Set up the machine and start hex

~/hex/.hex/bin/hex restore

restore sets this machine up from two lists: hex's own (.hex/services.json) and theirs (~/hex/services.json, if they have one; see Moving hex). It installs what's missing (bun, claude), installs hex's channels turned off (hex turns one on in its own sessions), lets Claude Code run them through its managed settings, trusts ~/hex for Claude Code the way its first prompt there would, and starts hex. Then it runs hex doctor.

Ask before running it: the managed settings file (/etc/claude-code/managed-settings.json on Linux, /Library/Application Support/ClaudeCode/managed-settings.json on macOS) is merged with what's there and written with sudo, and on Linux loginctl enable-linger may need sudo too, so their services keep running when they log out, as does turning on systemd-oomd.

With systemd, hex runs as the units it ships (hex.service, the hub, in systemd's session.slice, which session.slice.d/hex.conf puts ahead of everything else on the CPU, and on the disk where its scheduler weighs groups (bfq); hex-sessions.slice, which keeps its sessions in a memory slice apart from the hub; and hex-jobs.slice, which does the same for its jobs and gives way to the sessions), linked into ~/.config/systemd/user and enabled, and turns on systemd-oomd (with sudo), which stops a job that stalls the machine on memory. Without it, restore starts hex with hex start; have the machine run ~/hex/.hex/bin/hex run (it stays in the foreground) as it boots: a launchd agent with KeepAlive on macOS, a Sprite service on a Fly.io Sprite, or a crontab line @reboot ~/hex/.hex/bin/hex start.

doctor prints a fix line for each thing that isn't right; run it again until it says hex looks healthy. ~/hex/.hex/bin/hex status should show the hub running and a session named hex. The hub keeps General running and starts a session for every other thread when it's needed.

6. Make it theirs

  • Ask their name, what they do, and anything they want hex to know from day one, and save each fact as a memory: MEMORY_DIR=~/hex/memory ~/hex/.hex/vendor/memo note "<fact>". Then run MEMORY_DIR=~/hex/memory ~/hex/.hex/bin/wake, so the next session starts with them.

  • Ask what time zone they're in. If date here shows another one, set env.TZ in ~/hex/.claude/settings.json to theirs (like America/New_York), so schedules fire on their clock.

  • Ask what they want hex to bring up on its own, what never, and their hours. Write each answer in their words under "Tell me about", "Never tell me about", "When" or "How" in ~/hex/PROACTIVE.md, which hex reads before it messages them unprompted. The hourly check runs from 8:45 to 22:45; set the heartbeat's cron in ~/hex/schedules.json to their hours.

  • Models (optional): these go in the env of ~/hex/.claude/settings.json. HEX_ORCHESTRATOR_MODEL is the model every thread's session runs (unset, it runs the folder's model, as the agents it starts always do), HEX_MAIN_MODEL the same for General alone, HEX_ORCHESTRATOR_EFFORT the effort every thread's session runs (unset, the folder's effortLevel), and HEX_VOICE_MODEL the fast model a voice call runs (sonnet if unset).

  • Voice notes (optional): .hex/bin/transcribe works with any OpenAI-compatible /v1/audio/transcriptions endpoint: a hosted API, or a local speech-to-text server. Search the web for the current best option, suggest one, and if they agree, set TRANSCRIBE_URL (the full endpoint URL), TRANSCRIBE_MODEL and, if needed, TRANSCRIBE_API_KEY in .env.

  • Connectors (optional): every connector on their Claude account works in every hex session, nothing to set up on this machine. They add them at claude.ai → Settings → Connectors (you). Mail lets the hourly check read their inbox. Some that suit hex: Executor puts many accounts behind one connector (https://executor.sh/mcp), and AgentMail gives hex an inbox of its own (https://mcp.agentmail.to/mcp).

  • A computer of its own (optional): a Fly.io Sprite with a desktop and Chrome, for anything that needs a real browser. Install the sprite CLI (curl -fsSL https://sprites.dev/install.sh | sh) and ask them to run sprite login (you). Then:

    sprite create hex-computer
    sprite file push -s hex-computer ~/hex/.hex/computer/setup /home/sprite/setup
    sprite exec -s hex-computer -- sh -c '~/setup > ~/setup.log 2>&1; tail -n 8 ~/setup.log'

    It ends with cua-driver doctor, which should be all [ok ]. If the push fails right after create, run it again. Add - Agent computer: Sprite hex-computer to ~/hex/AGENTS.md, and set "HEX_COMPUTER": "hex-computer" in the env of ~/hex/.claude/settings.json so hex can sign in there with its vault. They can watch its screen from a machine with the sprite CLI: sprite proxy -s hex-computer 6080, then http://localhost:6080/vnc.html.

  • The vault is enclave and works with nothing to set up: hex sends a link, they fill it in, and it's saved encrypted in ~/.enclave/. The key that opens it is ~/.enclave/key.json; tell them to back it up somewhere safe. The link goes through a relay enclave hosts, which only ever sees encrypted data; enclave's README shows how to run their own. Then use the vault skill to bring in the password manager they already use, and set up passkeys on the computer if they have one.

  • Discord (optional): a second app for deeper work. Tag the bot in any channel and it opens a thread with its own session. Ask them to create an application at https://discord.com/developers/applications, turn on Message Content Intent under Bot, copy the bot token, and invite the bot to their server with the bot scope and the Send Messages, Send Messages in Threads, Create Public Threads, Manage Threads, Read Message History, Attach Files and Add Reactions permissions (you). Then set DISCORD_BOT_TOKEN in .env, write their Discord user id to ~/hex/state/discord/access.json as { "allowFrom": ["<user id>"] }, then run ~/hex/.hex/bin/hex restart.

  • Buzz (optional): Buzz is a workspace where people and agents share channels; hex joins as an agent and works like it does in Discord. Buzz Desktop deploys it through a provider that writes hex's Buzz key over SSH, so the computer running Buzz Desktop must reach this machine with ssh and a key, no password. Build the provider for that computer (bun-darwin-arm64 for an Apple silicon Mac, bun-darwin-x64, bun-linux-x64) and copy it into its ~/.local/bin:

    bun build --compile --target=bun-darwin-arm64 ~/hex/.hex/channels/buzz/provider.ts --outfile /tmp/buzz-backend-hex

    Then ask them to create an agent named hex in Buzz Desktop, pick hex as where it runs with this machine's SSH destination (like user@host), deploy it, and add it to the channels they want it in (you). Deploying writes ~/hex/state/buzz/.env and restarts the hub. Tag hex in a channel to check it answers.

  • T3 Code (optional): if they run T3 Code on this machine, hex can be one of its agents, working in whatever project a thread is in. Add hex to T3 as a local ACP agent whose command is ~/hex/.hex/bin/hex acp, under providerInstances in ~/.t3/userdata/settings.json (T3 picks it up without a restart):

    "hex": { "driver": "acpRegistry", "displayName": "hex", "config": { "source": "local", "commandPath": "/home/<user>/hex/.hex/bin/hex", "commandArgs": ["acp"] } }

    Claude Code starts background sessions only in folders it trusts, so hex trusts a project folder the first time a T3 thread opens there. A T3 chat with no project works in the hex folder. hex sessions in T3 get T3's own tools too, like html_render and preview.

  • More machines (optional): an agent job (job <unit> claude -p …) runs on this machine while it has a free slot and the memory and disk, however busy its CPU, on their other machines after that, and waits in line when none has room. The builds, tests and evals hex's agents run, and jobs with no agent, run 10 nice levels below the agents, so a busy CPU doesn't keep them out. A machine has room (.hex/bin/room) while a fifth of its memory and 25 GB of disk are free, and, for another machine, while its CPU is at most half busy and, for a Mac, it's not slowed by heat. It runs jobs as its own hex, the hex agent in its T3 Code, through this machine's T3 Code and its link to that one; a machine whose T3 Code has no hex takes no jobs. To add one, with hex installed on it, the t3 CLI and a signed-in Claude Code:

    1. ssh both ways with a key that needs no agent or passphrase, since jobs connect from services: from here env -u SSH_AUTH_SOCK ssh -o BatchMode=yes <name> true must work (<name> is what ssh reaches it by), and from there env -u SSH_AUTH_SOCK ssh -o BatchMode=yes <user>@<this machine's hostname> true, since its jobs reach hex that way.
    2. There, put T3CODE_PORT=3774 and T3CODE_HOST=127.0.0.1 in ~/.t3-hex/service.env, run t3 service install --base-dir ~/.t3-hex, set "linkedEnvironmentsEnabled": true in ~/.t3-hex/userdata/settings.json, add hex there under providerInstances as "hex", as in T3 Code above, and run t3 pair --base-dir ~/.t3-hex --tailscale --tailscale-serve-port 3774.
    3. Here, set the same setting in ~/.t3/userdata/settings.json and run t3 environment link <its https URL> --pairing-code <code> --access full-access. A link lasts 30 days, so add a job to ~/hex/schedules.json that renews it on the 1st and 15th: "<name>-link": { "cron": "0 9 1,15 * *", "prompt": "Run `.hex/bin/t3-relink <name>`, which renews the T3 Code link to <name> (links last 30 days). Tell me only if it failed, with its error." }.
    4. Set "HEX_MACHINES": "<name>:3" (then how many jobs it takes; several go space-separated, in order) in the env of ~/hex/.claude/settings.json. HEX_SLOTS (12) caps jobs on this machine.

7. Say hi (you)

Ask them to say hi in General. hex should answer within a few seconds. Then show them what hex does on its own: ask for something worth its own thread (for example "research X and keep me posted") and a new topic will appear with a session working on it.

Moving hex

Everything hex knows lives in four places: hex itself (.hex/, this repo), their folder (~/hex, a git repo of its own), state/ (hex.db, and who may talk to hex: each channel's access.json), and the vault (~/.enclave). On a new machine, with hex stopped on the old one: clone their folder to ~/hex and hex into ~/hex/.hex, copy over state/hex.db, state/*/access.json, .env and the vault, then run ~/hex/.hex/bin/hex restore.

What else hex needs on their machines goes in ~/hex/services.json, in the shape of hex's own .hex/services.json:

{
  "install": {
    "rclone": "curl -fsSL https://rclone.org/install.sh | sudo bash",
    "~/notes": "git clone https://github.com/<them>/notes ~/notes"
  },
  "units": ["services/backup.timer", "services/backup.service", "services/hex.service.d/env.conf"],
  "managed": { "cleanupPeriodDays": 90 }
}
  • install: a command, or a path (from home with ~/), and the line that makes it when it's missing. They run in order, in the folder of the list.
  • units: systemd unit files to link and enable, from the list's folder or from home. A file in a folder named for its unit (hex.service.d/) is a drop-in for it.
  • managed: Claude Code managed settings, merged into the machine's.

On more than one machine

A hex that should run on whichever of their machines is up keeps its records where every one of them reaches: in a Durable Object on their own Cloudflare account, in place of state/hex.db. Cloudflare runs exactly one of it and answers a write once several of its machines have it, so nothing is copied when hex moves, and a hex command or a terminal session on any machine writes to the same place. It takes the Workers Paid plan ($5 a month): the free plan stops writes after 100,000 rows a day.

  1. Put CLOUDFLARE_API_TOKEN (the "Edit Cloudflare Workers" template) and CLOUDFLARE_ACCOUNT_ID in ~/hex/.env, and run ~/hex/.hex/bin/hex store deploy. It makes the key the store answers to, keeps it in .env as HEX_STORE_KEY, deploys the Worker with it, and prints the Worker's address once it answers. A Worker that answers to a key already keeps it: a machine without that key in its .env is refused.
  2. With no session mid-turn, since none can hand its words to a hub while hex is stopped: ~/hex/.hex/bin/hex stop, then ~/hex/.hex/bin/hex store move <the address> hex, where hex names the object the records go into. It moves only into a Worker that runs the store this hex is built with (after an update, run hex store deploy again first), then sends every row of hex.db, compares each with what the object holds, then writes state/store.json (the address, the name and the key), which is what points hex there, and renames hex.db to hex.db.moved (one an earlier move left is kept, under the time it was set aside). A move that stopped partway finishes or starts over when run again, and while it runs no hub starts on this machine, however hex is started. Then ~/hex/.hex/bin/hex start. Where hex runs as hex.service, hex stop and hex start stop and start the unit, so systemd doesn't bring hex back in between.
  3. On each other machine, set hex up as above, then copy over state/store.json in place of state/hex.db, and the three lines of .env above into that machine's own ~/hex/.env: an update there deploys the store, and runs as a job that finds the Cloudflare token in that file only.

hex sql '<query>' reads the records wherever they live, and can change nothing. hex store copy <file> writes them out as a SQLite file. To go back to a file: ~/hex/.hex/bin/hex stop, ~/hex/.hex/bin/hex store back, then ~/hex/.hex/bin/hex start. It takes hex, so a hub on any other machine stops, copies every row into state/hex.db, compares each with what the object holds, and only then sets state/store.json aside as store.json.back; then delete state/store.json on each other machine. If it fails, hex stays on the object and running it again starts over, and where the records are in hex.db already it does nothing, so it can run as a start step, as the move can. To give either a time limit, run it under timeout <seconds>: what it ends before store.json is written (moving) or set aside (going back) leaves hex where it was, and once that's done hex has moved, whatever the exit.

hex status and hex doctor say whether the store answers, and before a move hex status says whether the Worker hex store deploy set up answers.

hex runs on one machine at a time: a hub that starts takes hex, and the one that had it stops at its next call, tells General why, and stays stopped, whatever starts it (a service manager included), until hex start there. Whatever passes hex between machines can give hex run the lease's number as HEX_STORE_LEASE, a whole number: once a hub has claimed hex with one, the object refuses a hub on an older lease or on none, so a machine that comes back can't take hex back. A start on a newer lease than the one a machine lost hex under is that machine holding hex again, so it runs without hex start. A machine that lost hex still pays the store what its hubs owed, each time something starts hex there. A hex that no longer runs under a lease ends it with hex store lease clear.

Updating

.hex/bin/update runs every morning from schedules.json. It pulls hex once bin/check passes on the new version, and restarts the hub and hex's sessions. When the records are in a Durable Object, it first deploys the store the new version is built with, if it differs, and goes on only once the object state/store.json names answers as that store, which it has restart on the new code at once. If the object still answers as the store before after five and a half minutes, past the longest Cloudflare would put the restart off, the new one stays deployed and hex ships at the next update; if it doesn't answer at all, the store before it goes back. Either way hex stays as it was until then. Nothing deploys over a store that doesn't answer, or that was built from a commit made after the new version's.

A version that starts but misbehaves goes back with ~/hex/.hex/bin/hex rollback <commit>, naming the earlier commit to go back to: in seconds, with no check and no store deploy, since an older hex runs on a newer store. It runs where hex runs, restarts the hub once no call is live, and says hex went back only once a hub on that commit is up and General has connected to it; otherwise it says what's in the way, and running it again finishes it. From then on bin/update won't take the commit hex went back from, or anything main had built on it by then, including an update already under way, on this machine or on one that takes hex over later (each hub tells the store what hex rollback went back from on its machine); a commit merged to main after the rollback ships as usual, so revert the bad one next. A hub that can't start goes back on its own machine only, since the cause may be that machine's. hex refused <commit> says whether a commit is held back. If the commit gone back to can't start either, hex stays down and says so rather than run the one it went back from: go further back. A rollback made by mistake is undone by merging any commit to main, such as a reland of what it held back.

Backups

Every night at 3:00 on their clock, General's hub copies hex's records (state/hex.db, or what the Durable Object holds) to state/backups/hex-<date>.db, and to ~/hex-backups on hex's computer when HEX_COMPUTER names one, keeping the last seven in each place. A night that fails tells General. To bring one back:

  1. ~/hex/.hex/bin/hex stop, on every machine that runs hex.
  2. Copy the backup over ~/hex/state/hex.db, and delete hex.db-wal and hex.db-shm beside it.
  3. With the records in a Durable Object, they go into a new one, and the one hex used stays as it was: delete state/store.json, run ~/hex/.hex/bin/hex store move <the address> <a name no object has had>, and copy the new state/store.json to each other machine.
  4. ~/hex/.hex/bin/hex start.

Watching from outside (optional)

hex can't tell anyone it's down when its own machine is. watch/ is a small Executor app that runs on Executor's servers: the hub sends it a signed pulse each minute, and it tells their Telegram group when the pulses stop for 4 minutes, when they start again, and when two machines run a hub at once.

  1. npm i -g executor@beta, executor apps login, executor apps create --name hex-watch --files ~/hex/.hex/watch, then executor apps deploy --app <its id> --files ~/hex/.hex/watch.
  2. In the app's page on Executor, connect a Telegram bot account with hex's bot token (you), then finish the pulse webhook's setup there: it shows a callback URL and a signing secret.
  3. Set HEX_PULSE_URL to the callback URL and HEX_PULSE_SECRET to the secret in .env, and run ~/hex/.hex/bin/hex restart.
  4. Enable the app's watch schedule, and point it at General with its alertTo tool: { "chat": "<HEX_MAIN_THREAD>", "thread": "" }. Its status tool should list this machine within a minute.