Skip to content

Configuration

Token Optimizer reads configuration from two places: environment variables and a config.json file. Environment variables take precedence. When both set the same setting, the environment variable wins for that run, and config.json holds the persistent default.

config.json lives at ~/.claude/token-optimizer/config.json. It stores feature flags, consent status, the pricing tier, and timestamps. The v5 command and the various setup-* and consent commands write to it. Most users never edit it by hand; the commands keep it consistent.

Each active compression feature has a config.json key and an environment override. Setting the environment variable to 0 disables the feature for that run regardless of the persisted value.

VariableDefaultEffect
TOKEN_OPTIMIZER_BASH_COMPRESSenabledSet to 0 to disable Bash output compression for eligible read-only commands
TOKEN_OPTIMIZER_READ_CACHEenabledSet to 0 to disable the read cache entirely (no delta, no skeleton substitution)
TOKEN_OPTIMIZER_READ_CACHE_DELTAenabledSet to 0 to disable delta mode only (re-reads return full content instead of a diff)
TOKEN_OPTIMIZER_READ_CACHE_MODEsoft_blockSelect the read-cache mode: soft_block, warn, shadow, or block. See the modes table below.
TOKEN_OPTIMIZER_STRUCTURE_MAPsoft-block onlySet to beta to enable structure-map compression event logging. This is a separate measurement toggle, not the mode selector above.
TOKEN_OPTIMIZER_QUALITY_NUDGESenabledSet to 0 to disable the quality-drop alerter
TOKEN_OPTIMIZER_LOOP_DETECTIONenabledSet to 0 to disable the retry-loop detector
TOKEN_OPTIMIZER_FIRST_READ_SHADOWenabledSet to 0 to disable both first-read skeleton measurement and active first-read skeleton serving
TOKEN_OPTIMIZER_FIRST_READ_ACTIVEenabledSet to 0 to disable active first-read skeleton serving for promoted cohorts
TOKEN_OPTIMIZER_VERBOSITY_MIN_FILL25Context fill % at which the lean-output nudge fires (fill alone; quality is not a condition)

The matching config.json keys are: v5_bash_compress, read_cache_enabled, v5_delta_mode, v5_structure_map_beta, v5_quality_nudges, and v5_loop_detection (the v5_ prefix is a legacy naming convention; the features are current). Manage them with measure.py v5 enable|disable <feature> rather than editing the file.

The read cache operates in one of four modes, selected with TOKEN_OPTIMIZER_READ_CACHE_MODE (for example TOKEN_OPTIMIZER_READ_CACHE_MODE=shadow). The default is soft_block.

