# Configure Sonjoo CLI audits

> Create and validate sonjoo.toml, resolve configuration precedence, and control crawl scope, rule gates, and report output.

Canonical documentation: <https://sajaddehshiri.ir/sonjoo-seo-audit/cli/configuration/>

Use `sonjoo.toml` for settings you want to share and review with the project. Run `sonjoo config show` from the same working directory as your audit to see the effective configuration.

## How does Sonjoo choose a configuration?

For CLI commands that load configuration, later sources override earlier ones.

1. Built-in defaults.
2. User settings at `$SONJOO_HOME/settings.json`, or `~/.sonjoo/settings.json` by default. Sonjoo resolves that default from `HOME`, then `USERPROFILE`.
3. The nearest `sonjoo.toml` found upward from the working directory, stopping at `HOME` if reached, or the file explicitly supplied with `--config`.
4. Working-directory overrides at `.sonjoo/settings.json`.
5. Supported command-line flags for the current invocation.

Use `SONJOO_HOME` to isolate user settings, saved audit history, cache, and dashboard runtime state. An explicitly named TOML file changes step 3. Working-directory overrides and supported flags still take precedence. The local dashboard and HTTP API use built-in project settings and the run options you submit. The CLI and MCP can load project files.

## Create and validate a project configuration

Run `sonjoo init --yes` in a new project or write a configuration in an empty directory. This example limits newly discovered crawl URLs to paths under `/docs/` and requires the title rule in CI. Start the crawl at `/docs/` to include only that section from the first page.


```sh
cat > sonjoo.toml <<'TOML'
[project]
name = "Documentation checks"

[crawler]
max_pages = 25
concurrency = 2
timeout_ms = 10000
include = ["/docs/**"]
respect_robots = true

[rules.override]
core-title-present = { fail_ci = true }

[output]
format = "json"
path = "reports/audit.json"
save = false

[ci]
fail_under = 75
min_coverage = 90
TOML

sonjoo config validate --json --config ./sonjoo.toml
sonjoo config show --json --config ./sonjoo.toml
```

Change the include pattern to match the URL paths you want to inspect. `timeout_ms` is in milliseconds and `max_duration_s` is in seconds. The `ci` initialization preset disables robots compliance, so review the generated crawler settings before targeting a live site. The example above explicitly keeps robots compliance enabled.

## Set user or project overrides

Use `--local` for the working directory or `--global` for settings in the Sonjoo home directory.

```sh
sonjoo config crawler.concurrency 2 --local
sonjoo config show --json
```

To diagnose an unexpected setting, check your working directory, the selected TOML file, the local JSON overrides, and the command flags. See [CI gates](https://sajaddehshiri.ir/sonjoo-seo-audit/guides/ci-gates/) to choose thresholds and [exports](https://sajaddehshiri.ir/sonjoo-seo-audit/cli/exports/) for format and path precedence.

## Look up crawler, link and output settings

Run `sonjoo config show --json` from an empty project with an empty `SONJOO_HOME` to inspect the installed binary's defaults. Run `sonjoo config validate --config ./sonjoo.toml` to validate the effective settings with your project and local overrides.

| Setting                                                                       | Built-in value                                                             | What it controls                                                                                                                                                                         |
| ----------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `project.name`, `project.domains`                                             | Empty                                                                      | Optional project label and domain list. Use `crawler.include` and `crawler.exclude` to constrain discovery.                                                                              |
| `crawler.max_pages`                                                           | `10`                                                                       | Linked-page budget. TOML accepts 1–10,000. The `audit --max-pages` flag accepts 1–1,000, and the `crawl --max-pages` flag accepts 1–10,000.                                              |
| `crawler.concurrency`, `crawler.per_host_concurrency`                         | `3`, `2`                                                                   | Global and per-host crawl concurrency limits. Accepted ranges are 1–20 and 1–5.                                                                                                          |
| `crawler.delay_ms`, `crawler.per_host_delay_ms`                               | `100`, `200`                                                               | Global and per-host crawl pacing in milliseconds. Each accepts 0–60,000.                                                                                                                 |
| `crawler.timeout_ms`                                                          | `30000`                                                                    | Request timeout in milliseconds. TOML accepts 1,000–300,000. The `audit --timeout` flag accepts 1,000–120,000.                                                                           |
| `crawler.max_duration_s`                                                      | `0`                                                                        | Enables a collection time budget when positive for `audit --crawl` or `crawl`. Set whole seconds up to 86,400. `0` leaves the CLI crawl unbounded by time. MCP applies its own fallback. |
| `crawler.max_retry_after_ms`                                                  | `120000`                                                                   | Maximum accepted `Retry-After` wait for the crawl, in milliseconds. Accepted range is 0–600,000.                                                                                         |
| `crawler.include`, `crawler.exclude`                                          | Empty lists                                                                | Match newly discovered paths. An exclusion wins when both match.                                                                                                                         |
| `crawler.allow_query_params`, `crawler.drop_query_prefixes`                   | Empty allowlist, tracking prefixes `utm_`, `gclid`, `fbclid`, `mc_`, `_ga` | Choose which query parameters are retained during crawl URL normalization. An explicit allowlist takes precedence.                                                                       |
| `crawler.respect_robots`, `crawler.respect_crawl_delay`, `crawler.user_agent` | `true`, `true`, empty string                                               | Respect site directives and use Sonjoo's default crawler identity unless you supply one.                                                                                                 |
| `external_links.enabled`, `external_links.cache_ttl_days`                     | `true`, `7`                                                                | Enable external link verification and set its cache lifetime. The TTL accepts 0–365 days.                                                                                                |
| `external_links.timeout_ms`, `external_links.concurrency`                     | `10000`, `5`                                                               | External-link probe timeout (1,000–60,000 ms) and concurrency (1–20).                                                                                                                    |
| `output.format`, `output.path`, `output.save`                                 | `console`, empty path, `true`                                              | Choose output type, optional path, and history persistence. See [export precedence](https://sajaddehshiri.ir/sonjoo-seo-audit/cli/exports/#write-an-html-report).                        |
| `ci.fail_under`, `ci.min_coverage`                                            | `70`, `0`                                                                  | Set score and measured crawl coverage thresholds. Each accepts 0–100.                                                                                                                    |

See [crawl path and query rules](https://sajaddehshiri.ir/sonjoo-seo-audit/features/crawling/#control-link-discovery-and-url-scope) for examples.

## Select and configure audit rules

All rules are eligible by default (`rules.enable = ["*"]`). Narrow `rules.enable` or `rules.disable` using rule IDs or patterns such as `links-*`. Disable takes precedence. Under `[rules.override]`, set a rule's `priority` to `high`, `normal`, `low`, or `ignore` for reporting, or set `fail_ci = true` for a required result. Priority does not change a rule's measured outcome or score.

Under `[rule_options."<rule-id>"]`, set options supported by the selected rule. `sonjoo explain <rule-id> --json` shows option names, defaults, and validation bounds. The [catalog](https://sajaddehshiri.ir/sonjoo-seo-audit/features/rules/) explains what each check measures. Add project-specific searches and extractions in [`[custom]`](https://sajaddehshiri.ir/sonjoo-seo-audit/features/ai-search-extraction/#custom-search-and-extraction).
