Command-line interface

Every Mago invocation follows the pattern mago [GLOBAL OPTIONS] <SUBCOMMAND>. Global options must come before the subcommand.

mago --colors=never lint        # correct
mago lint --colors=never        # wrong, --colors is a global option

Global options

These options apply to every subcommand and control the runtime, configuration discovery, and output.

FlagDescription
--workspace <PATH>Workspace root. Defaults to the current directory.
--config <PATH>Path to the config file. Without it, Mago searches the workspace, $XDG_CONFIG_HOME, ~/.config, and ~. See discovery.
--php-version <VERSION>Override the configured PHP version, e.g. 8.2.
--threads <NUMBER>Override the thread count. Defaults to the number of logical CPUs.
--allow-unsupported-php-versionRun against a PHP version Mago does not officially support. Use with care.
--no-version-checkSilence the warning emitted on minor or patch drift from the project's pinned version. Major drift remains fatal. See version pinning.
--colors <WHEN>When to colour output: always, never, or auto (default).
-h, --helpPrint help and exit.
-V, --versionPrint the installed version and exit.

Environment variables

Most configuration overrides use the MAGO_* prefix and are documented on the environment variables page. The two you are most likely to set day-to-day are:

VariablePurpose
MAGO_LOGLog filter for tracing output. Values: trace, debug, info, warn, error.
MAGO_EDITOR_URLURL template for clickable file paths in terminal output. See editor integration.

Subcommands

The core tools:

CommandDescription
mago analyzeStatic analysis: type errors, logic bugs.
mago astPrint the AST of a PHP file.
mago formatFormat PHP files.
mago guardEnforce architectural rules and boundaries.
mago lintLint for style, correctness, and best practices.

Utility commands:

CommandDescription
mago configPrint the merged configuration or its JSON Schema.
mago initScaffold a starter mago.toml.
mago list-filesList the files Mago will process.
mago generate-completionsPrint shell completion scripts.
mago self-updateReplace the installed binary with a newer release.

Exit codes

CodeMeaning
0Success. No issues found.
1Issues found that need attention.
2Tool error: configuration, I/O, parse failure, etc.

↳ Edit this page →