How air-verse/air works
Purpose and Runtime
Air is a Go CLI for development-time live reload of Go applications. It watches a project tree, rebuilds on relevant changes, terminates/restarts the configured executable, and can optionally proxy HTTP traffic to inject browser reload support. It is not a production deployment system.
The primary binary entry point is main.go; release version metadata is in version.go. The main runtime is Go 1.25+ and is designed to run on Linux, macOS, and Windows.
CLI Bootstrap and Configuration
CLI parsing, command modes (air, air init), configuration selection, and argument forwarding are centered in:
• main.go
• runner/flag.go
• runner/config.go
Configuration is normally loaded from .air.toml in the target working directory or an explicit -c path. CLI flags can override config fields, including nested build settings. Config defines watch filters, build commands, executable entrypoint/arguments, environment files, platform-specific build settings, logging, and proxy behavior.
Runner Orchestration Engine
runner/engine.go is the central control plane: it initializes configured services, starts watching, coordinates initial and subsequent builds, and owns rebuild/restart lifecycle decisions.
• runner/engine.go
• runner/common.go
• runner/exiter.go
The engine forms the principal boundary between filesystem events and process lifecycle: events are filtered/debounced into rebuild requests; builds either leave the existing application intact on failure or replace it after successful output.
Filesystem Watch Pipeline
Watch registration and event handling are encapsulated by:
• runner/watcher.go
• runner/util.go
• runner/util_linux.go
The watcher recursively observes configured directories and handles new directories appearing after startup. It applies inclusion/exclusion rules from configuration (directories, extensions, named files), suppresses irrelevant/generated paths, and sends meaningful changes toward the engine rather than directly invoking builds. OS-specific utility files support platform differences, with corresponding Unix and Windows implementations in runner/util_unix.go and runner/util_windows.go.
Build and Managed Application Process
Build execution is configured rather than hardcoded: pre-build commands, the main build command, post-build commands, environment-file loading, and OS-specific overrides establish the artifact. The configured entrypoint then resolves to an executable plus default/configured/CLI-supplied arguments.
Process and command concerns are concentrated in:
• runner/engine.go
• runner/cmdarg_test.go (behavioral contract)
• runner/util_windows.go
Air manages child-process termination and restart, including platform-specific process handling. This is a strong isolation boundary: the watched project’s compiler and executable are external subprocesses, while Air only supervises their invocation and I/O.
Optional Development Proxy and Browser Reload
An optional proxy sits between a browser and the watched application:
• runner/proxy.go
• runner/proxy_stream.go
• runner/proxy.js
When enabled, Air listens on a proxy port, forwards traffic to the application port, and can alter suitable HTML responses to support reload behavior after static-file changes. Stream handling preserves proxying for response types that should not be buffered or transformed. Browser-side behavior is carried by the embedded JavaScript assets runner/proxy.js and runner/worker.js.
Packaging, Container Use, and Delivery
The project ships as a Go binary and supports containerized development:
• Dockerfile
• .goreleaser.yml
• .github/workflows/release.yml
Dockerfile provides a runnable image context; mounted source trees are expected for live reload. GoReleaser and GitHub Actions produce release artifacts. Smoke tests exercise rebuild behavior through a separate sample Go application under smoke_test/check_rebuild/, validating the end-to-end watch → build → restart path.
Main entry points: engine.go Runner engine · main.go Air CLI · proxy.go Development proxy · watcher.go Filesystem watcher
Components 17
CLI & Config
- Air CLI · Selects command mode and starts the runner.
main.go - Version metadata
version.go - Flag parsing · Parses Air commands and forwards application arguments.
runner/flag.go - Config loading · Loads .air.toml or an explicit config path and applies overrides.
runner/config.go
Reload Runtime
- Runner engine · Coordinates watch events, builds, and application replacement.
runner/engine.go - Lifecycle control · Owns shutdown and common runner behavior.
runner/exiter.go - Filesystem watcher · Recursively observes configured project directories and filters changes.
runner/watcher.go - Platform utilities · Supports watch and process differences across operating systems.
runner/util.go - Configured build · Runs pre-build, build, and post-build commands with configured environment.
runner/engine.go - Managed application · Configured executable restarted only after successful builds.
Optional Proxy
- Development proxy · Forwards browser traffic and injects reload support into suitable HTML.
runner/proxy.go - Streaming proxy path · Preserves response streaming when content should not be transformed.
runner/proxy_stream.go - Browser reload assets · Client and worker code used for browser reload behavior.
runner/proxy.js
Delivery
- Container image · Provides a runnable Air image for mounted development source trees.
Dockerfile - Release pipeline · GitHub Actions and GoReleaser produce distributable binaries.
.github/workflows/release.yml - GoReleaser config
.goreleaser.yml
Other components
- Watched project tree · Application source and static files mounted or selected as the watch target.
Connections 20
- Air CLI → Version metadata: reports version
- Air CLI → Flag parsing: parses CLI
- Flag parsing → Config loading: selects and overrides
- Config loading → Runner engine: configures
- Air CLI → Runner engine: starts
- Runner engine → Filesystem watcher: registers watches
- Watched project tree → Filesystem watcher: file changes
- Filesystem watcher → Platform utilities: uses OS support
- Filesystem watcher → Runner engine: filtered rebuild requests
- Runner engine → Configured build: runs on relevant change
- Configured build → Managed application: successful artifact replaces
- Runner engine → Managed application: terminates and restarts
- Runner engine → Lifecycle control: uses shutdown control
- Runner engine → Development proxy: starts when enabled
- Development proxy → Managed application: forwards requests
- Development proxy → Streaming proxy path: routes streaming responses
- Development proxy → Browser reload assets: injects reload client
- Container image → Air CLI: packages
- Release pipeline → GoReleaser config: runs
- GoReleaser config → Air CLI: builds releases