Skip to content

CLI

Terminal window
go tool trpcgo generate [flags] [packages]

If no package patterns are supplied, the CLI analyzes ..

FlagDescription
-o, -outputWrite generated TypeScript router types to a file. Defaults to stdout.
-dirWorking directory for Go package resolution. Defaults to ..
-w, -watchWatch Go files and regenerate on changes.
-zodWrite generated Zod 4 schemas to a file.
-zod-miniGenerate schemas using zod/mini functional syntax.

Generate TypeScript router types:

Terminal window
go tool trpcgo generate -o web/gen/trpc.ts ./...

Generate TypeScript router types and Zod schemas:

Terminal window
go tool trpcgo generate -o web/gen/trpc.ts --zod web/gen/zod.ts ./...

Generate from another working directory:

Terminal window
go tool trpcgo generate -dir ./server -o ../web/gen/trpc.ts --zod ../web/gen/zod.ts ./...

Watch during development:

Terminal window
go tool trpcgo generate -o web/gen/trpc.ts --zod web/gen/zod.ts -w ./...

The static analyzer detects calls to trpcgo registration functions:

  • Query, VoidQuery, Mutation, VoidMutation, Subscribe, VoidSubscribe.
  • SubscribeWithFinal, VoidSubscribeWithFinal.
  • All Must* variants.

Procedure paths must be string literals.

trpcgo.MustQuery(router, "user.get", getUser) // detected
path := "user.get"
trpcgo.MustQuery(router, path, getUser) // not detected by static generation

The CLI creates output files with os.Create. Create parent directories first:

Terminal window
mkdir -p web/gen
go tool trpcgo generate -o web/gen/trpc.ts --zod web/gen/zod.ts ./...

Runtime dev generation creates missing parent directories automatically.

Watch mode runs generation once, then watches Go files under -dir recursively. It ignores common heavy directories such as .git, vendor, node_modules, testdata, dist, build, and coverage.

Only .go file create/write events trigger regeneration.