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 worktree | Devbox | Tasks sandbox |
| ---------------------- | ---------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Persistence after stop | Everything 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 reset | The 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 steps | Create 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 reach | The 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 URL | localhost:8010 | Stable 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. |
| Cost | The 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 for | Work 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:employeesin 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 agentdoes 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:
- Shell:
hogli devbox:ssh. - Editor:
hogli devbox:open --vscode,--cursor, or--web. - Commands from an agent:
hogli devbox:exec, described in Run commands on the box. - Edit locally, run on the box: read references/sync.md before using
hogli devbox:sync. - The running app: follow Run the PostHog app.
- A box per git worktree: follow One devbox per worktree.
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 leadingworktree-,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--labelto 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-fromusesdevbox:clone, so the source must be running and the clone asks for confirmation unless-yis passed. Pass-yonly after the user agrees.hogli worktrees:clean --mode full --stop-boxesstops the recorded box of each worktree it removes, and--delete-boxesdeletes it with its disk. With neither flag, it uses the action saved by--on-clean, and--keep-boxesoverrides 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-runlists the boxes, and the confirmation prompt counts them.- A box whose worktree was already removed gets the same action on the next
worktrees:cleanrun, within that run's--repoand--sourceselection. A moved or unmounted worktree does not count as removed. hogli devbox:worktree:pruneacts 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--stopor--deleteto choose,--path <worktree>to limit it to one worktree, and--dry-runto list them. Use it after t3code, herdr or a plaingit worktree removedeleted 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
hoglandCLI, 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 withhogland devbox ssh wt-<label>, and start the stack there withhogli start -d. - Pass
--provider hoglandwith--autoto save Hogland as the default, which automatic boxes then use.hogli devbox:config:rm worktree-providergoes back to Coder. worktrees:clean --stop-boxeshibernates the box, and--delete-boxesdeletes 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 devboxwt-<label>, ordefaultfor the devbox nameddefault. It runshogland devbox clone, so it needs ahoglandCLI 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-yis passed. Pass-yonly after the user agrees.--start-appsaves the setting on a new box as the file~/.config/hogli/start-app. Every laterdevbox:worktreerun on that box then waits for the mirror to catch up and runshogli 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-checkouthook, forclaude,codex,posthog-codeandphw, which it recognizes by their worktree folders, and forother. - 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 conductorwrites its hooks to the main checkout's uncommitted.conductor/settings.local.tomlinstead, and leaves an existing file for you to edit. t3code does not runt3.jsonby 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 runherdr plugin link <main checkout>/tools/herdr-devbox-pluginonce. Paseo has no checked-in hook either: put an untrackedpaseo.jsonin the main checkout whoseworktree.setuprunsbin/devbox-worktree-hook created paseoand whoseworktree.teardownrunsbin/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.login the worktree's git directory. Read it withcat "$(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.lockdiffers from the main checkout's. - Turn it off with
hogli devbox:worktree --auto offorhogli devbox:config:rm worktree-auto. - Boxes keep running until
hogli worktrees:cleanremoves their worktree, so pair this with--on-clean stop.hogli devbox:worktree --auto claude --on-clean deletesaves both settings, from any checkout.hogli devbox:setupshowsoffwhen no source is enabled. - Superset, Orca and worktrunk run
bin/devbox-worktree-hook removingbefore they delete a worktree. It runshogli 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 archivinginstead, 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-cleanaction saved, every new worktree runsdevbox:worktree:prunein 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 whengit worktree prunewould delete that directory, so a worktree on an unmounted drive counts as removed unlessgit worktree locklocks it. - herdr has two ways to use devboxes. With
--auto herdr, agents run on the laptop and each herdr worktree gets its own box. Withhogli 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
otheris 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_TOKENreads 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 runhogli devbox:restarton a running box. The template documentsCLAUDE_CODE_OAUTH_TOKEN,GH_TOKEN,ANTHROPIC_API_KEY,OPENAI_API_KEY, andPOSTHOG_GIT_SIGNING_KEY, whichhogli devbox:setup --configure-git-signingsets.devbox:secret:listshows names, env vars, and descriptions, never values. - Keys for a while (evals):
hogli devbox:secrets:pushlends theop://references in~/.config/posthog/devbox-secrets.envto 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:statusanddevbox:secrets:clearshow 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, intodevbox-<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-yonly after the user agrees. Only the owner can clone a box. - Template updates:
hogli devbox:updateapplies the latest template when the box is outdated.devbox:startalso updates an outdated box when it starts it. Boxes thatdevbox:startanddevbox:clonecreate have Coder's automatic updates on, so they also move to the latest template when they start from the web UI or autostart, and onhogli 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 thatdevbox:updatewarns about. - Disk full:
hogli devbox:cleanup:diskrunshogli doctor:diskon 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,--yesand--areaoptions ofdoctor:disk. Stale worktrees on the box needhogli worktrees:cleanrun there. - Claude Code on the box: the user logs in on the box with
hogli devbox:claude:login, which opens an interactiveclaude auth login, so ask the user to run it in their own terminal.devbox:claude:statusshows the account and auth method without a credential, anddevbox:claude:logoutdeletes the login from the box. TheCLAUDE_CODE_OAUTH_TOKENsecret fromdevbox:setupis 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
ghisn't logged in.hogli devbox:gh:loginlogsghin 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:statusshows the account with the token masked, anddevbox:gh:logoutdeletes the login from the box. - Pairing:
hogli devbox:share --user <coder-user> --role usegrants access, anddevbox:userslists usernames. The other user gets a shell as the owner, including the owner's Claude Code and GitHub CLI logins, sodevbox:shareoffers to log out of each first and refuses when it can't check a login, unless--keep-claude-loginor--keep-gh-loginis passed.devbox:unshareremoves access only afterhogli 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-dotfilessaves a dotfiles repo that the box applies on start, running its executableinstall.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.