All skills
Skillintermediate

The Four Codegen Types

> **Load when:** You need to understand what kind of codegen you're working on, or why similar code exists in multiple places.

Claude Code Knowledge Pack7/10/2026

Overview

The Four Codegen Types

Load when: You need to understand what kind of codegen you're working on, or why similar code exists in multiple places.

Quick Reference

TypeTriggerOutputKey File
In-Module Bindingsdagger developinternal/dagger/dagger.gen.gocore/sdk.go:93 (CodeGenerator)
Runtime DispatchModule startupdagger.gen.go (main pkg)modules.go:140 (moduleMainSrc)
SDK Librariesgo generatesdk/go/dagger.gen.gosdk/go/generate.go
Generated Clientsdagger client installdagger/dagger.gen.gocore/sdk.go:20 (ClientGenerator)

Type 1: In-Module Client Bindings

When: dagger develop or dagger call on a module

What: Generates client bindings so module code can call dag.Container(), dag.Directory(), dependency APIs.

Implementation: CodeGenerator interface at core/sdk.go:93

type CodeGenerator interface {
    Codegen(ctx, deps, introspection, pkgName) (*GeneratedState, error)
}

Type 2: Runtime Dispatch

When: Module starts up and needs to route incoming function calls

What: Generates invoke() function that dispatches calls to user implementations.

Key insight: SDKs differ here:

SDKApproachLocation
GoStatic generated switch/casecmd/codegen/generator/go/templates/modules.go:140
PythonDynamic introspectionsdk/python/src/dagger/mod/_module.py
TypeScriptHybrid AST + reflectionRuntime, no generated dispatch

Go example output:

func invoke(ctx context.Context, parentJSON []byte, parentName, fnName string, inputArgs map[string][]byte) (any, error) {
    switch parentName {
    case "MyModule":
        switch fnName {
        case "Build":
            // deserialize, call, return
        }
    }
}

Type 3: SDK Libraries

When: During Dagger development via go generate

What: Builds the shipped SDK packages (dagger.io/dagger Go package, dagger Python package, etc.)

Implementation: Same CodeGenerator interface, but:

  • No module context
  • No dependency handling
  • Different config paths

Entry point: sdk/go/generate.go runs cmd/codegen generate-library

Type 4: Generated Clients

When: dagger client install (experimental)

What: Like Type 1, but for regular programs outside module runtime.

Key difference: Includes Connect(), Close(), serveModuleDependencies().

Implementation: ClientGenerator interface at core/sdk.go:20

Supported: Go and TypeScript only.

See generated-clients.md for details.