Skip to main content
Version: 1.0-beta

Generating code

dagger generate

Runs every generator in your workspace. A generator doesn't write to your files directly — it returns a changeset: a diff of the proposed changes. Dagger shows you the changed paths and line counts, and nothing is written until you approve.

Functions can also return a changeset without being generators — a formatter's fix, called with dagger api call, is the common case. Checks never do; they only validate.

List generators​

dagger generate -l
MODULE    GO-PACKAGE  GENERATOR  DESCRIPTION
dang-sdk generate re-generate modules and clients managed by the Dang SDK
go * generate Run go generate in this package.
# Use --all to expand collections and list each item.

A * stands for every item in a collection, such as every Go package. Use --all to list one row per item.

Filter generators​

dagger generate 'dag://protobuf/*'         # all generators from a module
dagger generate dag://changelog/generate # a single generator
dagger generate --go-package=version # one Go package

Generators accept the same module and collection filters as checks, and --generator=NAME selects generators by name. See Filter checks.

Apply without prompting​

Pass -y / --auto-apply to skip the review step — useful in scripts and non-interactive sessions:

dagger generate -y

Coding agents​

When Dagger detects that a coding agent is running dagger generate, it requires an explicit choice up front. Pass -y to apply the result, or --no-apply to run the generators and show the changes without writing them:

dagger generate --no-apply

--no-apply exits successfully even when there are pending changes, just like choosing Discard at the interactive prompt. Generators still run and may perform other work; only the changeset is withheld.

Verify in CI​

In CI you usually want to check that committed files are up to date rather than rewrite them. dagger check runs each generator as a read-only check and fails, without applying anything, if its output differs from what's committed:

# GitHub Actions
- run: dagger check --generated=true

A failing generator check means the committed output is stale — run dagger generate locally, apply the changeset, and commit.