setting-up-devbox

Guide a PostHog engineer through spinning up, connecting to, running commands on, and mirroring local code to a remote devbox (a Coder workspace running the…

npx skills add https://github.com/posthog/posthog-foss --skill setting-up-devbox

Setting up a PostHog devbox

A devbox is a Coder workspace on EC2 for PostHog development. Drive it through hogli devbox:* and don't reimplement what those commands do. A new box has the repo at ~/posthog on master, prewarmed dependencies, and Claude Code installed. hogli devbox:<command> --help has the current flags. This skill covers the order of operations and what the help text leaves out.

People use a box in different ways: a shell or editor for general development, a remote target for a local checkout, or a host for the running PostHog app. Work out which one the user wants, and don't start the PostHog stack unless they ask for the app.

Choosing an environment

When the user asks whether a devbox is the right place for the work, compare it with the other two options:

Local worktreeDevboxTasks sandbox
Persistence after stopEverything stays on the user's machine.devbox:stop keeps the disk, including /home. Only devbox:destroy deletes it.The sandbox is destroyed after an idle timeout: 30 minutes for background runs, 1 hour for user-created runs, 10 minutes for PostHog AI runs, and at most 2 hours with a per-task override. Interactive Modal runs snapshot /tmp/workspace before cleanup so a follow-up can restore it. Files outside /tmp/workspace are lost.
Context resetThe user decides.The user decides. Agent sessions on the box stay on its disk.Each task starts a new agent session. A follow-up on the same task resumes that session from the snapshot or the run log.
Provisioning stepsCreate a worktree. Install dependencies or start the stack only when needed.devbox:doctor and devbox:setup once per machine, then devbox:start.One message creates the task. The backend provisions the sandbox, clones the repository, and starts the agent.
MCP reachThe MCP servers configured on the user's machine.The MCP servers the user configures in Claude Code on the box.MCP Store installations: shared team installations, plus the user's personal installations for tasks they create. Built-in agent tasks get only the connections granted to that agent. PostHog Desktop can import or relay its own servers into a run.
Preview URLlocalhost:8010Stable and PostHog-internal: https://app--<workspace>--<coder-user>.<coder-host>.One URL per run, /api/projects/<team>/tasks/<task>/runs/<run>/preview/, on the dev-stack image. It works only while the sandbox runs.
CostThe user's machine.An EC2 instance. Billing stops on devbox:stop.Sandbox time is metered per run and counts against the team's PostHog Desktop usage limit.
Best forWork that does not need the running stack.Long-lived state, MCP servers outside the MCP Store, a stable preview link, and agent history on the box.Bounded one-off work that benefits from a fresh context.

A stopped box keeps its state, and hogli devbox:start (with -n <label> for a labeled box) resumes it.

Get a box

Copy this checklist and track it:

- [ ] 1. hogli devbox:doctor: the tailnet and control plane checks are ok
- [ ] 2. hogli devbox:setup has run on this machine
- [ ] 3. hogli devbox:start: the box is running
- [ ] 4. The user is connected the way they asked for
- [ ] 5. hogli devbox:stop when the user is done

1. Check access

hogli devbox:doctor is read-only: it never prompts or changes host config. Commands that reach a box run the same reachability check first, so fix a failure here before anything else.

  • The active tailnet must be posthog.com. Doctor prints it and names a wrong tailnet as the cause.
  • Every PostHog employee has the route to the Coder control plane through group:employees in the tailnet policy. Nobody needs a PR to get access.
  • If doctor reports the control plane unreachable, read references/access-troubleshooting.md before changing anything.
  • [missing] Commit signing agent does not block starting or using a box. It matters only for signed commits made on the box.

2. Set up this machine once

hogli devbox:setup is interactive, so ask the user to run it in their own terminal. Without a terminal, login and every runtime command work when CODER_SESSION_TOKEN and CODER_URL are exported, because the Coder CLI uses that token before any stored login. Setup still prompts for each configuration step that has no saved value, so pass --skip-configure-<step> for those. Read the token from a file into the variable. Never put it on a command line or in the conversation. SSH from a shell that has the variable works. When setup says no working login is stored on disk, programs that start without the variable, such as an editor or a mutagen daemon, cannot reach the box. It installs the Coder CLI at the server's version into ~/.hogli/bin, logs in, installs the pinned mutagen binary for devbox:sync, and writes the coder.* SSH host entries that devbox:ssh and devbox:exec use. ~/.hogli/bin is not on PATH, so call that CLI as ~/.hogli/bin/coder when a step needs coder directly. Each optional step has a --configure-<step> and --skip-configure-<step> flag: ssh, git-identity, git-signing, region, dotfiles, claude. Run it again when a command prints Coder CLI vX does not match server vY, because it reinstalls the matching CLI.

On Linux, the reachability check can run sudo tailscale set --accept-routes and prompt for a password. Run setup interactively once before an agent drives devbox commands unattended.

3. Start the box

hogli devbox:start

This creates the box on first use and resumes it after a stop. It returns once the box's startup scripts finish, so the box is ready to connect to. devbox:restart, devbox:update and devbox:clone wait the same way. If a script fails or the wait gives up, the box still runs and hogli prints a warning that points to hogli devbox:logs. It brings up the PostHog stack only when the workspace has --start-app set, which is covered in Run the PostHog app. --disk (100 or 200 GiB) applies only when the box is created. When AWS has no capacity for the box's instance type in its zone (InsufficientInstanceCapacity), hogli starts the box on the template's other instance types by itself and keeps the disk. There is nothing to pass. --region (us-east-1 or eu-central-1) starts that region's default box and creates it if it doesn't exist, so leave it off when resuming an existing box. A box's region can't change.

The default box is devbox-<coder-user>, and a labeled box is devbox-<coder-user>-<label>. Boxes in eu-central-1 add an -eu suffix, for example devbox-<coder-user>-eu. hogli devbox:list shows the exact names. Target a labeled box with -n <label> on commands that act on a box. Inside a worktree that devbox:worktree set up, those commands target the worktree's box without -n, print the box they picked on stderr, and stop when that box was deleted; rerun devbox:worktree to create it again. An explicit -n <label> or @user still wins, -n @<coder-user> targets your default box, and devbox:clone without a source still copies the default box.

4. Connect

Match what the user asked for:

5. Stop when done

hogli devbox:stop keeps the disk and stops billing. It also pauses the box's devbox:sync mirror, and devbox:start resumes it. Stops, starts, and devbox:update keep /home. hogli devbox:destroy deletes it, so don't keep anything irreplaceable only on a box.

Run commands on the box

hogli devbox:exec -- <command> runs one command over SSH and returns its exit code. Without --flox, wrap the command in bash -lc '...'. A non-login shell doesn't reliably load the shell profile, so tools on a login-shell PATH such as ~/.local/bin report "command not found". Project tools such as pnpm, pytest and the Python venv are on PATH only inside PostHog's flox environment. For those, add --flox, which runs the command in ~/posthog inside flox activate: hogli devbox:exec --flox -- pnpm --filter=@posthog/frontend typescript:check. Use bash -c '...' after --flox when the command needs shell syntax such as &&. Put -- between hogli's flags and the command's own. devbox:exec and devbox:ssh fail to connect until devbox:setup has written the SSH config.

Run the PostHog app

Use this section only when the user wants the app, for example to QA a change or share a link.

Start the stack

  • New box: hogli devbox:start --start-app. The setting stays on the workspace, so every later start brings the stack up in the background. The flag applies only when hogli creates the box; on an existing box hogli refuses it, because the Coder CLI keeps a parameter's last-build value. Change it on an existing box in the Coder dashboard under the workspace's parameters.
  • Running box: hogli devbox:exec -- bash -lc 'cd ~/posthog && ./bin/hogli up -d -y'.

Wait for it

The stack keeps booting after the start command returns. Poll in a bounded loop until this prints 200 or 302. A 000 or 502 means the stack is still booting.

hogli devbox:exec -- bash -lc "curl -s -o /dev/null -w '%{http_code}' --max-time 10 http://127.0.0.1:8010/"

When resuming QA on an existing box, check it before recreating sync, restarting the stack, or making a new box:

hogli devbox:status
hogli devbox:exec -- bash -lc 'cd ~/posthog && git status --short --branch && git rev-parse --short HEAD'
hogli devbox:sync --json

Keep going when the app serves the intended branch and SHA, the target route loads, and its APIs work. Note unrelated degraded processes instead of chasing full health.

Give the user the URL

The template exposes the app as a Coder subdomain app that only the box owner can open:

https://app--<workspace>--<coder-user>.<coder-host>

<coder-host> is the host of Coder URL in hogli devbox:doctor, and hogli devbox:list shows the workspace name. hogli devbox:status prints this URL on the App: line, with the app's health check status, for a box the user owns. For example, devbox-jane-d owned by jane-d on coder.dev.posthog.dev is https://app--devbox-jane-d--jane-d.coder.dev.posthog.dev. The user must be on the tailnet, and the browser goes through Coder sign-in first. Each box has its own URL, so prefer it over forwarding when the user runs several boxes.

Verify the link before handing it over. Coder runs the template's health check against the app, so read that status instead of sending a request with the user's session token. hogli devbox:status shows it, or read it directly:

~/.hogli/bin/coder list --output json | jq -r '.[] | select(.name=="<workspace>") | .latest_build.resources[]?.agents[]?.apps[]? | select(.slug=="app") | .health'

healthy means Coder routes the URL to a working app. initializing means the check hasn't passed yet, and unhealthy means it keeps failing.

hogli devbox:forward is the alternative when the user wants localhost. It tunnels box port 8010 to a local port and holds the terminal until stopped. The default box gets localhost:8010 while that port is free. Every other box, and the default box when 8010 is taken, gets a port in 18000-18999 derived from the box name, so the same box gets the same port on each run. When that port is taken, the next free one is used. Pass --port <port> to choose the port yourself; the command then fails if that port is in use.

One devbox per worktree

Use this when the user runs several local git worktrees and wants each one to run its stack on its own box. Run hogli devbox:worktree from inside the linked worktree, never through devbox:exec.

hogli devbox:worktree --dry-run                 # print the box and sync plan
hogli devbox:worktree                           # start or create the box, then create the mirror
hogli devbox:worktree --clone-from default -y   # create the box as a clone of a running box
hogli devbox:worktree --on-clean stop           # save what worktrees:clean does with the box
  • The label comes from the branch name, lowercased, with / and _ turned into - and a leading worktree-, worktree/ or <coder-user>/ dropped. Coder caps workspace names at 32 characters, so a long branch gets a shortened label with a 4-character hash. Pass --label to choose one.
  • hogli records the worktree path and box name in ~/.config/posthog/hogli_devbox_worktrees.json. A re-run reuses that box, even after a branch rename, and keeps an existing mirror.
  • A worktree recreated at the same path, as t3code does when it resumes a thread it cleaned up, takes over the box of the worktree it replaced while that box still exists, and gets a new mirror.
  • It refuses a derived label whose box already exists and is not recorded for this worktree, so it never takes over a box the user made by hand. Pass --label <label> to use that box on purpose. It always refuses a box recorded for another worktree.
  • --clone-from uses devbox:clone, so the source must be running and the clone asks for confirmation unless -y is passed. Pass -y only after the user agrees.
  • hogli worktrees:clean --mode full --stop-boxes stops the recorded box of each worktree it removes, and --delete-boxes deletes it with its disk. With neither flag, it uses the action saved by --on-clean, and --keep-boxes overrides that. It acts only on boxes in the record file, and skips a box that was recreated under the same name. A box it leaves alone is dropped from the record file, so a later run never touches it. --dry-run lists the boxes, and the confirmation prompt counts them.
  • A box whose worktree was already removed gets the same action on the next worktrees:clean run, within that run's --repo and --source selection. A moved or unmounted worktree does not count as removed.
  • hogli devbox:worktree:prune acts only on those boxes of removed worktrees, without removing any worktree. It uses the saved action, or stops the boxes when none is saved. Pass --stop or --delete to choose, --path <worktree> to limit it to one worktree, and --dry-run to list them. Use it after t3code, herdr or a plain git worktree remove deleted a worktree.
  • Clear the saved action with hogli devbox:config:rm worktree-boxes.

Run worktree boxes on Hogland

hogli devbox:worktree --provider hogland gives the worktree a Hogland devbox, restored from the devbox-golden snapshot, instead of a Coder workspace.

  • It needs the hogland CLI, installed and signed in. A missing CLI fails with the install command.
  • The box is named wt-<label>, and Hogland caps the name at 32 characters.
  • hogli writes an SSH entry for hogland.wt-<label> under ~/.hogli/hogland-ssh/, and the mirror goes to /home/hog/posthog. Open a shell with hogland devbox ssh wt-<label>, and start the stack there with hogli start -d.
  • Pass --provider hogland with --auto to save Hogland as the default, which automatic boxes then use. hogli devbox:config:rm worktree-provider goes back to Coder.
  • worktrees:clean --stop-boxes hibernates the box, and --delete-boxes deletes it.
  • A worktree that still has a box on the other provider is refused until that box is removed.
  • --clone-from <label> clones the running Hogland devbox wt-<label>, or default for the devbox named default. It runs hogland devbox clone, so it needs a hogland CLI that has that command; an older one fails with the upgrade command. The clone copies the whole box, including secrets, so it asks for confirmation unless -y is passed. Pass -y only after the user agrees.
  • --start-app saves the setting on a new box as the file ~/.config/hogli/start-app. Every later devbox:worktree run on that box then waits for the mirror to catch up and runs hogli up -d. A clone keeps the source's setting. On an existing box the flag is ignored, so delete or create that file on the box to change it.

Provision a box for every new worktree

hogli devbox:worktree --auto claude,phw saves the worktree sources that get a box automatically. The sources are claude, codex, posthog-code, phw, t3code, herdr, superset, emdash, orca, conductor, worktrunk, paseo, and other for a plain git worktree add. It only saves the setting, so run it from any checkout. Two triggers start hogli devbox:worktree -y in the background, and the first one for a worktree wins:

  • The husky post-checkout hook, for claude, codex, posthog-code and phw, which it recognizes by their worktree folders, and for other.
  • The app's own create hook, which runs bin/devbox-worktree-hook created <source>. The repo checks these hooks in for Superset (.superset/config.json), Emdash (.emdash.json), Orca (orca.yaml) and worktrunk (.config/wt.toml). Orca and worktrunk ask each user to approve the commands once. Conductor would let a checked-in script replace each user's own scripts, so --auto conductor writes its hooks to the main checkout's uncommitted .conductor/settings.local.toml instead, and leaves an existing file for you to edit. t3code does not run t3.json by itself: each user imports it once from Import from t3.json in the project's scripts menu or in Settings → Projects → Actions. t3code runs only the first script set to run on worktree creation, so a project that already has its own setup script skips this one. herdr has no repo hook file, so run herdr plugin link <main checkout>/tools/herdr-devbox-plugin once. Paseo has no checked-in hook either: put an untracked paseo.json in the main checkout whose worktree.setup runs bin/devbox-worktree-hook created paseo and whose worktree.teardown runs bin/devbox-worktree-hook removing. Paseo copies it into each new worktree.

The script runs the main checkout's hogli, so pull the main checkout after a change to these commands.

  • Claude subagent worktrees (.claude/worktrees/agent-*) never get a box, so a fan-out of agents doesn't create one box per agent.
  • The hook returns at once. Output goes to hogli-devbox-worktree.log in the worktree's git directory. Read it with cat "$(git rev-parse --git-dir)/hogli-devbox-worktree.log".
  • The hook skips the box when the main checkout has no Python environment to borrow, or when this worktree's uv.lock differs from the main checkout's.
  • Turn it off with hogli devbox:worktree --auto off or hogli devbox:config:rm worktree-auto.
  • Boxes keep running until hogli worktrees:clean removes their worktree, so pair this with --on-clean stop. hogli devbox:worktree --auto claude --on-clean delete saves both settings, from any checkout. hogli devbox:setup shows off when no source is enabled.
  • Superset, Orca and worktrunk run bin/devbox-worktree-hook removing before they delete a worktree. It runs hogli devbox:worktree:teardown --background, which stops the mirror while the files still exist and then stops the box in the background (log: ~/.config/posthog/hogli-devbox-teardown.log). The box's record is then dropped, so the box no longer belongs to any worktree.
  • Emdash and Conductor run bin/devbox-worktree-hook archiving instead, because they keep an archived worktree on disk. It adds --keep-record, so when the app restores the worktree, its create hook starts the same box again.
  • herdr reports a removal only after the folder is gone, so its plugin runs devbox:worktree:prune --path <worktree>.
  • Claude Code and t3code have no removal hook. With an --on-clean action saved, every new worktree runs devbox:worktree:prune in the background, which acts on the boxes of worktrees removed since. Run it by hand to clean up sooner.
  • Claude Code deletes a worktree's folder but leaves its admin directory under .git/worktrees/. Prune counts a worktree as removed when git worktree prune would delete that directory, so a worktree on an unmounted drive counts as removed unless git worktree lock locks it.
  • herdr has two ways to use devboxes. With --auto herdr, agents run on the laptop and each herdr worktree gets its own box. With hogli devbox:open --herdr, the box is a herdr machine, and agents and worktrees run on it with no mirror. devbox:open --herdr <label> on a worktree's box gives terminals for the stack and tests. Edit files in the local worktree, because files edited on a mirrored box conflict with the mirror. Deleting a box also removes its herdr machine.
  • A t3code worktree restored from a cleaned-up thread skips setup scripts, so it gets a box only when other is enabled.

Other tasks

  • Tokens on the box: store them as Coder user secrets, which reach every box the user owns. hogli devbox:secret:set GH_TOKEN reads the value from a hidden prompt or from --file. Never put a token on a command line or in the conversation. A secret reaches only boxes started after it is set, so run hogli devbox:restart on a running box. The template documents CLAUDE_CODE_OAUTH_TOKEN, GH_TOKEN, ANTHROPIC_API_KEY, OPENAI_API_KEY, and POSTHOG_GIT_SIGNING_KEY, which hogli devbox:setup --configure-git-signing sets. devbox:secret:list shows names, env vars, and descriptions, never values.
  • Keys for a while (evals): hogli devbox:secrets:push lends the op:// references in ~/.config/posthog/devbox-secrets.env to the box, in memory and for 12 hours by default. On the box, wrap the command that needs them: devbox-secrets run -- <command>. devbox:secrets:status and devbox:secrets:clear show and remove them.
  • A second box with the same state: hogli devbox:clone --as <label> copies a running box's full disk, including any secrets on it, into devbox-<coder-user>-<label> in the source box's region. Stop the stack on the source first for a consistent copy. It asks for confirmation, so pass -y only after the user agrees. Only the owner can clone a box.
  • Template updates: hogli devbox:update applies the latest template when the box is outdated. devbox:start also updates an outdated box when it starts it. Boxes that devbox:start and devbox:clone create have Coder's automatic updates on, so they also move to the latest template when they start from the web UI or autostart, and on hogli devbox:restart. Coder never updates a box while it keeps running, but a restart of an outdated box is a full template update and can trigger the one-time dependency re-install that devbox:update warns about.
  • Disk full: hogli devbox:cleanup:disk runs hogli doctor:disk on the box that the other devbox commands pick, and -n <label> picks another box. Inside a devbox it cleans that box. It takes the --dry-run, --yes and --area options of doctor:disk. Stale worktrees on the box need hogli worktrees:clean run there.
  • Claude Code on the box: the user logs in on the box with hogli devbox:claude:login, which opens an interactive claude auth login, so ask the user to run it in their own terminal. devbox:claude:status shows the account and auth method without a credential, and devbox:claude:logout deletes the login from the box. The CLAUDE_CODE_OAUTH_TOKEN secret from devbox:setup is an opt-in for unattended use: it can only make model requests, so Remote Control and usage checks don't work, and it overrides the box login on every box the user owns. Never turn on Remote Control or skipped permission prompts on a box for the user.
  • GitHub on the box: git uses Coder's GitHub app, which reaches only repos where the app is installed, and gh isn't logged in. hogli devbox:gh:login logs gh in on the box and points git at that login. gh prints a one-time code the user enters at https://github.com/login/device, so ask the user to run it in their own terminal. devbox:gh:status shows the account with the token masked, and devbox:gh:logout deletes the login from the box.
  • Pairing: hogli devbox:share --user <coder-user> --role use grants access, and devbox:users lists usernames. The other user gets a shell as the owner, including the owner's Claude Code and GitHub CLI logins, so devbox:share offers to log out of each first and refuses when it can't check a login, unless --keep-claude-login or --keep-gh-login is passed. devbox:unshare removes access only after hogli devbox:restart.
  • Build and agent logs: hogli devbox:logs -f.
  • Personal setup: the box works as shipped. Changes made on the box survive stops and updates. hogli devbox:setup --configure-dotfiles saves a dotfiles repo that the box applies on start, running its executable install.sh. A saved repo URL applies to boxes hogli creates. To change it on an existing box, edit the workspace's parameters in the Coder dashboard.

Gotchas

  • Never echo a secret value into the transcript, logs, a PR, or a command line.
  • code-server (devbox:open --web) has no SSH agent forwarding, so commit signing fails there. Use VS Code Desktop, Cursor, or JetBrains over SSH to sign commits.

More skills from posthog