Lifecycle specification

Post-Attach Phase

Human-facing hooks that run each time a developer or editor attaches — short guidance, actionable warnings, and pointers to interactive sign-in.

Applies at
.devcontainer/lifecycle/post-attach.d/
Status
Stable

01 Defines

The postAttachCommand phase: scripts in post-attach.d/ that run every time a developer or editor attaches to a running container.

02 Applies when

  • A task only makes sense once a person is present.
  • Interactive authentication cannot happen unattended and needs a short prompt instead.
  • The developer benefits from next-step guidance once the workspace is ready.

03 Boundaries

  • Workspace mutations, dependency installs, and service startup happen whether or not an editor attaches, so they belong earlier.
  • Nothing the repository needs in order to be usable depends on this phase.

Expected behaviour

  1. 01
    Scripts are fast and non-blocking, so they do not delay the editor.
  2. 02
    Scripts may run many times as developers detach and reattach.
  3. 03
    Missing authentication produces an instruction, not a failure.
  4. 04
    A failing script is reported and skipped by the runner; attaching is never blocked.

Behaviour#

Post-attach is the last phase and the only one aimed at a person. It runs on every attach, including reattaching to a container that has been running for days, so it says what is useful now and gets out of the way.

The repository stays usable without it. A container that is started and never attached — by automation, for example — has everything it needs from the earlier phases; post-attach only adds guidance on top. Anything that has to happen for the session itself belongs in Post-Start Phase .

Output as the deliverable#

A post-attach hook’s output is its product. The hook changes nothing and must succeed either way — its job is to convert machine state into the one instruction the developer needs: “run aws sso login --profile sandbox”, “run gh auth login”, “next: hugo server -D”.

That shapes everything about the phase. Hooks are one screen tall, because more text is skipped. They point at an action, because an explanation is what the action’s own output is for. And they never fail on the state they describe, because the developer has not signed in yet — the instruction itself is the successful outcome.

Failure behaviour#

A failing post-attach hook is reported and skipped like any other, and here the stakes are lowest: nothing depends on the phase, so the cost of a broken hook is a missing message, visible in the event summary. The one real failure to design against is a hook that blocks — an attach that hangs waiting for input no one sees. Fast and non-blocking is not a style preference; it is the phase’s contract.

Good uses

  • Checking aws sts get-caller-identity and suggesting aws sso login --profile sandbox
  • Checking gh auth status and showing a short gh auth login instruction
  • Showing next steps such as npm run dev or hugo server -D

Avoid

  • Workspace mutations, dependency installs, or service startup
  • Long-running tasks that delay the editor
  • Anything that must succeed before the repository is usable

Examples#

.devcontainer/lifecycle/post-attach.d/10-check-github-auth.sh
#!/usr/bin/env bash
set -euo pipefail

if ! gh auth status >/dev/null 2>&1; then
    echo "GitHub authentication is not configured. Run: gh auth login"
fi

The hook prints and exits successfully either way. Signing in is left to the developer, and an earlier phase is never blocked waiting for it.

The same pattern carries the “what next” message that makes a fresh attach feel finished rather than empty:

.devcontainer/lifecycle/post-attach.d/20-show-next-steps.sh
#!/usr/bin/env bash
set -euo pipefail

echo "Ready. Start the site with: hugo server"

A hook this small is exactly the right size: it answers the first question (“what do I do now”) and lets the work itself answer the rest.