ModeBehavior
soft_blockDefault. On an unchanged re-read, substitute a compact result (delta or structure map) instead of the full file. Always allows the read to proceed.
warnAllow the full re-read, but emit a warning that the file was already read. No substitution.
shadowMeasure what substitution would have saved without changing the result the model sees. Used for validation.
blockRefuse the redundant re-read outright. Most aggressive; available on platforms that support read interception (for example OpenClaw).
VariableDefaultEffect
TOKEN_OPTIMIZER_CONTEXT_SIZEauto-detectedOverride the assumed context window size for all commands. Equivalent to the --context-size flag.
TOKEN_OPTIMIZER_QUALITY_WINDOW20Rolling window size for ratio-based quality signals
TOKEN_OPTIMIZER_TOOL_CALL_WARNautoTool-call warning threshold; scales with the context window
TOKEN_OPTIMIZER_TOOL_CALL_CRITICALautoTool-call critical threshold; scales with the context window
TOKEN_OPTIMIZER_RELEVANCE_THRESHOLD0.3Minimum relevance score for collecting a checkpoint as a continuity candidate or teaser
TOKEN_OPTIMIZER_RELEVANCE_FULL_THRESHOLD0.5Minimum relevance score for emitting the full recovered-data block instead of a one-line teaser
TOKEN_OPTIMIZER_DENSITY_MIN_MESSAGES6Keep decision-density scoring neutral until the session has this many messages
TOKEN_OPTIMIZER_FRESH_NUDGE_QUALITY70Quality-score threshold used by the fresh-session nudge
TOKEN_OPTIMIZER_FRESH_NUDGE_MIN_FILL45Minimum context fill % used by the fresh-session nudge
VariableDefaultEffect
TOKEN_OPTIMIZER_CHECKPOINT_RETENTION_DAYS7Days to keep checkpoints before cleanup
TOKEN_OPTIMIZER_CHECKPOINT_RETENTION_MAX50Maximum checkpoints to scan for restore
TOKEN_OPTIMIZER_CHECKPOINT_TELEMETRYoffSet to 1 to enable the checkpoint-stats telemetry summary
TOKEN_OPTIMIZER_PROGRESSIVE_CHECKPOINTSenabledSet to 0, false, no, or off to disable progressive checkpoint capture at the 20/35/50/65/80% fill bands
TOKEN_OPTIMIZER_CHECKPOINT_FILES10Maximum active/recent files retained in extracted checkpoint state
TOKEN_OPTIMIZER_CHECKPOINT_EVENT_MAX1000Maximum checkpoint telemetry events retained after pruning
TOKEN_OPTIMIZER_CHECKPOINT_COOLDOWN_SECONDS90Minimum time between checkpoint fires
TOKEN_OPTIMIZER_EDIT_BATCH_WRITE_THRESHOLD4Write-count delta that triggers an edit-batch checkpoint
TOKEN_OPTIMIZER_EDIT_BATCH_FILE_THRESHOLD3Changed-file delta that triggers an edit-batch checkpoint
TOKEN_OPTIMIZER_CONTINUITY_MAX_SESSIONS5Maximum prior sessions represented in a continuity hint
TOKEN_OPTIMIZER_CONTINUITY_PER_SESSION_SCAN3Maximum checkpoint candidates scanned per prior session
TOKEN_OPTIMIZER_RESUME_TOPIC_BAR0.22Residual-topic score above which a resume request is treated as naming a topic rather than asking for the most recent same-project checkpoint

These seven names are read by opencode/src/util/env.ts and exist only there; the feature names also exist on other platforms, but these exact environment-variable names are not cross-platform aliases.

VariableDefaultPlatformEffect
TOKEN_OPTIMIZER_SMART_COMPACTIONtrueOpenCodeEnable compaction context injection
TOKEN_OPTIMIZER_CONTINUITYtrueOpenCodeEnable session continuity
TOKEN_OPTIMIZER_NUDGEStrueOpenCodeEnable quality nudges
TOKEN_OPTIMIZER_ACTIVITYtrueOpenCodeEnable activity-mode tracking
TOKEN_OPTIMIZER_TRENDStrueOpenCodeEnable trends collection
TOKEN_OPTIMIZER_DATA_DIRplatform-global locationOpenCodeBase directory, used verbatim, under which the token-optimizer/ data folder is created
TOKEN_OPTIMIZER_CHECKPOINT_MAX_CHARS2000OpenCodeMaximum characters of checkpoint content injected on continuity restore
VariableDefaultEffect
TOKEN_OPTIMIZER_HOST127.0.0.1Bind host for the dashboard server
TOKEN_OPTIMIZER_DASHBOARD_HOST127.0.0.1Dashboard-specific bind host; set to 0.0.0.0 for LAN access before setup-daemon
TOKEN_OPTIMIZER_DASHBOARD_TIMEOUT30 secondsTotal retry budget when opening the dashboard server
TOKEN_OPTIMIZER_TURN_PRELOAD_MAX40Maximum recent sessions whose per-turn data is embedded in a static dashboard

Dashboard ports are fixed per runtime: 24842 (Claude Code), 24843 (Codex), 24844 (Hermes), 24845 (Copilot). They are not configured by environment variable; they are assigned by the engine so multiple runtimes can serve dashboards simultaneously without conflict. The --port flag on dashboard overrides the port for a one-off serve.

