How isabbir/tokeneconomizer works
TokenEconomizer is a coding-agent plugin that learns repository-specific cost-saving decisions across sessions. Its live path receives agent hooks, identifies repository state, applies micro-skills, tool pruning, and loop-guard interventions, then folds session evidence into future decisions. Agent-specific trace readers and cache-aware pricing support learning and reporting. The repository also contains an experimental benchmark suite with agent harnesses and task runners. Edges follow the supplied source references and excerpts or README descriptions; some experimental subsystems are represented at directory level because their implementation was not sampled.
Main entry points: controller.py Hook controller · fold.py Session fold · swebench.py SWE-Bench runner · context.py Runtime context
Components 22
Live plugin
- Host adapters
tokeneconomizer/plugin/hosts.py - Hook controller
tokeneconomizer/plugin/controller.py - Runtime context
tokeneconomizer/plugin/context.py
Cost mechanisms
- Micro-skills
tokeneconomizer/microskills - Session fold
tokeneconomizer/plugin/fold.py - Tool pruning
tokeneconomizer/toolprune - Agent settings
tokeneconomizer/plugin/denylist.py - Loop guard
tokeneconomizer/loopguard/turn.py - Loop assessment
tokeneconomizer/loopguard/rules.py
Shared services
- Repository state
tokeneconomizer/plugin/repos.py - State paths
tokeneconomizer/plugin/paths.py - Session traces
tokeneconomizer/trace - Cost accounting
tokeneconomizer/plugin/accounting.py - Cache pricing
tokeneconomizer/pricing.py
Experiments
- Codex recovery
experiments/te_bench/codex_spiral.py - Benchmark workloads
experiments/te_bench/workloads.py - SWE-Bench runner
experiments/te_harness/swebench.py - Codex harness
experiments/te_harness/codex.py - Copilot harness
experiments/te_harness/copilot.py - Experiment results
experiments/scripts
Other components
- Developer
- Coding agent
Connections 25
- Developer → Coding agent: starts sessions
README.md - Coding agent → Host adapters: emits hooks
tokeneconomizer/plugin/hosts.py - Host adapters → Hook controller: dispatches events
tokeneconomizer/plugin/controller.py - Hook controller → Runtime context: builds context
tokeneconomizer/plugin/controller.py - Runtime context → Repository state: resolves repository
tokeneconomizer/plugin/context.py - Runtime context → State paths: selects state paths
tokeneconomizer/plugin/context.py - Hook controller → Micro-skills: injects learned facts
README.md - Hook controller → Loop guard: checks tool turns
tokeneconomizer/plugin/controller.py - Loop guard → Loop assessment: assesses progress
tokeneconomizer/loopguard/turn.py - Coding agent → Session traces: writes session logs
tokeneconomizer/trace/__init__.py - Hook controller → Session fold: starts session fold
tokeneconomizer/plugin/controller.py - Session fold → Session traces: reads session traces
tokeneconomizer/plugin/fold.py - Session fold → Micro-skills: updates learned facts
tokeneconomizer/plugin/fold.py - Session fold → Tool pruning: evaluates tool use
tokeneconomizer/plugin/fold.py - Tool pruning → Agent settings: proposes removals
tokeneconomizer/plugin/denylist.py - Agent settings → Coding agent: configures loaded tools
README.md - Session fold → Cost accounting: records cost
tokeneconomizer/plugin/fold.py - Cost accounting → Cache pricing: weights token usage
- Benchmark workloads → SWE-Bench runner: supplies tasks
- SWE-Bench runner → Codex harness: runs agent variant
experiments/te_harness/swebench.py - SWE-Bench runner → Copilot harness: runs agent variant
experiments/te_harness/swebench.py - SWE-Bench runner → Codex recovery: uses Codex recovery
experiments/te_harness/swebench.py - Codex harness → Cache pricing: accounts token cost
experiments/te_harness/codex.py - Copilot harness → Cache pricing: accounts token cost
experiments/te_harness/copilot.py - SWE-Bench runner → Experiment results: produces measurements