---
title: "Agent workflows"
description: "How a coding agent finds keys by their text, finds missing keys, adds and translates messages, and checks its work with the x18n CLI."
canonical_url: "https://x18n.dev/agents/workflows"
---
# Agent workflows

> How a coding agent finds keys by their text, finds missing keys, adds and translates messages, and checks its work with the x18n CLI.

Coding agents are first-class users of x18n. An agent uses the same CLI as a human, with `--json`. It never edits locale files by hand, and it checks its own work with `x18n check`.

An agent can work with x18n in three ways:

- The CLI with `--json`. Every command prints the [JSON contract](https://x18n.dev/references/json-contracts).
- The [MCP server](https://x18n.dev/agents/mcp), with tools for the same tasks.
- The [shipped skills](https://x18n.dev/agents/skill), which teach an agent to set up x18n, fix what `x18n check` reports, and run the loops on this page.

## Rules for agents

- Do not edit locale files directly. Use `x18n set`, `x18n apply`, `x18n rename` and `x18n delete`. They keep the format, the key style, the order and the placeholders of each file.
- Before you use a key in code, find out whether it exists: `x18n get <key> --json`. To reuse a key with the same text, search the values: `x18n search "<text>" --json`.
- Keep every placeholder of the source value, such as `{name}`, `{{count}}`, `%s` or `@:key`.
- Read the JSON output, not the human output.
- For renames and deletes, run with `--dry-run` first and read the plan.

## The JSON output

Every command prints one document with the same envelope:

```json
{
  "x18n": 2,
  "command": "keys",
  "data": {},
  "diagnostics": [],
  "errors": []
}
```

`data` holds the result. `errors` holds the errors, each with its code in `name`, the reason in `why`, a `fix` and a `docs` link. The exit code tells the agent what to do next:

| Exit code | Meaning                                                     | Next step                                      |
| --------- | ----------------------------------------------------------- | ---------------------------------------------- |
| `0`       | Success.                                                    | Continue.                                      |
| `1`       | `x18n check` found errors, or `x18n apply` rejected values. | Fix the reported keys.                         |
| `2`       | Usage or config error.                                      | Read `errors`.                                 |
| `3`       | A decision is needed.                                       | Run again with `--yes` to accept the defaults. |
| `4`       | Files changed during the command.                           | Run it again.                                  |

## Check the project

```sh
x18n status --json
x18n check --json
```

`x18n status` lists the projects, the locales with their coverage and the counts of diagnostics. `x18n check` lists every diagnostic.

## Find the key behind a text

A user often names a text that they see in the app, not a key. The agent searches the values:

```sh
x18n search "Sign in" --json
x18n search "Anmelden" --exact --json
```

The search covers every locale and ignores case. It is fuzzy by default, and values that contain the query rank first. `--exact` keeps only those values. Each match has the key, the matched locale and value, and the usages with file, line and column. The [MCP tool](https://x18n.dev/agents/mcp) `x18n_search` does the same.

## Add a key while coding

```sh
x18n search "Settings" --exact --json
x18n get settings.title --json
x18n set settings.title --value "Settings" --json
```

When `x18n search` finds a key with the same meaning, the agent reuses it. Without `--locale`, `x18n set` writes the source locale. Then use the key in code, for example `t('settings.title')`. To see which locales still lack keys, run `x18n keys --missing de --json --limit 50`.

## Translate missing messages

```sh
x18n prompt translate --to de --limit 50
```

The [translate prompt](https://x18n.dev/agents/prompts) lists the messages to translate, with rules and context. The agent writes the results as `{ "de": { "<key>": "<translation>" } }` to a file, then applies and checks them:

```sh
x18n apply translations.json --json
x18n check --only placeholder-mismatch,invalid-syntax --locale de --json
```

`x18n apply` refuses values whose placeholders differ from the source value, and lists them in `data.rejected`. The agent fixes them and applies again. If the prompt says that more keys remain, the agent continues with `--cursor <nextCursor>`.

## Review translations

```sh
x18n prompt review --locale de --limit 50
```

The review prompt asks the agent to compare existing translations with the source and the glossary. The agent does not change values itself. It leaves a [review](https://x18n.dev/guide/reviews) for a human: `x18n review suggest <key> --locale de --value <text> --text <why>` for a better value, or `x18n review request-change <key> --locale de --text <why>` for a problem without a clear fix. A human then applies or resolves each one, in the editor, the UI or with `x18n review apply-suggestion <id>`. With `review.enabled: false`, the agent fixes values with `x18n set` instead.

## Clean up

```sh
x18n keys --unused --json
x18n delete old.key --dry-run --json
x18n delete old.key --json
```

A key with a [prefix usage](https://x18n.dev/guide/concepts#prefix-usage) is not unused, so `x18n keys --unused` does not list keys that computed keys can reach.

To delete all unused keys at once, show the user the plan first, and run it only when they confirm:

```sh
x18n delete --unused --dry-run --json
x18n delete --unused --json
```

`data.deleted` lists each key with its locales and files. `data.kept` lists unused keys that a computed key in a scope may reach, with those usages; they stay. `data.warnings` names computed keys outside any scope, which may reach any key.

## Rename keys

```sh
x18n rename home.title home.heading --dry-run --json
x18n rename home.title home.heading --json
x18n rename pages screens --json
```

A rename changes every locale and every usage in code. A rename of a parent key, such as `pages`, moves every key under it. A rename to a key that exists stops with exit code 1.

## Extract hard-coded strings

```sh
x18n extract --list --json
x18n extract --plan extract-plan.json
```

Before applying the plan, read and edit `extract-plan.json`:

1. Remove items you do not want to extract.
2. If you change `key`, also update the corresponding message reference in `replacement`. `key` names the resource message. `replacement` is the code to insert. Applying the plan does not regenerate replacement code from the key.
3. Keep the other fields and unrelated expressions. Preserve the quotes, escaping and namespace syntax that the template requires.

For example, changing `key` from `welcomeAboard` to `page.welcome` also requires changing `{{ $t('welcomeAboard') }}` to `{{ $t('page.welcome') }}`.

Preview the changes:

```sh
x18n extract --apply extract-plan.json --dry-run --json
```

Inspect both the resource edits and the source-code edits. Make sure that each edited message reference points to the intended resource key. Make sure that the replacement code preserves unrelated expressions and has valid syntax. A successful dry-run does not establish these conditions.

After this review, apply the plan:

```sh
x18n extract --apply extract-plan.json --json
```

## Large projects

List commands take `--limit` and return `nextCursor`. Pass it as `--cursor` to get the next page. This keeps the output of a large project small enough for the context of an agent:

```sh
x18n keys --json --limit 100
x18n keys --json --limit 100 --cursor 100
```

In a monorepo, `x18n status --json` lists several projects. Pass `--project <name>` to commands that write files.


## Sitemap

See the full [sitemap](https://x18n.dev/sitemap.md) for all pages.