VariableDefaultEffect
TOKEN_OPTIMIZER_TRENDS_RETENTION_DAYSunlimitedDays to keep rows in the history database
TOKEN_OPTIMIZER_ARCHIVE_RETENTION_HOURS24Hours to keep archived tool results
TOKEN_OPTIMIZER_ARCHIVE_RETENTION_MAX_FILES1000Maximum files across tool archives; oldest sessions are removed first
TOKEN_OPTIMIZER_ARCHIVE_RETENTION_MAX_BYTES104857600Maximum aggregate tool-archive bytes (100 MiB); oldest sessions are removed first
TOKEN_OPTIMIZER_QUALITY_CACHE_RETENTION_DAYS7Days to keep quality-cache snapshots; 0 means unlimited
TOKEN_OPTIMIZER_ORPHAN_RETENTION_DAYS30Minimum inactivity age for orphan plugin-data reclamation (hard floor: 7 days)

Per-session file caches are auto-deleted after 48 hours and are not configurable. See Your data and privacy for the full storage map.

Keep-Warm is opt-in and managed by the keepwarm-* commands; there are no plain feature-flag environment variables for it. Consent and billing mode are persisted in config.json and read by keepwarm-consent-status.

The two Keep-Warm names found in the Python core are internal execution markers and are listed under Internal and test-only names.

VariableDefaultEffect
TOKEN_OPTIMIZER_COPILOT_USD_PER_CREDIT0.01USD value of one Copilot AI credit, for cost display
TOKEN_OPTIMIZER_COPILOT_PREMIUM_RATE0.04USD per premium request
TOKEN_OPTIMIZER_COPILOT_CAPS_JSON(unset)JSON override of the Copilot capability map when upstream fixes outpace the shipped matrix, for example '{"pretooluse_ctx": true}'
TOKEN_OPTIMIZER_COPILOT_BINcopilotOverride the Copilot CLI executable used by doctor and hook-bridge checks
TOKEN_OPTIMIZER_COPILOT_HOME~/.copilot or auto-detectedOverride the Copilot home used by Token Optimizer; validated before use

The pricing tier drives every cost and savings calculation. Set it with measure.py pricing-tier <tier>; the value persists in config.json. The default is anthropic.

TierPricing basis
anthropicAnthropic API direct rates (default)
Vertex AI GlobalGoogle Vertex AI global rates
Vertex AI RegionalVertex AI regional rates (a regional premium applies)
AWS BedrockAWS Bedrock rates
subscriptionFlat-rate subscription; Keep-Warm dollar savings are not applicable and Keep-Warm stays off
VariableDefaultEffect
TOKEN_OPTIMIZER_RUNTIMEclaudeSelect the platform adapter: claude, codex, opencode, copilot, or hermes
TOKEN_OPTIMIZER_SKIP_VERIFYoffSet to 1 to skip checksum verification during script install (not recommended)
TOKEN_OPTIMIZER_STAR_ASKenabledSet to 0 to disable the one-time GitHub star offer entirely
TOKEN_OPTIMIZER_STAR_MIN_SESSIONS3Minimum logged sessions before the one-time star offer’s value-history gate is satisfied
TOKEN_OPTIMIZER_DEBUGoffEmit runtime-detection and refetch-guard diagnostics to stderr
TOKEN_OPTIMIZER_NO_PROC_SCANoffSkip best-effort process-tree scans used as runtime-detection fallbacks
TOKEN_OPTIMIZER_ALLOW_UNSAFE_RUNTIME_HOMEoffFor container layouts, relax only the under-$HOME containment check; absolute, existing, non-symlink directory checks still apply
HERMES_HOME~/.hermesOverride the Hermes home directory for the Hermes adapter
VariableDefaultEffect
TOKEN_OPTIMIZER_ARCHIVE_EXEMPT_TOOLS(unset)Comma-separated fnmatch globs added to the built-in list of MCP tools whose full output stays inline
TOKEN_OPTIMIZER_ARCHIVE_EXEMPT_DEFAULTSenabledSet to off, false, 0, or none to remove the built-in archive exemptions
TOKEN_OPTIMIZER_COST_PER_MTOKmodel-derivedPositive numeric override for the input-token price estimate used by the hook-safe compression-savings path

