> ## Documentation Index
> Fetch the complete documentation index at: https://glua.bluejutzu.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Command Line Interface

> Lint and format Garry's Mod Lua outside the editor with the glua CLI, using the same analysis as the language server so CI and your editor agree.

The `glua` command runs the same parser, analyser and formatter as the extension,
so a finding in CI is the same finding you saw in the editor. Use it to gate pull
requests, run a pre-commit hook, or format a whole addon in one go.

## Installing

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-macchiato"}}
pnpm add -D glua-cli
```

Or build it from the repository:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-macchiato"}}
git clone https://github.com/Bluejutzu/glua-lsp
cd glua-lsp
pnpm install
pnpm run build
node packages/glua-cli/dist/glua.js --help
```

## `glua lint`

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-macchiato"}}
glua lint lua/
glua lint lua/autorun/server/sv_main.lua
glua lint . --quiet --max-warnings 0
```

| Flag                    | Description                                      |
| ----------------------- | ------------------------------------------------ |
| `-f, --format <format>` | `pretty` (default), `compact`, `github`, `json`  |
| `--root <dir>`          | Project root for config files and relative paths |
| `--max-warnings <n>`    | Exit non-zero above this many warnings           |
| `-q, --quiet`           | Only report errors                               |

Exits `1` when there are errors, or when `--max-warnings` is exceeded. Otherwise `0`.

<Note>
  The whole project gets indexed even when you lint a single file. Cross-file rules — an unhandled net message, a duplicate hook identifier, a missing `AddCSLuaFile` — are only correct once the index has seen everything.
</Note>

### Output formats

<CodeGroup>
  ```text pretty theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-macchiato"}}
  lua/autorun/sh_mistakes.lua
    9:11   info     'PlayerSpawned' is not a documented gamemode hook…  unknown-hook
    41:9   error    Compound assignment '+=' is not valid Lua.          compound-assignment

  Summary
  ───────────────────

    1 error  •  5 warnings  in 5 files
  ```

  ```text compact theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-macchiato"}}
  lua/autorun/sh_mistakes.lua:41:9: error: Compound assignment '+=' is not valid Lua. [compound-assignment]
  ```

  ```text github theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-macchiato"}}
  ::error file=lua/autorun/sh_mistakes.lua,line=41,col=9,title=glua(compound-assignment)::Compound assignment '+=' is not valid Lua.
  ```

  ```json json theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-macchiato"}}
  [
    {
      "file": "lua/autorun/sh_mistakes.lua",
      "line": 41,
      "column": 9,
      "severity": "error",
      "code": "compound-assignment",
      "message": "Compound assignment '+=' is not valid Lua."
    }
  ]
  ```
</CodeGroup>

## `glua fmt`

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-macchiato"}}
glua fmt lua/            # report what would change
glua fmt lua/ --write    # apply it
glua fmt lua/ --check    # verify, for CI
```

| Flag           | Description                                           |
| -------------- | ----------------------------------------------------- |
| `-w, --write`  | Rewrite files in place                                |
| `-c, --check`  | Exit non-zero if anything would change, write nothing |
| `--root <dir>` | Project root for config files                         |

<Warning>
  Files that do not parse are skipped and reported, never rewritten. Formatting broken code is how one problem becomes two.
</Warning>

## `glua rules`

Lists every diagnostic code alongside its settings key. Worth knowing because
the two are different: `net-payload-mismatch` is what you suppress inline,
`netReadWriteMismatch` is what you set in `.glua.json`.

## Configuration

The CLI reads exactly the same files as the editor — `.glua.json`,
`.gluafmtrc.json`, `.editorconfig`, `.prettierrc` — resolved from `--root` or the
working directory. See [Configuration](/configuration/overview).

## In GitHub Actions

The `github` format emits workflow annotations, so findings appear inline on the
pull request diff.

```yaml theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-macchiato"}}
name: Lint
on: [push, pull_request]

jobs:
  glua:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: pnpm/action-setup@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: pnpm
      - run: pnpm install --frozen-lockfile
      - run: pnpm exec glua lint lua/ --format github
      - run: pnpm exec glua fmt lua/ --check
```

## Colour

Honours [`NO_COLOR`](https://no-color.org) and turns itself off when piped.
`--no-color` disables it explicitly, `FORCE_COLOR=1` forces it on through a pipe.


## Related topics

- [GLua Language Server Commands](/reference/commands.md)
- [GLua Code Formatter](/features/formatter.md)
- [Get Started with GLua Language Server](/quickstart.md)
- [Committed Config Files for GLua](/configuration/config-files.md)
