@alexgreensh/token-optimizer 5.13.50 → 5.13.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1262,6 +1262,26 @@ def _antigravity_signal() -> bool:
1262
1262
  return _ancestor_in_process_tree(_AGY_BASENAMES)
1263
1263
 
1264
1264
 
1265
+ def _codex_plugin_env_signal() -> bool:
1266
+ """True when CLAUDE_PLUGIN_ROOT / CLAUDE_PLUGIN_DATA point inside Codex's
1267
+ plugins dir (``<codex home>/plugins/``): a hook Codex loaded from the
1268
+ plugin's hooks.json. Never raises."""
1269
+ try:
1270
+ base = (codex_home() / "plugins").resolve(strict=False)
1271
+ for var in _CLAUDE_PLUGIN_ENVS:
1272
+ raw = os.environ.get(var, "").strip()
1273
+ if not raw:
1274
+ continue
1275
+ try:
1276
+ Path(raw).expanduser().resolve(strict=False).relative_to(base)
1277
+ return True
1278
+ except (ValueError, OSError, RuntimeError):
1279
+ continue
1280
+ except Exception:
1281
+ return False
1282
+ return False
1283
+
1284
+
1265
1285
  @functools.lru_cache(maxsize=None)
1266
1286
  def detect_runtime() -> str:
1267
1287
  """Return the active runtime name.
@@ -1325,6 +1345,16 @@ def detect_runtime() -> str:
1325
1345
  if _opencode_process_signal():
1326
1346
  return _RUNTIME_OPENCODE
1327
1347
 
1348
+ # Codex loads the plugin's own hooks/hooks.json and hands each hook ONLY
1349
+ # CLAUDE_PLUGIN_ROOT / CLAUDE_PLUGIN_DATA (no CODEX_HOME, no override;
1350
+ # verified live, see tests/test_codex_sessionstart_json_contract.py). Both
1351
+ # point inside Codex's plugins dir, which no Claude Code plugin uses, so
1352
+ # they name Codex before the Claude plugin-env tier below claims them.
1353
+ # Without this, a Codex session wrote its state into ~/.claude and pointed
1354
+ # Claude Code's statusLine at the Codex plugin cache.
1355
+ if _codex_plugin_env_signal():
1356
+ return _RUNTIME_CODEX
1357
+
1328
1358
  if any(os.environ.get(env_var) for env_var in _CLAUDE_PLUGIN_ENVS):
1329
1359
  return _RUNTIME_CLAUDE
1330
1360