These controls change estimates, cohort gates, collection bounds, or cache behavior. They are user-settable, but primarily useful for validation and advanced deployments.

VariableDefaultEffect
TOKEN_OPTIMIZER_OVERHEAD_CACHE_TTL3600 secondsTTL for cached structural-overhead calculations
TOKEN_OPTIMIZER_COMPONENTS_CACHE_TTL60 secondsIn-process TTL for repeated component scans
TOKEN_OPTIMIZER_LOOP_CONTINUATION_FACTOR1.0Multiplier applied to measured looped volume for the separately labelled avoided-continuation estimate
TOKEN_OPTIMIZER_COHORT_MIN3Minimum size for each compared cohort in contamination and retrieval estimates
TOKEN_OPTIMIZER_AVG_READ_TOKENS2500Per-avoided-read token estimate used by retrieval savings
TOKEN_OPTIMIZER_AVOIDED_READS_CAP8Per-session cap on avoided reads in the retrieval estimate
TOKEN_OPTIMIZER_ROUTABLE_OPUS_FRACTION0.3Fraction of Opus work treated as routable in the model-routing opportunity calculation
TOKEN_OPTIMIZER_BASELINE_OPUS_SHARE0.0 (unset)Explicit pre-Token-Optimizer Opus share; values outside (0, 1] fall back to measured history
TOKEN_OPTIMIZER_AVOIDABLE_WRITE_FRACTION0.3Share of full-file Writes treated as avoidable in the separately labelled output-waste opportunity
TOKEN_OPTIMIZER_AVOIDABLE_WRITE_TOKENS1500Output-token delta assigned to each avoidable full-file Write opportunity
TOKEN_OPTIMIZER_CACHE_DROP_GAP_SECONDS300Call gap treated as a likely 5-minute cache expiry in cache-drop estimates
TOKEN_OPTIMIZER_BASELINE_ONBOARDING_DAYS1Initial install-period days excluded from baseline construction
TOKEN_OPTIMIZER_BASELINE_WINDOW_DAYS30Early-history window used to construct the baseline
TOKEN_OPTIMIZER_BASELINE_WINSOR_PCT0.99Percentile used to cap high-token sessions in baseline means
TOKEN_OPTIMIZER_BASELINE_MIN_SESSIONS30Minimum sessions required for a stable early-history baseline
TOKEN_OPTIMIZER_AFTER_MIN_SESSIONS10Minimum recent sessions required before trusting the after-window comparison
TOKEN_OPTIMIZER_MIN_INPUT_TOKENS1000Minimum input tokens for a session to enter the interactive-work comparison pool
TOKEN_OPTIMIZER_MIN_DURATION_MINUTES1.0Minimum duration for a session to enter the interactive-work comparison pool
TOKEN_OPTIMIZER_INITIAL_BACKFILL_DAYS365Lookback used by the one-time deep session-history backfill
TOKEN_OPTIMIZER_COLLECT_COMMIT_BATCH200Number of collected sessions committed per backfill batch
TOKEN_OPTIMIZER_COLLECT_MAX_PER_RUN150Maximum newly parsed sessions per collection run; 0 is unbounded
TOKEN_OPTIMIZER_INITIAL_BACKFILL_MAX_ATTEMPTS5Maximum deep-backfill attempts before returning to the rolling window

