Getting Started with moth

moth compiles and tools Moth projects. You use it from the command line to create projects, check them, build them and run the hot-reloading dev server.

If you are running the compiler from the repository instead of an installed moth binary, use cargo run -- before the same commands:

cargo run -- dev .
cargo run -- check .
cargo run -- build .

Commands

Command Use Notes

help

Prints the current command list and supported flags. Use this to find command-specific options.

--version

Prints the current compiler/tool version.

-v and -V are also accepted.

new html

Creates an HTML project.

Accepts an optional path and --force. Creates @config.moth, @entry.moth and optionally .gitignore. The project and HTML settings are top-level compile-time constants.

check .

Runs project discovery, frontend compilation, type checking, HIR lowering and borrow validation without writing build artifacts.

Add --terse for compact one-line diagnostics.

dev .

Builds the project, starts a local dev server, watches files and reloads the browser when sources change. This is the main day-to-day command for working on HTML projects.

build .

Builds the project and writes output files.

Without --release, directory projects write to the configured dev output folder. With --release, they write to the configured release output folder.

tests

Runs the compiler integration test suite. (developer tool)

Mainly useful when working on the compiler itself. Use --terse for compact output or --backend html / --backend html_wasm to focus one backend profile.

Flags

Flag Applies to Effect

--release

build, dev

Selects the release build profile and release output folder where supported.

--html-wasm

HTML builds Selects the HTML-Wasm backend for an HTML build.

--terse

check, tests

Prints compact diagnostics or test summaries for tools, logs and LLM workflows.

--force

new html only

Allows replacing existing scaffold-owned files after a confirmation warning. Never overwrites .gitignore or unrelated files.

--host, --port, --poll-interval-ms

dev only

Configures the local dev server. Defaults are `127.0.0.1`, `6342` and `300`.

Create a new HTML project

An HTML project keeps settings in @config.moth and executable page content in @entry.moth. The first build creates output folders and manifests. See Project structure for routing, assets and output rules.

Starter shape

Project and builder settings are ordinary top-level compile-time constants. The project and html records are optional:

project #= (
    name = "my_site",
)
html #= ()

The selected directory is the source root. To supply a version, add it to the project record or pass a configurable value through the $config input marker.

@entry.moth supplies HTML metadata with direct const builder slots. An empty or metadata-only entry still produces a page:

[$in title:Welcome]

A directory with @entry.moth is entry-eligible, including when the file is empty.

Start a new project:

moth new html
moth new html my-site
moth new html ~/projects/my-site

If you omit the path, moth asks for confirmation in the current directory:

No project path specified. Current directory: /your/path
Create the new HTML project in this directory? y/N:

If the target directory already exists, you are given three choices:

Target directory already exists:
/path/to/target

What do you want to do?
  1. Create the project inside this directory
  2. Create a new child folder for the project inside this directory
  3. Cancel

Choose 1/2/3:

If the path contains directories that do not exist, moth asks before creating them:

The project target contains directories that do not exist:
/path/to/new/site

Create the missing directories and scaffold the project there? y/N:

After the final directory is chosen, moth asks for the project name:

Project name (press Enter to use project directory name):

Then it asks whether to add a .gitignore with Moth defaults:

Add a .gitignore with Moth defaults? Y/n:

If .gitignore already exists, moth asks whether to append missing defaults instead of overwriting.

Generated project structure

A project after its first build looks like this:

project-root/
├── @config.moth
├── @entry.moth
├── _dev/
│   └── .moth_manifest
├── _release/
│   └── .moth_manifest
└── .gitignore

Using --force

--force allows replacing scaffold-owned files when they already exist:

moth new html my-site --force

It still asks for a second confirmation and never overwrites .gitignore or unrelated files.

After creation, check and run the project:

cd my-site
moth check .
moth dev .

Run the dev server

dev handles normal day-to-day Moth project work. It builds the project, serves the generated files locally, watches for source changes and sends reload events to the browser.

moth dev .

By default, open:

http://127.0.0.1:6342/

Useful dev-server options:

moth dev . --port 8080
moth dev . --host 0.0.0.0
moth dev . --poll-interval-ms 100

When a build fails, fix the reported error and save again. The dev server is designed around fast feedback rather than a manual rebuild loop.

Build a project

Use build when you want files written to disk without running the dev server.

moth build .

For a release build:

moth build . --release

For HTML projects, generated files are written under the configured output folder. The default scaffold uses _dev for development output and _release for release output.

Check without building

check gives the fastest correctness signal for editor loops and CI-style validation. It doesn't write output artifacts, but it runs the shared frontend diagnostics that all backends use.

moth check .

Use terse mode when another tool will read the output:

moth check . --terse

Terse diagnostics have a stable compact shape:

E|type|@entry.moth|4:12|Expected Bool, found I32|help=Use a Bool expression here.
W|identifier_naming_convention|button.moth|1:1|Dependency alias case mismatch

Reading compiler errors

Moth uses the same formatted diagnostic system across the compiler front end and backend builders. That means syntax errors, type errors, config errors, file errors, borrow-checker errors, dev-server errors and backend errors use the same basic shape.

A normal diagnostic contains:

Example shape:

Type Error (ಠ_ಠ) 🔥
Declaration 'count' has incompatible initializer type. Expected 'I32', but found 'String'.

  --> @entry.moth:6:17
    |
  6 | count I32 = "wrong"
    |             ^^^^^^^
  Use an I32 value here, or change the declaration type.

Read diagnostics from top to bottom:

  1. The kind tells you which part of the compiler rejected the program.
  2. The message tells you the actual rule that failed.
  3. The file/line/column points to the primary source location.
  4. The caret shows the token or expression the compiler is complaining about.
  5. The guidance lines are suggestions, not a separate error.

Error kinds

Kind Meaning Usual fix
Syntax Error The source text could not be parsed as Moth syntax. Check punctuation, block delimiters, template brackets, dependency clauses and declaration shape.
Type Error The expression type does not match the expected type. Check annotations, return types, function arguments, collection element types and contextual casts.
Language Rule Error The syntax is valid, but it violates a language rule. Check things like mutability, binding visibility, unsupported feature surfaces, duplicate names or invalid top-level code.
Missing File or Directory The project references a file, directory, dependency path or output path that cannot be resolved. Check spelling, relative paths, the selected project directory and project config.
Malformed Config The project config exists but contains unsupported, missing or invalid settings. Check `@config.moth` and backend-specific config rules.
Borrow Checker Violation The program violates Moth's access and ownership rules. Check mutable/exclusive access, later uses after possible moves and overlapping borrows.
Dev Server Issue The local server could not start, watch, build or serve the project correctly. Check port conflicts, host binding, project path, and file permissions.
Compiler Bug / HIR / LIR / WASM Generation Bug The compiler hit an internal invariant or unsupported backend path. Reduce the input if practical and report it. User code should receive structured errors instead of compiler bugs.

Warnings

Warnings identify source that can compile but deserves attention, such as naming mismatches and malformed HTML or CSS template content. Use moth check . to review them without writing build output.