Setting up devbox

From PostHog/posthog · View interactive version

Setting up devbox is an AI agent skill from the GitHub repository PostHog/posthog. Starts, connects to, and troubleshoots a PostHog devbox, a remote Coder workspace for PostHog development that can also run the full stack, through `hogli devbox:*` commands. Use when asked to spin up or resume a devbox, open a shell or editor on it, run a command on it, mirror a local checkout to i

How to use this skill

Skill file

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.

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

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

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.

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 script runs the main checkout's hogli, so pull the main checkout after a change to these commands.

Other tasks

Gotchas

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.