# Shared flags

Every command built on readerly accepts the same reader flags. `readerFlags(argv)` in [`src/flags.ts`](https://github.com/loadsheet/readerly/blob/main/src/flags.ts) scans for them, and `createOut` calls it with the `argv` you pass.

| Flag | What it changes |
| --- | --- |
| `--format <name>` | The [format](https://readerly.loadsheet.dev/guide/formats): `text`, `agent`, `json`, `jsonl`, or one the tool adds. An unknown name is a usage failure, exit code 2. |
| `--json` | The same as `--format json`. `--format` wins when both are given. |
| `--full` | Turns the agent [budget](https://readerly.loadsheet.dev/guide/budget) and the terminal's row cap off. Adds each diagnostic's `why` and `docs` in `agent`, and a `see:` branch with its `docs` in `text`. |
| `--max-chars <n>` | Sets the budget to `n` characters. `n` must be a positive integer, or the run is a usage failure. `--full` wins over it. |
| `--color`, `--no-color` | Turns color on or off in `text`. The last one given wins. See [Color](https://readerly.loadsheet.dev/guide/color). |
| `--no-input`, `--non-interactive` | Turns prompts off. A prompt with a default uses it, and one without fails with `action_required`. |
| `--yes`, `-y` | Answers yes to an `out.confirm` that no flag, `--input` or env value answered, except one that asks for a typed name. |
| `--verbose` | Prints the profile's reasons and `out.debug()` lines on stderr. |
| `--quiet` | In `text`, drops `out.log()` lines, info rows and the progress line. The verdict still counts the infos. |
| `--input <json\|@file\|@->` | Passes answers to prompts as a JSON object, a file, or stdin. See [Prompts and input](https://readerly.loadsheet.dev/guide/prompts). |

`--verbose` and `--quiet` cancel each other, and the last one given wins. There is no `-v` or `-q`. `-v` usually means `--version`, so readerly leaves both to your tool.

## How the scan works

`readerFlags` never throws, and it doesn't change the array you pass. A flag that takes a value accepts `--format json` or `--format=json`. When the value is missing, or the next argument starts with `--`, the value is empty, and `resolveProfile` reports `--format needs a value.` or `--max-chars needs a value.`.

Everything else goes to `rest`, in order: positional arguments, your tool's own flags, `-v`. The scan stops at `--`, which goes to `rest` with every argument after it, so `acme lint -- --json` passes `--json` to your tool.

```ts [flags.ts]
import { readerFlags } from "readerly/profile";

readerFlags(["check", "--json", "src", "--fix", "--max-chars", "10"]);
// { json: true, maxChars: "10", rest: ["check", "src", "--fix"], full: false, … }
```

Hand `rest` to your argument parser. [Argument parsers](https://readerly.loadsheet.dev/integrations/argument-parsers) has examples with `node:util` `parseArgs`.

`createOut` also builds the rerun command from `rest`, such as `acme check src` in a `next:` or `hidden:` line. Reader flags never appear in it, and readerly adds `--full` or `--format json` where a line needs them.

## What the flags set in the profile

`resolveProfile()` in [`src/profile.ts`](https://github.com/loadsheet/readerly/blob/main/src/profile.ts) combines the flags with the environment and [detection](https://readerly.loadsheet.dev/guide/readers) into one `Profile`. `createOut` exposes it as `out.profile`.

| `Profile` field | Set by |
| --- | --- |
| `format` | `--format`, `--json`, `<TOOL>_FORMAT`, then detection |
| `color` | `--color`, `--no-color`, then the [color rule](https://readerly.loadsheet.dev/guide/color); always `false` in `agent`, `json` and `jsonl` |
| `interactive` | `true` only for the `terminal` reader on `text`, without `--no-input`, with stdin and stderr on a TTY |
| `budget` | `--full` (no limit), `--max-chars`, then 8,000 for the `agent` format or an agent reading `text`; no limit otherwise |
| `full` | `--full` |
| `yes` | `--yes`, `-y` |
| `verbosity` | `verbose`, `quiet` or `normal` |
| `annotations` | `"github"` for the `ci` reader on GitHub Actions with `text`; not set otherwise |
| `detection` | The `Detection` from `detect()`, or the one you passed |
| `why` | One reason each for `format`, `color`, `interactive` and `budget` |

## Seeing why with `--verbose`

With `--verbose`, `createOut` writes `profile.why` to stderr once, the first time the command prints anything, one line per decision. A coding agent running `acme check --verbose` gets this on stderr:

```text
format: agent (detected agent (AI_AGENT))
color: false (format agent)
interactive: false (reader is agent)
budget: 8000 (format agent)
```

The same run with `--json` in a pipe:

```text
format: json (--json)
color: false (format json)
interactive: false (reader is pipe)
budget: Infinity (no budget for pipe on json)
```

When a command prints something different from what you expected, run it with `--verbose` first. Each line names the flag, variable or detection result that decided it.

<!-- vitehub-docs:section-links -->
## In this section

- [Introduction](https://readerly.loadsheet.dev/raw/guide.md)
- [Installation](https://readerly.loadsheet.dev/raw/guide/installation.md)
- [Readers](https://readerly.loadsheet.dev/raw/guide/readers.md)
- [Coding agents](https://readerly.loadsheet.dev/raw/guide/agents.md)
- [Formats](https://readerly.loadsheet.dev/raw/guide/formats.md)
- [Shared flags](https://readerly.loadsheet.dev/raw/guide/flags.md) (this page)
- [Color and glyphs](https://readerly.loadsheet.dev/raw/guide/color.md)
- [Diagnostics](https://readerly.loadsheet.dev/raw/guide/diagnostics.md)
- [Budget](https://readerly.loadsheet.dev/raw/guide/budget.md)
- [Prompts and input](https://readerly.loadsheet.dev/raw/guide/prompts.md)
- [Failures and exit codes](https://readerly.loadsheet.dev/raw/guide/failures.md)
- [JSON and JSONL](https://readerly.loadsheet.dev/raw/guide/json.md)
- [Custom renderers](https://readerly.loadsheet.dev/raw/guide/renderers.md)
- [API](https://readerly.loadsheet.dev/raw/guide/api.md)

Next: [Color and glyphs](https://readerly.loadsheet.dev/raw/guide/color.md)

All pages: [llms.txt](https://readerly.loadsheet.dev/llms.txt)