These names are implementation plumbing, child-process sentinels, generated-script constants, or test seams. They are documented here so the reference covers every TOKEN_OPTIMIZER_* identifier in skills/token-optimizer/scripts/*.py, but they are not presented as user-facing tuning knobs.

NameCode defaultInternal purpose
TOKEN_OPTIMIZER_SNAPSHOT_DIRresolved runtime data directoryTest/sandbox override for snapshot, cache, and decision-log storage
TOKEN_OPTIMIZER_SAFE_ROOTresolved Claude homeTest-only safe root for structure-replay glob expansion; candidates outside the normal root are rejected
TOKEN_OPTIMIZER_PRICING_AS_OFcurrent UTC timePins the pricing date in tests; invalid values fall back to the current time
TOKEN_OPTIMIZER_PRETOOL_OPUSoffExplicit consent gate for applying the 0.95-Opus fallback when no measured baseline exists
TOKEN_OPTIMIZER_SESSION_MODELunknownEvent-time model hint used by compression logging
TOKEN_OPTIMIZER_PLUGIN_DATAruntime-resolvedPlugin-data path passed between runtime adapters
TOKEN_OPTIMIZER_UTF8_REEXECunsetChild-process sentinel that prevents a UTF-8-mode re-exec loop
TOKEN_OPTIMIZER_KEEPWARM_PINGunsetMarks a keep-warm ping child so its Stop hook cannot recursively arm another ping
TOKEN_OPTIMIZER_KEEPWARM_ALLOW_LLM_PINGoffInternal dogfood escape hatch for the token-spending keep-warm LLM ping; absent or false keeps the ping disabled
TOKEN_OPTIMIZER_DAEMON_ENSURE_THROTTLE86400 secondsTest seam for the daemon ensure-attempt throttle
TOKEN_OPTIMIZER_DAEMON_PULSE_PROBE60 secondsTest seam for the daemon pulse health-probe interval
TOKEN_OPTIMIZER_DAEMON_PULSE_REVIVE300 secondsTest seam for the daemon pulse revival interval
TOKEN_OPTIMIZER_DAEMON_VERIFY_TIMEOUT2.0 secondsTest seam for the daemon health-verification retry budget
TOKEN_OPTIMIZER_DAEMON_VERSIONplugin versionConstant embedded in the generated daemon script; not read from the environment
TOKEN_OPTIMIZER_MARKERtoken-optimizer/scriptsPython constant used to recognize installed Codex hook entries; not read from the environment
TOKEN_OPTIMIZER_VERSIONplugin manifest versionPython constant populated from plugin metadata; not read from the environment
TOKEN_OPTIMIZER_CHECKPOINT_TTLunused (former default 300 seconds)Former environment name retained only in a source comment; restore eligibility now uses retention days
TOKEN_OPTIMIZER_PREVENTED_LOOP_ITERATIONS3Parsed into an internal constant that is not referenced elsewhere in the current Python core

The keys below are the persistent equivalents of the runtime flags. Edit through the commands rather than by hand; the table documents what each key holds.

KeyHoldsSet by
v5_bash_compressBash compression on/offv5 enable|disable bash_compress
read_cache_enabledRead cache on/offv5 and read-cache commands
v5_delta_modeDelta mode on/offv5 enable|disable delta_mode
v5_structure_map_betaStructure-map event logging on/offv5 enable|disable structure_map
v5_quality_nudgesQuality nudges on/offv5 enable|disable quality_nudges
v5_loop_detectionLoop detection on/offv5 enable|disable loop_detection
quality_bar_disabledSticky status-line opt-outsetup-quality-bar --uninstall
consent statusData-notice acknowledgmentconsent --grant|--reset
daemon consentBookmarkable-URL consentdaemon-consent --set
pricing tierActive pricing tierpricing-tier <tier>
keep-warm consent and billing modeKeep-Warm enablement statekeepwarm-enable, keepwarm-disable
  1. Command-line flags (for example --context-size) win for the single command.
  2. Environment variables win over config.json for the run.
  3. config.json holds the persistent default.
  4. Engine defaults apply when nothing else is set.

A value marked (verify) anywhere in these docs means the source did not state that detail definitively. None appear in this table; every default above is confirmed against the engine or the platform adapter source.