---
source: https://iinventedlight.com/library/notes/devcontainer-lifecycle.md
title: "Run Dev Container lifecycle commands at create and start"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC-BY-4.0 (Dev Container Specification); MIT (devcontainers/cli); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Dev Container Specification, devcontainer.json reference; devcontainers/cli, devcontainers/cli README. CC-BY-4.0; MIT."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-19
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-19
as_of: 2026-11-19
confidence: medium
untested: "Not reproduced (2026-11-19). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-devops: Dev Container lifecycle scripts"
tags: [devcontainer, lifecycle, postcreatecommand, devcontainer-json]
client: Librarian
sources:
  - id: S1
    title: "devcontainer.json reference"
    publisher: Dev Container Specification
    url: https://containers.dev/implementors/json_reference/
    accessed: 2026-11-19
    license: "CC-BY-4.0"
  - id: S2
    title: "devcontainers/cli README"
    publisher: devcontainers/cli
    url: https://raw.githubusercontent.com/devcontainers/cli/main/README.md
    accessed: 2026-11-19
    license: "MIT"
---
# Run Dev Container lifecycle commands at create and start
**Answer:** When you create or work with a dev container, different commands may need to run at different points in its lifecycle. Each command property is a string or list of command arguments that should execute from the `workspaceFolder`. A single-string value is run in `/bin/sh`. Put `&&` in that string to execute multiple commands. The array syntax will execute the command without a shell.

The devcontainers CLI documents `devcontainer run-user-commands`. That command runs lifecycle commands like `postCreateCommand`.

## Create, start, and attach

`initializeCommand` runs on the host machine. It runs during initialization, during container creation, and on subsequent starts. It may run more than once during a given session. `onCreateCommand` will run after `initializeCommand`. It is the first of three commands — the others are `updateContentCommand` and `postCreateCommand` — that finalizes container setup when a new dev container is created. Those commands execute inside the container immediately after it has started for the first time.

`postStartCommand` is a command to run each time the container is successfully started. `postAttachCommand` is a command to run each time a tool has successfully attached to the container. `waitFor` is an enum that specifies the command any tool should wait for before connecting. It defaults to `updateContentCommand`.

| Property | Description |
|---|---|
| `initializeCommand` | host machine |
| `onCreateCommand` | inside the container |
| `updateContentCommand` | after `onCreateCommand` |
| `postCreateCommand` | after `updateContentCommand` |
| `postStartCommand` | each time the container is successfully started |
| `postAttachCommand` | each time a tool has successfully attached |
| `waitFor` | `updateContentCommand` |

## See also

- [devcontainer-features](https://iinventedlight.com/library/notes/devcontainer-features/)

## Claims

- id: C1
  claim: onCreateCommand runs after initializeCommand, and the create-time trio finishes with postCreateCommand.
  source: S1
  evidence: "`onCreateCommand` will run after `initializeCommand`"

- id: C2
  claim: postStartCommand runs on each successful start, and waitFor defaults to updateContentCommand.
  source: S1
  evidence: "Defaults to `updateContentCommand`."

- id: C3
  claim: The devcontainer CLI run-user-commands action runs lifecycle commands such as postCreateCommand.
  source: S2
  evidence: "Runs lifecycle commands like `postCreateCommand`"

## Sources

- [S1] devcontainer.json reference. Dev Container Specification. https://containers.dev/implementors/json_reference/ . License: CC-BY-4.0. Accessed 2026-11-19.

- [S2] devcontainers/cli README. devcontainers/cli. https://raw.githubusercontent.com/devcontainers/cli/main/README.md . License: MIT. Accessed 2026-11-19.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Dev Container Specification, devcontainer.json reference; devcontainers/cli, devcontainers/cli README. CC-BY-4.0; MIT. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
