---
title: Codegen
description: Generate C, Rust, or TypeScript code from ABI YAML with thru abi codegen
source_url:
  html: https://thru.org/docs/cli-reference/abi-codegen/
  md: https://thru.org/docs/cli-reference/abi-codegen.md
---

# Codegen

Use `thru abi codegen` when you already have ABI YAML and want generated client-side or runtime-facing code, not an on-chain ABI account.

## Use This When

- you want generated C headers and helpers from ABI type definitions
- you want Rust or TypeScript types organized by package
- you have one or more ABI files plus imported dependencies on disk

Choose another ABI command when:

- you want to inspect type resolution or IR before generating code: [Analyze](https://thru.org/docs/cli-reference/abi-analyze.md)
- you want to publish an ABI on-chain: [Account](https://thru.org/docs/cli-reference/abi-account.md)
- you need a flattened or publish-ready YAML artifact instead of generated source: [Flatten](https://thru.org/docs/cli-reference/abi-flatten.md) or [Prep for Publish](https://thru.org/docs/cli-reference/abi-prep-for-publish.md)

## Syntax

```bash
thru abi codegen \
  --files <FILE>... \
  --language c|rust|typescript \
  [--include-dir <DIR>...] \
  [--output <DIR>] \
  [--verbose]
```

## Required Inputs

| Input | What it does |
| - | - |
| `—files <FILE>…` | One or more root ABI YAML files to load. |
| \`—language c | rust |
| `—include-dir <DIR>…` | Adds search roots for imported ABI files. |
| `—output <DIR>` | Output directory for generated code. Defaults to `generated`. |

## Output Shape

The generator resolves imports, groups types by package, and writes package directories underneath the output directory.

C

Emits package directories containing `types.h` and `functions.c`.

Rust

Emits package directories with `types.rs`, helper modules, and `mod.rs` scaffolding.

TypeScript

Emits package directories with `types.ts`.

| Language | Typical output |
| - | - |
| `c` | Package directories with `types.h` and `functions.c`. |
| `rust` | Package directories with `types.rs`, helper modules, and `mod.rs` scaffolding. |
| `typescript` | Package directories with `types.ts`. |

## Minimal Patterns

**C output:**

```bash
thru abi codegen \
  --files ./program.abi.yaml \
  --language c \
  --output ./generated/c
```

**Rust output with imports:**

```bash
thru abi codegen \
  --files ./program.abi.yaml \
  --include-dir ./abi \
  --language rust \
  --output ./generated/rust
```

**TypeScript output:**

```bash
thru abi codegen \
  --files ./program.abi.yaml ./shared.abi.yaml \
  --include-dir ./abi \
  --language typescript \
  --output ./generated/ts
```

## Notes

- `--files` can be repeated so one run can generate code for multiple root packages.
- The command creates the output directory if it does not already exist.
- `--verbose` is useful when import resolution is the risky part of the task because it prints loaded files, packages, and output locations.
- Use [Analyze](https://thru.org/docs/cli-reference/abi-analyze.md) first if you want to inspect layout or validation helpers before you commit to generated output.
