Skip to main content
The clean command removes unused or orphan translation keys from your locale JSON files.

Usage

Options

boolean
default:"false"
Actually delete keys. Without this flag, glot runs in dry-run mode and only shows what would be deleted.
string[]
default:"all"
Rules to clean. Can be specified multiple times. If not specified, all rules are applied.Possible values:
  • unused - Keys defined in locale files but not used in code
  • orphan - Keys in non-primary locales but not in primary locale
string
Override the source code root directory. Defaults to the value from configuration file.
string
Override the messages directory path. Defaults to the value from configuration file.
string
Override the primary locale. Defaults to the value from configuration file.
boolean
default:"false"
Enable verbose output for debugging.

Dry-Run Mode (Default)

By default, glot runs in dry-run mode to preview changes:
Output:

Apply Changes

To actually delete the keys:
Output:

Clean Specific Key Types

Unused Keys Only

Remove keys that exist in locale files but are never used in code:

Orphan Keys Only

Remove keys that exist in non-primary locales but not in the primary locale:
When --rules is not specified, both unused and orphan keys are cleaned.

Safety Checks

Glot includes safety mechanisms to prevent accidental data loss:
Glot will refuse to clean if:
  • Dynamic keys are detected - Template literals with expressions like t(`key.${id}`) can’t be statically analyzed
  • Parse errors exist - Some files couldn’t be parsed correctly
If you see this message:
You’ll need to either:
  1. Replace dynamic keys with static alternatives
  2. Use // glot-message-keys "pattern.*" to declare which keys are used dynamically
Do NOT use glot-disable-next-line for dynamic keys when using clean. While it suppresses the warning, it doesn’t tell glot which keys are actually used. This means clean may incorrectly delete keys that are dynamically referenced.

Handling Dynamic Keys

Examples

Preview All Cleanable Keys

Clean Everything

Clean Only Unused Keys with Custom Source Root

Directives

Use glot-message-keys for dynamic keys

Orphan Keys

Understanding orphan key detection

Missing Keys

Understanding missing key detection