oathe / scan / reports / caution
Is microsoft/TokenEconomizer safe?
Use with caution. microsoft/TokenEconomizer is not clearly unsafe, but the audit flagged risks to review before you install it. Oathe's behavioral security audit gave the TokenEconomizer skill by microsoft a trust score of 73/100 with 11 findings, none critical or high.
https://github.com/microsoft/TokenEconomizer
Is microsoft/TokenEconomizer safe to install?
TokenEconomizer is a legitimate, well-structured Microsoft open-source plugin for AI agent cost optimization that hooks into agent lifecycle events to inject learned repository facts, guard against infinite loops, and prune unused tools. No malicious behavior was observed during this audit — the sensitive file accesses in monitoring data predated the clone by 6 seconds and are attributable to the audit infrastructure itself. The primary concerns are architectural: the plugin runs Python code on every agent event with full filesystem access, injects session-learned content into system prompts via a persistent state store (creating a secondary prompt injection vector if that store were compromised), and can remove agent tool capabilities via toolprune.
What security issues were found in microsoft/TokenEconomizer?
Category Scores
Findings (11)
MEDIUM Microskills system injects session-learned content into agent system prompt -15 ▶
The plugin distills 'micro-skills' from prior agent sessions and injects them as a system-prompt section (tokeneconomizer.facts or SECTION='tokeneconomizer') at the start of each session. If the ~/.tokeneconomizer state store were written by a malicious process, compromised repository, or cross-skill attack, the injected content would appear as trusted first-party context to the agent.
Evidence: SessionStart hook returns hookSpecificOutput.additionalContext which is set as event.systemPromptOptions.sections[SECTION] in pi/tokeneconomizer.ts; Hermes registers it via ctx.register_system_prompt_section(SECTION_ID, bridge.section, position='after_memory', max_chars=4000)
MEDIUM Hook dispatcher injects unvalidated additionalContext into agent system prompt -13 ▶
On every UserPromptSubmit event the hook dispatcher may return additionalContext (e.g., repository maps) that is appended to the agent's system prompt. This content is generated by local Python code and there is no visible sanitization between what the Python layer returns and what enters the prompt.
Evidence: In plugin/pi/tokeneconomizer.ts before_agent_start handler: const extra = out?.hookSpecificOutput?.additionalContext; if (extra) { manual = manual ? ... }; event.systemPromptOptions.sections = { [SECTION]: manual }
MEDIUM envfacts module reads and stores environment facts that may include secrets -15 ▶
tokeneconomizer/microskills/envfacts.py is designed to learn 'facts' about the environment for injection into future sessions. Environment scanning commonly captures environment variables including API keys, tokens, and paths to credential files. These facts are stored persistently in ~/.tokeneconomizer and re-injected into future agent system prompts.
Evidence: File tokeneconomizer/microskills/envfacts.py exists and is part of the microskills pipeline; test_envfacts.py and test_envfacts_args.py confirm this module is a core, tested component
LOW Python hook scripts execute with unrestricted filesystem access on every agent event -13 ▶
The te_bootstrap.py dispatcher runs as a subprocess on every agent lifecycle event with full access to the user's filesystem. While no malicious file reads were observed in this test, the design gives the plugin code the same filesystem permissions as the agent user on every hook invocation.
Evidence: hooks.json, codex-hooks.json, copilot-hooks.json all invoke te_bootstrap.py via shell/Python at every SessionStart, UserPromptSubmit, PostToolUse, Stop, SessionEnd events; te_bootstrap.py is a full Python script with no explicit sandboxing
MEDIUM Plugin runs Python subprocess on every agent lifecycle event -20 ▶
The hook architecture invokes te_bootstrap.py (or the te-hook shell script) as a child process on every agent event. This creates a persistent, high-frequency code execution surface that could accumulate significant cost and latency, and means any vulnerability in the bootstrap script is exploitable on every agent turn.
Evidence: SessionStart timeout=15, UserPromptSubmit timeout=20, PostToolUse timeout=60, Stop timeout=10, SessionEnd timeout=10 — all events trigger subprocess execution per hooks.json and copilot-hooks.json
LOW Obfuscated inline Python in codex-hooks.json commandWindows field -10 ▶
The Windows hook command uses a compact inline Python one-liner with import('os'), import('sys'), and import('runpy').run_path() that is difficult to audit at a glance, though functional analysis shows it correctly bootstraps te_bootstrap.py.
Evidence: codex-hooks.json commandWindows: "python -X --% -u -X utf8 -c e=__import__('os').environ;r=e.get('PLUGIN_ROOT')or(e['CLAUDE_PLUGIN_ROOT']);s=__import__('sys');s.argv[:]=[r+'/scripts/te_bootstrap.py','hook','--host','codex'];__import__('runpy').run_path(s.argv[0],run_name='__main__')"
LOW Long PowerShell one-liners in copilot-hooks.json are difficult to audit -10 ▶
The Windows commands in copilot-hooks.json are 500+ character PowerShell blocks that discover Python interpreters and launch the bootstrap. While functionally legitimate, the density makes code review difficult and could mask subtle malicious logic.
Evidence: copilot-hooks.json windows field begins: "& { $env:PYTHONUTF8 = '1'; $OutputEncoding = [Console]::InputEncoding = [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding; $payload = if ($MyInvocation.ExpectingInput) ..." (500+ chars)
LOW Pre-existing Ubuntu update connections present before clone; absent after -10 ▶
Connections to 185.125.190.48:443 and 185.125.190.109:443 (Ubuntu CDN) appeared in BEFORE snapshot and were gone in AFTER snapshot. These were pre-existing system connections unrelated to the plugin install.
Evidence: BEFORE: tcp ESTAB 10.0.2.15:45994 185.125.190.109:443 and 10.0.2.15:43502 185.125.190.48:443; AFTER: neither connection present
INFO Canary file accesses preceded git clone by 6 seconds — attributable to monitoring setup -10 ▶
Filesystem events show .env, .ssh/id_rsa, .aws/credentials, .npmrc, .docker/config.json, and GCloud credentials were opened at 05:45:02 (timestamp 1795412702). The git clone did not begin until 05:45:08 (1795412708). These accesses occurred in the context of the monitoring infrastructure's sudo process (pid=1103) during audit setup. All canary files confirmed intact.
Evidence: type=PATH msg=audit(1795412702.627:267-272) for all sensitive files; git clone EXECVE at audit(1795412708.145:507); canary integrity check: ✅ All canary files intact
MEDIUM toolprune capability allows plugin to remove agent tool capabilities -20 ▶
The plugin's toolprune mechanism writes deny-lists to .codex/config.toml and .claude/settings.local.json to disable agent capabilities the plugin has decided are unused. While user-confirmable, this means the plugin can progressively restrict the agent's available tools across sessions based on its own heuristics.
Evidence: SKILL.md toolprune section: 'apply and restore edit the project's .codex/config.toml and record the change in TokenEconomizer's own state'; tokeneconomizer/toolprune/stage.py and tools.py implement the denial mechanism
LOW Session transcripts stored locally and analyzed for pattern learning -15 ▶
The fold mechanism reads complete session transcripts (including all tool calls and results) after sessions end, extracts patterns, and stores them in ~/.tokeneconomizer for future injection. Sessions may contain sensitive file contents, API responses, credentials, or business logic.
Evidence: tokeneconomizer/plugin/fold.py processes session transcripts; tokeneconomizer/microskills/distiller.py extracts learnable facts; session JSON files stored in ~/.tokeneconomizer/opencode-sessions/ and ~/.tokeneconomizer/hermes-sessions/
Should I install microsoft/TokenEconomizer?
Oathe's verdict for microsoft/TokenEconomizer is CAUTION with a trust score of 73/100. Recommendation: Install with caution.