CLI orchestration and repository workflows
The gt CLI is the local control point for sending project content to General Translation and bringing approved translations back into a repository. It joins project discovery, configuration, file and inline content collection, Git context, API work, local state, setup, and output cleanup into repeatable workflows. It can also collect source context for Paraglide JS messages and can run as a packaged executable for project-local integrations.
Command model
The CLI presents one command surface while adapting its work to the project that invokes it. This lets file translation and inline content translation use the same service and repository rules across JavaScript, Python, and Vue projects.
Command selection
The primary entry point selects a project adapter from the manifest and local project shape. The adapter supplies framework-aware scanning and setup behavior. Framework detection and library detection remain separate so a library used by an application does not change the application's setup model by itself.
The CLI also checks package version consistency in monorepos before workflows rely on project-local GT packages. It follows only the repository's declared workspace entries and reports conflicting declared versions for the enabled GT libraries. Related React packages are checked as a shared version group for newer package releases. Projects can skip this check with --skip-version-check or skipVersionCheck in gt.config.json.
The published gt package provides the executable and selected modules for integrations that need the same project and translation capabilities. The root command reports its package version with --version or -V, and accepts the hidden -v alias for scripts that use the short form. Dictionary bundling uses a portable WebAssembly path. Standalone binaries also load project package metadata so project-local packages such as the Paraglide JS compiler can resolve at run time.
The shared command surface covers project setup, configuration, authentication, translation, Git, direct API access, and project administration. Adapters add commands for project-specific extraction and translation operations.
References: packages/…/main.ts• L1-13 packages/…/index.ts• L11-48 packages/…/base.ts• L238-318 packages/…/version.ts• L1-19 packages/…/detectFramework.ts• L24-101 packages/…/index.ts• L121-169 packages/…/package.json• L1-109 packages/…/build-exe.sh• L17-24 packages/…/monorepoVersionCheck.ts• L52-150 packages/…/monorepoVersionCheck.ts• L203-245 packages/…/monorepoVersionCheck.ts• L399-433 packages/…/monorepoVersionCheck.test.ts• L183-239 packages/…/monorepoVersionCheckWorkspaces.test.ts• L59-98 packages/…/CHANGELOG.md• L14-19
Invocation lifecycle
Every workflow turns command flags and project configuration into one resolved settings object before it performs work. The settings object carries project identity, locales, file targets, branch policy, review and publish policy, parser choices, and API access.
The normal lifecycle moves from local discovery to remote work and then back to repository updates:
flowchart LR
A[CLI command] --> B[Resolve project and settings]
B --> C[Collect optional Paraglide context]
C --> D[Collect files and inline content]
D --> E[Resolve Git branch]
E --> F[Upload or query source versions]
F --> G[Prepare and enqueue work]
G --> H[Wait for completed translations]
H --> I[Download and merge files]
I --> J[Post-process and record state]
J --> K[Publish when configured]
stage records remote work for a later download. translate joins staging or enqueueing with waiting and downloading. download consumes staged or configured version data without starting new work. upload sends source files and local translations without creating translation jobs. The api and project commands use the same project context for direct service work without entering the translation pipeline.
When JSON parsing is configured to include source-code context for Paraglide JS messages, the CLI runs the installed Paraglide compiler before file collection. Context collection is optional. A missing compiler or a collection failure produces a warning and does not block the main workflow.
Setup commands use the same resolved-answer model before they write files. They validate required choices and unsafe inputs first. Only then do they apply application changes, save configuration, install packages, or create development credentials.
References: packages/…/base.ts• L270-320 packages/…/base.ts• L719-846 packages/…/base.ts• L1164-1537 packages/…/stage.ts• L20-114 packages/…/download.ts• L42-176 packages/…/upload.ts• L20-85 packages/…/flags.ts• L19-127 packages/…/collectParaglideContext.ts• L18-55
Command flags
Flags provide per-run changes to project, locale, timing, repository, branch, output, and setup policy. They do not replace the shared settings model. Each command validates its flags before it changes files or calls the service.
Important flag groups include:
- Project context:
--config,--api-key, and--project-id. - Translation scope:
--default-locale,--locales, and--version-id. - Safety and timing:
--dry-run,--timeout,--force, and--force-download. - Repository behavior:
--save-local,--publish,--branch,--tag, and--message. - Branch behavior:
--enable-branching,--disable-branch-detection, and--remote-name. - Output behavior: locale paths, static URLs, relative assets, imports, and default-locale visibility.
Quiet output hides normal progress but keeps warnings and errors. JSON and API-key modes keep machine data on stdout and diagnostics on stderr so scripts can consume results without parsing human messages.
References: packages/…/flags.ts• L7-190 packages/…/base.ts• L252-299 packages/…/onboarding.ts• L69-146 packages/…/index.ts• L57-94
Configuration and project context
Configuration gives the CLI a stable description of a project. Flags and environment values provide run-specific or machine-specific input. The CLI resolves these sources into one settings view so collection, API work, download, and output handling use the same rules.
Configuration resolution
The CLI resolves gt.config.json from the project root, with explicit --config support and legacy locations where supported. Commands that change or translate a project require usable configuration unless the command is creating it.
Settings merge configuration with flags and then add defaults for the source locale, API endpoint, project identity, parser behavior, branch policy, and publish intent. GT_API_URL takes precedence over the configured baseUrl. A shell or CI GT_API_KEY takes precedence for CLI work. When the same key came from an env file, the CLI treats it as an application runtime key and prefers a valid CLI login instead. User-token access stays lazy and reads the local login only when the API needs it.
Locale values from configuration and flags are combined while the default locale stays out of the target list. A configured locale can use a custom service mapping. Local checks can keep the project's locale identity, while real service requests require a canonical service code or an explicit mapping.
The settings stage also validates project identity, locale patterns, review policy, and output patterns before remote work starts. Static URL patterns may be one pattern or a list. Each pattern must contain [locale], and the longest matching pattern controls a URL when patterns overlap.
References: packages/…/resolveConfig.ts• L5-30 packages/…/generateSettings.ts• L92-148 packages/…/generateSettings.ts• L190-275 packages/…/cliApiKey.ts• L1-17 packages/…/loadEnv.ts• L1-33 packages/…/apiBaseUrl.ts• L1-6 packages/…/oauth.ts• L481-521 packages/…/index.ts• L252-321
File scope and output mapping
The files configuration maps source files to translated outputs. A [locale] placeholder maps one source set to many locale outputs. A format transform maps one source format to a different translated output format.
This mapping is the shared contract for collection, upload, download, local-edit detection, and publishing. It also carries review rules, inline parsing flags, and special handling for shared catalogs or composite schema files.
Static URL localization uses the same mapping to decide whether a translated page exists. The configuration can localize Markdown links and selected static JSX URL attributes. Dynamic URL expressions remain unchanged because the CLI cannot know their target path without running the application.
References: packages/…/parseFilesConfig.ts• L35-204 packages/…/parseFilesConfig.ts• L207-353 packages/…/supportedFiles.ts• L1-50 packages/…/transformFormat.ts• L12-110 packages/…/fileMapping.ts• L27-166 packages/…/index.ts• L202-243 packages/…/index.ts• L263-281
Configuration persistence
Setup creates or updates gt.config.json without changing unrelated project settings. It preserves file options and avoids rewriting a file when the selected settings did not change. Translation commands may persist the current remote version and branch identifiers unless omitConfigIds is enabled.
The .gt directory is the logical home for working data. gt-lock.json stays at the repository root because it travels with generated files and participates in Git workflows. It records downloaded versions, staged work, output metadata, and hashes for confirmed local translation uploads.
References: packages/…/setupConfig.ts• L37-149 packages/…/updateConfig.ts• L18-74 packages/…/generateSettings.ts• L234-285 packages/…/downloadedVersions.ts• L8-30 packages/…/UploadTranslationsStep.ts• L80-207
Translation workflows
Translation commands share a staged pipeline so source identity, locale mapping, branch context, job status, and local writes remain consistent. The commands differ mainly in where they enter and leave this pipeline.
Source collection and staging
Collection combines configured files with inline updates from the selected runtime. It gives each source unit a stable identity so the service can reuse versions and recognize file moves. It records warnings for unreadable, empty, or invalid inputs instead of hiding collection gaps.
When files.*.parsingFlags.json.includeSourceCodeContext is enabled, collection first asks an installed @generaltranslation/paraglide-js compiler to write metadata for Paraglide messages. The metadata adds source context to the later upload. The step is best effort, so normal file collection can continue when the compiler is absent or cannot run.
The staging flow resolves the branch, synchronizes source files, optionally submits local edits, prepares the project, and enqueues only work that still needs translation. setup stops before enqueueing. enqueue starts from collected source data and sends work. Font synchronization runs before enqueueing when fonts are configured. The shared aggregation path also attaches aligned companion metadata, validates structured files, resolves configured Mintlify $ref files while retaining their file map, and preserves the source shape needed by later upload and download steps.
Inline extraction follows the same content rules as the compiler and runtime. Automatic JSX capture uses the same structural numbering and content shape as compile-time translation, which keeps extracted hashes aligned with rendered content. Existing user translation components remain distinct from automatically captured content.
References: packages/…/collectFiles.ts• L22-129 packages/…/aggregateFiles.ts• L91-220 packages/…/aggregateFiles.ts• L460-604 packages/…/stage.ts• L27-102 packages/…/setupProject.ts• L21-62 packages/…/enqueue.ts• L23-89 packages/…/collectParaglideContext.ts• L18-55 packages/…/resolveMintlifyRefs.ts• L25-46 packages/…/stage.test.ts• L83-125
Source and translation upload
The upload workflow sends current source files and local translated files to the service without creating translation jobs. The command uses the same source aggregation as stage and translate, then applies the common file mapping to ordinary locale files. Composite JSON extracts locale content from the source file, while Apple .xcstrings sends one locale slice from a shared catalog using the locale’s canonical service tag. Binary files stay byte-safe during this handoff.
Large source payloads can use a storage upload and a reference instead of the inline request path. This keeps large files and source-code context within service request limits without changing the source identity or the later workflow.
The upload command checks for a default locale and usable credentials before it calls the service. Missing, unreadable, or invalid translation files are skipped with a warning so the source and other locales can continue. An empty source set ends with an upload-specific message and makes no remote call. After branch resolution, the workflow uploads sources, uploads available translations against the resolved current branch, and publishes when configured.
This diagram shows how local repository content becomes remote source and translation state.
flowchart LR
A[Configured source and local translations] --> B[Aggregate file units]
B --> C[Resolve branch]
C --> D[Upload sources]
D --> E[Upload changed translations]
E --> F[Record confirmed hashes]
F --> G[Publish when configured]
References: packages/…/upload.ts• L41-127 packages/…/upload.ts• L129-248 packages/…/aggregateFiles.ts• L91-111 packages/…/aggregateFiles.ts• L460-604 packages/…/upload.ts• L20-85 packages/…/UploadSourcesStep.ts• L69-216 packages/…/UploadTranslationsStep.ts• L33-168 packages/…/CHANGELOG.md• L34-43
Job completion and download
After jobs are enqueued, the CLI tracks each file, version, branch, and locale as one translation unit. It reuses completed translations, polls the remaining jobs, and keeps the server's failure reason with each failed unit. Successful units can download in the same run even when other units fail or the overall wait reaches its timeout.
Download applies review policy, writes text or binary output, and merges shared catalog or schema content with the current source when needed. A staged download reads its work list from gt-lock.json. Failed units remain available for a later retry, while completed units can be used at once. Optional locale-directory cleanup runs only after at least one translation is confirmed complete and only for translated output paths.
The result separates successful, failed, pending-review, and skipped units. This prevents partial output from being presented as complete and lets a later invocation resume only the work that remains. When all polled units fail, the workflow stops before downloading output.
References: packages/…/download.ts• L47-187 packages/…/download.ts• L190-230 packages/…/PollJobsStep.ts• L18-206 packages/…/downloadFileBatch.ts• L99-523 packages/…/downloadedVersions.ts• L131-300 packages/…/download.test.ts• L78-312
Post-processing and publishing
Post-processing runs on files downloaded or re-merged during the current invocation. It adapts generated content for documentation systems and static localization rules, then records hashes so later local-edit checks can separate CLI output from user changes.
Static URL localization rewrites matching Markdown links and configured JSX URL attributes. A docsUrlPattern may cover several documentation roots, and the most specific matching root wins. The process can keep links to pages with no translated output on the source route. It does not rewrite dynamic URL expressions.
Mintlify redirect localization is opt-in. When a page was renamed or removed in the same run, the CLI can add localized copies of its redirect for locales that have the destination page. It preserves anchors and existing redirect fields, follows redirect arrays stored through $ref, avoids existing localized sources, and does not create nested locale paths.
Publishing is explicit. A publish failure is reported as a warning so a completed translation run is not treated as failed only because CDN state could not be updated.
References: packages/…/translate.ts• L37-210 packages/…/localizeStaticUrls.ts• L19-60 packages/…/localizeStaticUrls.ts• L215-344 packages/…/localizeStaticUrls.ts• L502-834 packages/…/localizeMintlifyRedirects.ts• L20-143 packages/…/localizeMintlifyRedirects.ts• L185-221 packages/…/resolvePublish.ts• L7-72 packages/…/publish.ts• L7-36
OpenAPI documentation references
OpenAPI post-processing keeps localized documentation tied to the localized specification file for each locale. It updates references in Markdown or MDX frontmatter and in Mintlify documentation registration.
The CLI preserves the source path style and keeps the original reference when the target file is missing or the reference is ambiguous. Warnings make unsafe documentation links visible instead of silently selecting unrelated API content.
References: packages/…/processOpenApi.ts• L56-164 packages/…/processOpenApi.ts• L226-335 packages/…/processOpenApi.ts• L380-415 packages/…/processOpenApi.ts• L491-587
Local edit submission
save-local protects edits made directly to translated files. The CLI compares the latest downloaded server translation with the local file and submits only meaningful differences. It does not enqueue new translation jobs.
The command first collects the configured files and resolves the active remote branch. It reads lockfile entries for that branch before it compares files, so a multi-branch lockfile cannot provide a stale baseline. If there is no file or GTJSON template to inspect, it returns without creating or resolving a remote branch.
The comparison uses the same file mapping and lockfile data as download. A recorded post-process hash avoids a remote read when the local locale slice is unchanged. For files that hold several locales, it submits only the changed locale slice. Binary edits are skipped because they do not have a supported text diff. Composite JSON with unreadable $ref files is not submitted when the missing data could erase stored translations.
The command reports whether at least one diff was saved and how many locale edits were skipped. It publishes only when a diff was submitted. Warnings from the current save run are counted separately from earlier warnings, so a partial save is visible without being reported as a clean success. The staging workflow enables this step only from the resolved settings, so a raw flag cannot override a configuration decision later in the run.
References: packages/…/base.ts• L406-424 packages/…/saveLocalEdits.ts• L16-111 packages/…/collectUserEditDiffs.ts• L176-233 packages/…/collectUserEditDiffs.ts• L267-361 packages/…/collectUserEditDiffs.ts• L364-512 packages/…/collectUserEditDiffsLockfileBranch.test.ts• L151-247 packages/…/saveLocalEditsBranch.test.ts• L133-237 packages/…/gitDiff.ts• L1-80 packages/…/generateSettings.ts• L331-340 packages/…/stage.ts• L65-71 packages/…/resolveMintlifyRefs.ts• L92-193 packages/…/CHANGELOG.md• L31-36
Git integration and repository state
Git provides branch context and a durable place to share generated translation state. The integration keeps translations tied to the branch that produced them and gives parallel branches defined merge behavior.
Branch resolution
When branching is enabled, the CLI combines local Git information with remote branch records. It can use the current branch, the default branch, and branch history to select the remote translation context. CI can provide a branch name when local Git information is not available.
Manual branch selection takes precedence. If detection fails, the CLI reports the fallback to the default remote branch. A requested branch can be created when policy allows it; other branch service failures remain errors. Workflows that compare local edits pass the branch resolved for the current run into lockfile reads, even when settings still contain a branch ID persisted by an earlier run.
References: packages/…/BranchStep.ts• L17-193 packages/…/saveLocalEdits.ts• L25-55 packages/…/collectUserEditDiffs.ts• L176-233 packages/…/branches.ts• L7-119 packages/…/generateSettings.ts• L392-408
Lockfile state
gt-lock.json records the remote version used for each file and locale. A staged entry marks work sent but not yet downloaded. A downloaded entry records the output path and update metadata. Translation entries may also carry a post-process hash for a confirmed local upload.
This state lets download resume staged work, lets later runs skip current output, and lets upload avoid unchanged local translations. Local-edit comparison uses the file's resolved branch to select the matching entry in a multi-branch lockfile. The CLI reads current and older lockfile shapes and upgrades the shape only when staged state needs the newer form.
References: packages/…/downloadedVersions.ts• L8-30 packages/…/downloadedVersions.ts• L131-300 packages/…/collectUserEditDiffs.ts• L176-233 packages/…/collectUserEditDiffsLockfileBranch.test.ts• L69-207 packages/…/stage.ts• L77-113 packages/…/UploadTranslationsStep.ts• L33-58
Merge drivers
gt git setup connects Git merge drivers to generated translation state. One driver merges lockfile version data. Another merges the shared GTJSON document by key. Both use three-way rules and reject conflicts that could lose content.
The command writes the required .gitattributes entries and local Git settings. It supports a dry run and can omit persisted config IDs when reducing config-file conflicts is more important than pinning a remote version.
References: packages/…/base.ts• L593-717 packages/…/setupMergeDrivers.ts• L31-177 packages/…/mergeDrivers.ts• L40-157
Run state and warnings
In-memory run state connects downloaded paths with post-processing and collects warnings for the final summary. It tracks each locale for files that contain several locales instead of keeping only the last write.
This state is temporary. The lockfile and post-process hashes carry the durable facts needed by later invocations. Warning categories make pending review, failed moves, failed translations, failed downloads, and skipped files visible without changing the main workflow contract.
References: packages/…/recentDownloads.ts• L1-54 packages/…/mintlifyRefMap.ts• L1-17 packages/…/orphanedFileNames.ts• L1-14 packages/…/translateWarnings.ts• L1-34 packages/…/base.ts• L819-846
Setup and API access
Setup turns an unconfigured project into a project with known locales, file targets, runtime guidance, and credentials. API access then uses the resolved project identity and authentication to perform translation or administration work.
Project setup
init detects the project type and guides the user through recommended settings. configure uses the same settings path for configuration changes without applying the full application setup. Both commands resolve and validate their answers before the first project change. They record completed steps so a later failure can report what already changed and support a safe rerun.
The setup and source-upload paths collect Paraglide JS source context when the matching JSON parsing flag is enabled. This removes the need for a separate context command in projects that use @generaltranslation/paraglide-js.
The setup flow routes React Router and Shopify Hydrogen applications to the React Router quickstart instead of the generic React quickstart. It also detects Expo and React Native as unsupported setup targets and stops before changing them. These checks keep framework guidance and file changes aligned with the application shape.
Supported framework setup includes Vite, React Router, and TanStack Start. React Router setup first checks that the app uses supported framework mode and has a readable configuration and root module. It accepts only request-rendered apps that use the app directory and a supported gt-react version; it refuses SPA, pre-rendered, alternate-directory, and experimental RSC shapes before changing files. TanStack Start setup keeps request middleware, translation loading, and the root provider in one request path. Custom loaders and unsafe application shapes are preserved and returned as manual actions.
Next.js Pages Router setup is deliberately handed to its quickstart. The CLI can still save translation configuration and local loader state, but it does not install or wire the application package. This produces a human-action result rather than implying that the application is ready.
Answers follow a stable order: explicit flags, existing configuration, accepted defaults, and interactive prompts. Noninteractive and JSON modes report missing choices and partial setup as structured results instead of waiting for input. Package-manager selection uses an explicit choice first, then project metadata, then an unambiguous lockfile. Setup refuses a monorepo workspace root and asks the command to run from the specific app instead.
For Mintlify and Next.js App Router projects, --locadex can stop local setup and hand the user to the GitHub connection flow. Interactive setup may open the dashboard URL. Noninteractive and JSON setup returns the URL without opening a browser and reports needs_human_action. This handoff changes no local files.
References: packages/…/base.ts• L926-1091 packages/…/base.ts• L1164-1735 packages/…/onboarding.ts• L167-455 packages/…/detectFramework.ts• L24-101 packages/…/setupTarget.ts• L11-77 packages/…/index.ts• L11-83 packages/…/vite.ts• L15-84 packages/…/wizard.ts• L41-188 packages/…/setupFlow.ts• L5-28 packages/…/collectParaglideContext.ts• L18-55 packages/…/CHANGELOG.md• L37-49
Translation loader ownership
Generated loaders connect the application to the locale files selected in configuration. Setup creates empty files for non-default locales so an application can load a known path before translations exist. The default locale remains the source content.
Before changing a loader, setup checks whether it owns the file. It preserves custom or uncertain application code and reports a manual action when it cannot prove that a generated loader is safe to update. This ownership rule makes reruns safe and prevents two loaders from competing for the same runtime path.
References: packages/…/createLoadTranslationsFile.ts• L26-163 packages/…/loader.ts• L1-38 packages/…/initializeGT.ts• L8-85 packages/…/vite.ts• L28-69 packages/…/base.ts• L1590-1679
Formatting hooks
The setup path treats formatting as an optional cleanup hook for files it changes. It uses an available Prettier, ESLint, or Biome tool on updated files. If no formatter is available or formatting fails, setup keeps the project changes and reports a warning.
References: packages/…/postProcess.ts• L6-134 packages/…/wizard.ts• L160-187 packages/…/wizard.ts• L191-259
Credential flow
login establishes a user session for the configured General Translation API. A normal terminal uses a browser flow with a local callback. SSH sessions, --no-browser, and callback failures use a device code that the user approves in a browser.
Setup reuses matching runtime credentials when they already exist. If it must provision credentials, it resolves an explicit or configured project first. An interactive user can choose an accessible project or ask setup to create one. A noninteractive run must provide the project or the inputs needed to create it. The new development key is limited to runtime translation generation and is written to .env.local with the framework-specific project and key names.
The setup path checks that .env.local can be edited safely before it creates a project or key. It refuses tracked, exposed, malformed, or non-regular files. A shell or CI GT_API_KEY is the credential sent to the API when present, so a permission denial explains how to remove that key or use an organization key. A signed-in user session is used when no API key takes precedence. The secret is never printed in normal output.
The session is bound to its API resource and stored with private permissions. The CLI refreshes an expiring session before use and does not silently reuse a session issued for a different API. logout removes the local session and attempts revocation. whoami checks the session and reports the account.
Setup can choose or create an accessible project, mint a development key, and save the project identity and framework-specific development variable to .env.local. Next.js uses GT_PROJECT_ID and GT_API_KEY; other supported client frameworks use their framework prefix with GT_PROJECT_ID and GT_DEV_API_KEY. Older Next.js public variable names remain readable for compatibility. Production credentials stay in the hosting environment.
References: packages/…/base.ts• L1438-1537 packages/…/developmentCredentials.ts• L19-43 packages/…/developmentCredentials.ts• L177-308 packages/…/oauth.ts• L114-174 packages/…/oauth.ts• L223-564 packages/…/credentialStore.ts• L16-168 packages/…/credentials.ts• L83-132 packages/…/credentials.ts• L175-303 packages/…/credentials.ts• L321-443 packages/…/initCredentials.test.ts• L168-246 packages/…/initCredentials.test.ts• L662-753
API boundary
The CLI uses one configured API client for translation work and a request path for dashboard sessions. The client receives project identity, API-key or user-token access, source locale, custom locale mapping, and service URL from resolved settings before a workflow starts.
Remote operations cover branch and file metadata, source and translation upload, project setup, job status, download, local edit diffs, and publishing. Large payloads may cross the service boundary through storage references. Service status codes and network errors remain visible to workflow diagnostics.
References: packages/…/generateSettings.ts• L219-229 packages/…/generateSettings.ts• L440-448 packages/…/api.ts• L1-31 packages/…/BranchStep.ts• L14-18 packages/…/UploadSourcesStep.ts• L17-24 packages/…/DownloadStep.ts• L5-14 packages/…/CHANGELOG.md• L51-61
Direct API requests
The api command is a low-level authenticated request path for service operations that do not belong to a translation workflow. It accepts an endpoint, standard HTTP method, headers, and an optional body file or standard input. It writes the response body without changing its text or binary form. It can also include response status and headers when requested.
The command can list API operations or print a selected OpenAPI fragment with local references resolved. It checks project identity agreement across configuration, flags, and environment, but does not require translation locales or file settings. Response data stays on stdout. Diagnostics and non-success status messages stay on stderr, while a non-success response exits with an error after its body is written.
References: packages/…/base.ts• L427-455 packages/…/api.ts• L21-127 packages/…/api.ts• L131-255 packages/…/api.ts• L318-450 packages/…/validation.ts• L34-71
API key management
api-key create creates a project API key with an explicit permission set and prints the secret once. With --org-id, it creates an organization API key instead. Organization key creation uses the signed-in user session because an API key cannot create another organization key. Organization-only permissions require --org-id, while project permissions remain valid for project keys.
Other output goes to stderr so scripts can capture the key from stdout without receiving diagnostics. The secret never enters the normal logger or a log file, and validation happens before settings resolution or any API request.
References: packages/…/base.ts• L513-593 packages/…/base.ts• L252-287 packages/…/validation.ts• L34-71 packages/…/CHANGELOG.md• L92-98
Project administration
Project commands create a service project with an organization key or report the status of an asynchronous setup job. They turn service errors into CLI diagnostics instead of exposing unhandled request failures.
References: packages/…/base.ts• L458-510
Console output
The console layer separates human progress from machine-readable command data. Interactive runs show prompts and progress. JSON mode emits authorization, handoff, and result events on stdout while setup progress and diagnostics use stderr. Quiet mode hides informational output while keeping warnings and errors. An optional log file keeps JSON records independent of console routing. API-key creation keeps the secret on stdout while routing its diagnostics to stderr.
Setup result events include the outcome, completed steps, missing options, human actions, and next steps when those facts exist. This lets automation distinguish a complete setup from a handoff, an incomplete setup, or a failure after partial local changes.
References: packages/…/logging.ts• L25-77 packages/…/logging.ts• L182-276 packages/…/logger.ts• L100-403 packages/…/index.ts• L428-466 packages/…/onboarding.ts• L149-200 packages/…/onboarding.ts• L229-455 packages/…/base.ts• L264-290
Translation operations
Inline translation operations connect source scanning with the same remote file workflow used by configured files. They cover dictionaries, inline markup and calls, source-template generation, and validation before translation work is sent.
Inline extraction
The CLI scans the selected source scope for dictionary entries and inline content owned by the active runtime. It checks IDs, syntax, ICU content, and source limits before creating the shared inline translation document.
For JavaScript and TypeScript dictionaries, the CLI uses a portable bundle step before reading exports. JSX extraction can follow content across supported imports and re-exports for statically analyzable derived values. Broken resolution produces warnings and keeps processable content rather than silently inventing source text.
References: packages/…/stage.ts• L11-84 packages/…/parse.ts• L31-164 packages/…/inline.ts• L69-83 packages/…/createESBuildConfig.ts• L12-29 packages/…/createDictionaryUpdates.ts• L20-117 packages/…/parseJsx.test.ts• L48-360
Source generation
generate creates a source-locale translation file for teams that manage translations themselves. It writes current source entries and removes target entries whose source keys no longer exist. It does not require a remote translation job.
References: packages/…/inline.ts• L103-177 packages/…/stage.ts• L11-36
Project validation
validate scans the whole project or selected files without changing the translation service. It reports whether inline content and dictionaries are valid. Its programmatic form returns messages grouped by file for tools that need machine-readable results.
References: packages/…/inline.ts• L86-100 packages/…/validate.ts• L25-207
See also Extraction and compilation, Compiler transform pipeline, Language and framework extractors, and Paraglide JS compilation.
Change checklist
When these files or sections are changed, remember to consider these:
- When command flags or settings fields change, check merge order and every workflow that consumes the resolved value.
- When monorepo discovery or version checks change, check declared workspace scoping, lockfile root detection, pnpm and package.json workspace pattern rules, dependency sources, skip controls, and structured error reporting together.
- When API URL or authentication resource changes, check environment precedence, session binding, API-client construction, direct requests, and setup diagnostics together.
- When CLI API-key resolution changes, check the distinction between shell or CI keys, env-file runtime keys, and signed-in user access.
- When file patterns, locale placeholders, or format transforms change, check collection, output mapping, local-edit diffing, download merging, post-processing, and publishing together.
- When
docsUrlPatternchanges from one pattern to several, check validation, longest-match selection, static links, JSX URL attributes, and Mintlify redirects together. - When static URL options change, check default-locale visibility, untranslated-page checks, exclusions, custom attributes, absolute URLs, and dynamic expressions.
- When redirect localization changes, check orphaned-file reporting,
$refchains, existing localized sources, destination availability, anchors, and nested-locale protection. - When inline JSX extraction changes, check compiler/runtime numbering, user-written component ownership, automatic injection,
Deriveresolution, and hash parity. - When locale validation or custom mappings change, check local dry-run behavior and canonical service values sent by the API client.
- When review or publish policy changes, check download eligibility, output state, version identity, and CDN behavior.
- When branch or version identity changes, check config persistence, gt-lock.json, staged downloads, and Git merge-driver rules.
- When local-edit save behavior changes, check current-branch lockfile selection, empty-work avoidance, per-locale comparison, skipped-edit counts, and publish gating.
- When polling or download status changes, check failed-unit reasons, partial downloads, timeout results, branch-scoped state, and locale-directory cleanup together.
- When setup writes application files, check formatter handling, custom-loader preservation, safe source shapes, storage changes, and manual-action output.
- When framework detection changes, check precedence between framework packages, React Native refusal, setup docs, environment names, and build-tool selection.
- When React Router preflight changes, check framework detection, readable config, request-rendered mode,
appdirectory use, supportedgt-reactversions, RSC exclusion, and the no-change refusal path together. - When setup answer handling changes, check explicit flags, existing config, defaults, prompts, missing-option results, partial-run results, next-step output, and stdout/stderr routing.
- When setup validation or step ordering changes, check that invalid inputs and unsafe credential files fail before local writes, installs, project creation, or key creation.
- When Locadex handoff changes, check framework gating, dashboard URL construction, browser behavior, JSON handoff events, and the no-local-change guarantee.
- When OAuth or development credential setup changes, check API binding, refresh, file permissions, Git exposure, ignore rules, atomic writes, project matching, and secret output.
- When upload aggregation changes, check source parsing, companion metadata, composite JSON extraction, shared-catalog slicing, binary reads, translation mapping, and branch association together.
- When Paraglide context collection changes, check the parsing flag, compiler discovery, metadata timing, warning behavior, standalone package resolution, and all commands that collect files.
- When upload deduplication changes, check both the lockfile hash and the server-confirmed result so failed persistence is retried.
- When
$refresolution changes, check provenance, circular or unreadable references, composite-locale protection, local edit submission, and restoration of the original file layout. - When direct API output changes, check method and header validation, project-ID agreement, raw body and response preservation, OpenAPI lookup, stdout/stderr routing, and HTTP error exits together.
- When version registration or package exports change, check
--version,-V, hidden-v, generated package version data, executable packaging, and machine-readable output behavior together. - When API-key permissions or organization-key support changes, check pre-request validation, user-session use, project-ID requirements, secret-only stdout, and the API adapter contract together.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| No usable configuration is found | The CLI cannot resolve project or file behavior | Run from the project root, pass --config, or run gt init |
| A monorepo declares conflicting GT package versions in its declared workspaces | The CLI exits before the workflow can use inconsistent project-local packages | Align the declared versions across the checked workspaces, or use --skip-version-check / skipVersionCheck when the check is not applicable |
A URL pattern or output path omits [locale] | The CLI cannot map localized links or files safely | Add the placeholder to every pattern or use a supported shared-file rule |
| Overlapping URL patterns are ordered without considering specificity | A link or redirect can receive the wrong locale path | Let the longest matching pattern control the URL |
| A static URL points to a source page with no translated output | A localized document can link to a missing page | Enable skipUntranslatedPages when source routes must remain unchanged |
| A redirect destination has no translated page | A localized redirect can point to a missing destination | Keep the destination available for that locale before adding the redirect |
| A translated page is reported as orphaned with its source page | Redirect localization can create a nested locale path | Let the redirect pass skip already localized sources and destinations |
| Project IDs differ across config, flags, and environment | The command stops before remote work | Use one project ID in all sources |
| A real API command has no usable key or login | Credential validation stops the workflow | Use a permitted API key or run gt login |
| A login belongs to another API resource | The session is rejected instead of refreshed | Log in against the API used by the project |
An env-file GT_API_KEY is mistaken for a CLI key while a login exists | CLI requests can use the wrong identity or runtime secret | Keep runtime keys in env files and let the CLI use its login; set shell or CI keys explicitly when the CLI must use one |
| Setup receives a missing or invalid answer in noninteractive mode | Setup stops before changing project files | Pass the missing option, accept --defaults for local choices, or run interactively |
| Branch detection fails outside a Git worktree or in CI | Work can fall back to the default branch | Set --branch and confirm branch policy |
| A local-edit save reads a lockfile entry from the wrong branch | The diff is compared with an unrelated server version or is missed | Resolve the branch before lockfile reads and use the branch attached to the current file references |
| A local-edit baseline is missing after the local hash shows an edit | The edit is not submitted and the run reports a skipped locale | Restore the matching remote version or rerun after the server data is available |
| A save-local run has no files or GTJSON template | No work is saved and no remote branch is created | Check file patterns and template configuration before saving |
| A translation job times out | Completed work can download but the run reports incomplete work | Increase the timeout and rerun download |
| Review blocks a translation | Local output stays absent or partial | Approve the translation and rerun the download step |
| gt-lock.json has no supported staged shape | Resume and merge behavior can fall back or fail | Run a current gt stage or gt translate before merging |
| Setup runs at a monorepo workspace root | The wizard refuses to choose an app and change shared files | Change to the target app directory and rerun setup |
| Expo or React Native is detected | Setup stops before changing the app | Follow the React Native quickstart and configure the integration manually |
React Router uses SPA, pre-render, alternate app-directory, RSC, or unsupported gt-react settings | Setup refuses to edit the app | Use a supported request-rendered app or configure the integration manually |
| Setup finds a custom loader or unsafe application shape | Automatic setup leaves code unchanged and reports manual work | Review the application boundary and connect the chosen storage mode manually |
| A Next.js Pages Router app is selected | The wizard leaves application wiring to the quickstart | Follow the Pages Router quickstart and treat the setup result as human action |
| Locadex is selected for an unsupported framework | Setup rejects the handoff before local work | Use Locadex only with Mintlify or Next.js App Router projects |
| Locadex handoff cannot open a browser | No local setup occurs and the user may miss the connection page | Use the reported dashboard URL in a browser |
| .env.local is tracked, exposed through a symlink, unsafe to parse, or Git cannot verify it | Setup refuses to mint or write a development secret | Remove the exposure, fix the file, and rerun setup |
| Project creation or key creation fails after setup files were written | The project is partially configured and no success result is claimed | Read the completed-step report, fix permissions or credentials, and rerun setup |
| No source files remain after collection | upload reports an upload-specific error and makes no remote call | Check file patterns, validation warnings, and the project configuration |
| A source catalog locale differs from the configured default locale | Upload stops instead of sending a mislabeled source slice | Align the catalog source language with the configured default locale |
| A local translation is unreadable or persistence is unconfirmed | That locale is skipped and is not recorded as current | Fix the file or service issue and rerun upload |
| A configured locale is absent from a shared catalog | That locale has no translation upload | Add the locale to the catalog or remove it from the upload scope |
| A Paraglide compiler cannot be resolved or context collection fails | Source context is absent from the upload, but the main workflow can continue | Install the compiler and fix its project resolution; treat the warning as a context-quality issue |
A Derive import chain is broken or recursive | Some inline entries are missing or extraction reports an error | Keep derived content statically resolvable and avoid recursive calls |
A configured $ref file is missing, invalid, or circular | Composite content can be incomplete and local edits may be skipped | Repair the referenced file and review warnings before uploading edits |
gt api receives an invalid method, endpoint, or body | No request is sent and the command exits with a diagnostic | Use a standard method, a valid endpoint, and readable body input |
| A direct API request returns a non-success status | The raw response is written, then the command exits with an error | Read the response body and diagnostics, then correct the request or service state |
An organization-only API-key permission is used without --org-id | Validation stops before settings or a request | Pass --org-id or use only project permissions |
| An organization API key is requested with only an API key credential | Key creation cannot authenticate the required organization operation | Log in with gt login so the command can use the signed-in user session |
-v is registered as a visible independent option or version data is stale | Scripts can fail to get the version or help output can expose the wrong contract | Register the hidden alias with the root version handler and generate package version data |
Key files
| File | Why to read it |
|---|---|
| packages/…/package.json | Defines the published CLI package, its current version, executable boundary, build, test, and public exports. |
| packages/…/bin-entry.ts | Shows startup environment loading and command parsing order. |
| packages/…/index.ts | Shows version registration and how the active project adapter is selected. |
| packages/…/version.ts | Defines the visible long version flags and hidden short alias. |
| packages/…/base.ts | Defines the shared command surface, setup lifecycle, hooks, API-key paths, and top-level translation lifecycle. |
| packages/…/flags.ts | Defines command contracts for shared, translation, inline, and setup flags. |
| packages/…/generateSettings.ts | Shows how configuration, flags, environment, locales, API access, branches, and output policy become one settings object. |
| packages/…/cliApiKey.ts | Defines how the CLI separates env-file runtime keys from shell or CI keys and signed-in access. |
| packages/…/index.ts | Defines the settings, framework, file, review, URL, and setup contracts. |
| packages/…/parsing.ts | Defines parser flags, including Paraglide source-context collection and inline extraction options. |
| packages/…/parseFilesConfig.ts | Explains how file patterns, review rules, and output choices become resolved paths. |
| packages/…/aggregateFiles.ts | Shows how configured source files become stable upload units and how shared catalogs, structured files, and references are prepared. |
| packages/…/collectParaglideContext.ts | Defines the optional source-context handoff to the project-local Paraglide compiler. |
| packages/…/stage.ts | Shows the source-to-enqueue workflow and the resolved-settings gate for local edits. |
| packages/…/upload.ts | Shows how source units are paired with local translations before upload. |
| packages/…/upload.ts | Shows branch resolution and the source, translation, and publish upload order. |
| packages/…/download.ts | Shows how completed remote work becomes local files. |
| packages/…/PollJobsStep.ts | Defines job reuse, polling, timeout, partial completion status, and failure reasons. |
| packages/…/BranchStep.ts | Defines the relationship between Git state and remote translation branches. |
| packages/…/saveLocalEdits.ts | Shows branch-first local-edit saving, template lookup, skipped-edit reporting, and publish gating. |
| packages/…/collectUserEditDiffs.ts | Shows branch-specific baseline selection and per-locale local-edit comparison. |
| packages/…/downloadedVersions.ts | Defines durable staged and downloaded state. |
| packages/…/setupMergeDrivers.ts | Shows how generated translation state connects to Git merging. |
| packages/…/postProcess.ts | Defines optional formatter cleanup for setup changes. |
| packages/…/localizeStaticUrls.ts | Defines locale-aware static link and JSX URL localization. |
| packages/…/localizeMintlifyRedirects.ts | Defines localized redirect creation for renamed or removed documentation pages. |
| packages/…/resolveMintlifyRefs.ts | Defines reference resolution, provenance tracking, and safe handling of unreadable or circular files. |
| packages/…/onboarding.ts | Defines setup answer precedence, pre-change validation, scripted outcomes, JSON events, completed-step tracking, and partial-run reporting. |
| packages/…/developmentCredentials.ts | Defines project selection, project creation, development-key provisioning, permission guidance, and credential persistence. |
| packages/…/wizard.ts | Defines React setup planning, Pages Router handoff, application wiring, and formatting choice. |
| packages/…/setupFlow.ts | Defines the GitHub connection handoff URL and browser behavior for Locadex setup. |
| packages/…/monorepoVersionCheck.ts | Defines monorepo discovery, declared-workspace scoping, GT package version checks, skip controls, and failure reporting. |
| packages/…/monorepoVersionCheck.test.ts | Shows the supported lockfile and workspace declaration cases for version checks. |
| packages/…/monorepoVersionCheckWorkspaces.test.ts | Shows the workspace include and exclude rules that control which packages are checked. |