CLI and agents
For agents
One page to point a coding agent at: when to run the TolkBot CLI, the commands it runs, the rules it follows, and what every output and exit code means.
For what the CLI gives an agent, in short, see TolkBot for coding agents.
When to run it, and when not to
With automated pull requests on, an agent has nothing to do. It adds strings to the base locale file and pushes, and TolkBot opens a pull request with the translations.
Run the CLI when:
- The translations belong in the same pull request as the feature. Translate before committing, and the feature ships in every language at once.
- You want to check what an agent wrote.
tolkbot validatecatches a dropped placeholder or a broken file, offline, before the commit.
The loop
After adding or changing strings in the base locale file, run these in the directory that holds tolkbot.json:
# What each language needs
npx tolkbot status
# Translate what is missing or changed, and write it into the locale files
npx tolkbot translate --all
# Check the files
npx tolkbot validate
Then commit the locale files with the rest of the change. None of the commands prompts without a terminal, and each prints JSON there, so an agent reads the result instead of parsing text.
translate waits for each language and writes it into its file before starting the next. It exits 0 when every language succeeded or was already up to date. validate exits 0 when it found no errors; its warnings, such as a language that is still missing keys, are in the report. See Commands for every option.
The rules
Never write a translation by hand when
translatecan.translateapplies the project's glossary, its learnings and its translation memory, and records each value so the next run knows it is up to date. A hand-written value has none of that.Correct a translation with
tolkbot set. It writes the value, checks its placeholders against the source, and records it as written by a person, so TolkBot keeps it until the source text changes.--learnsaves a learning, so later translations follow it:npx tolkbot set common.save --locale nb --value "Lagre" --learn "Lagre, not Spare: it stores a file"Never change a key a person holds. A key someone locked, or has an unsubmitted draft for in the dashboard, is theirs.
translateleaves it out on its own;tolkbot status --keyslists them underheldByPerson, and an agent leaves those alone too.
Instructions for your agent
Paste this into AGENTS.md or CLAUDE.md:
## Translations
TolkBot translates this project. Run its commands in the directory that holds `tolkbot.json`.
- Add new strings to the base locale file only. Never write the other locale files by hand.
- After changing strings, run `npx tolkbot status` and `npx tolkbot translate --all`, then `npx tolkbot validate` before committing.
- To correct a translation, run `npx tolkbot set <key> --locale <locale> --value "<text>" --learn "<why>"`. TolkBot keeps the value and learns from the note.
- Leave every key alone that `npx tolkbot status --keys` lists as held by a person.
- More: https://docs.tolkbot.ai/docs/for-agents
tolkbot init offers to write it for you at the end of setup. Without a terminal it writes it only when asked:
npx tolkbot init --agents-file
It goes into the nearest AGENTS.md, or CLAUDE.md where there is no AGENTS.md, or a new AGENTS.md at the repository root; pass a path to choose the file. The block sits between <!-- tolkbot:start --> and <!-- tolkbot:end -->, so running init again replaces it instead of adding a second copy.
Logging in
validate, telemetry and --help need no login and no network. Every other command talks to TolkBot and needs a token.
On your own machine, run tolkbot auth login once and every agent session there uses the token it stores. An agent can also start the login itself: without a terminal, tolkbot auth login prints the URL and a verification code as plain lines for the agent to pass to you.
In CI or a sandbox, set TOLKBOT_TOKEN to the contents of ~/.tolkbot/token from a machine where you logged in. That token is a session for you, not for a project: it lasts 30 days, and anything holding it can act as you in every organization you belong to. In its last 3 days every command prints a warning on stderr. If it leaks, tolkbot auth logout --all signs out every CLI session at once. See Installation and login.
Output contract
When stdin or stdout is not a terminal, nothing prompts and nothing waits for input. Each command takes its defaults (init behaves as if --yes was given), and every command that has --json prints JSON without being asked; --no-json prints text instead. The JSON each command prints is on Commands.
Under JSON, stdout holds the result and nothing else. Warnings, and anything a child process prints, go to stderr. A failure goes to stderr in one shape:
{
"error": {
"code": "not_authenticated",
"message": "Not logged in.",
"hint": "Run 'tolkbot auth login', or set $TOLKBOT_TOKEN for CI."
}
}
code is a stable string to branch on; codes are added, never renamed. hint says what to do, and is null when there is nothing to suggest. The exit code says which kind of failure it was:
| Exit | Meaning | Codes |
|---|---|---|
0 | Success | |
1 | The command ran and the result is a failure | failed, internal, no_config, project_not_found, repository_not_connected, no_translation_files, no_target_languages, not_found, job_not_found, job_not_finished, job_failed, job_cancelled, job_timed_out, nothing_to_apply, validation_failed, login_failed, repository_path_claimed, repository_path_in_use, key_not_found, placeholder_mismatch |
2 | Usage: an unknown or missing flag, or a choice to make that has no safe default | usage, unsupported_locale, ambiguous_project, ambiguous_term |
3 | Not logged in, or not allowed | not_authenticated, token_expired, token_rejected, signed_out, project_archived, admin_required |
4 | Billing | no_subscription, out_of_credits, payment_failed, project_limit_reached |
5 | Could not reach TolkBot | network |
Some commands report a result and a failure together. validate prints its report on stdout and exits 1 when it found an error; translate prints every language on stdout, then the failure on stderr, when a job failed. status --exit-code exits 1 when a language needs translating.
For the agent's tools
The whole documentation is also served as plain Markdown, for an agent that reads the web:
/llms.txtlists every page./llms-full.txtis every page in one file.