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 cstPrint the CST of a PHP file.
mago fixApply fixes from all four tools until no more changes are possible.
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 inspect-baselineSummarise and visualise a baseline file.
mago list-filesList the files Mago will process.
mago generate-completionsPrint shell completion scripts.
mago self-updateReplace the installed binary with a newer release.
mago versionPrint Mago's version. Same as --version.

mago fix

mago fix [PATHS...] runs guard → analyzer → linter → formatter, then repeats that order until a full pass changes no files. Each tool reads the changes from the previous tool. Without paths, the command uses the configured source paths.

mago fix
mago fix src/ tests/ --potentially-unsafe
mago fix --no-analyze --no-guard

Only safe fixes run by default. The command respects each tool's configuration, excludes, inline suppressions, and baseline. Issues without an allowed fix do not stop the other tools or cause an endless loop.

FlagDescription
--potentially-unsafeAllow safe and potentially unsafe fixes.
--unsafeAllow all fixes. Review the changes carefully.
--no-guardSkip the guard.
--no-analyzeSkip the analyzer.
--no-lintSkip the linter.
--no-fmtSkip the formatter.
--ignore-baselineApply fixes to issues hidden by each tool's baseline too.
--fail-on-remainingExit with code 1 if issues remain after fixes settle.
--max-passes <NUMBER>Limit full passes; defaults to 10 and accepts 1 to 256.

By default, the command succeeds when no more fixes are available at the selected safety level, even if issues remain. Disabling all four tools does nothing and succeeds.

If fixes keep returning to an earlier file state, or reach the pass limit, the command stops with code 1 and reports the problem. It keeps the edits already made; review the rules and settings before trying again. File access and other tool errors stop the command too.

You can raise --max-passes up to 256. If fixes still do not settle after 256 passes, report a bug in Mago.

Exit codes

CodeMeaning
0Success. mago fix found no more allowed fixes.
1Issues need attention, or fixes did not settle.
2Tool error: configuration, I/O, etc.

↳ Edit this page →