Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# TokenEconomizer

A plugin for Claude Code, Codex, the Copilot CLI and Pi (experimentally opencode, Cursor, Grok Build
and Hermes Agent) that reads finished sessions and changes what later sessions in the same repository pay
for: micro-skills, tool pruning, and a loop guard.
A plugin for Claude Code, Codex, the Copilot CLI and Pi (experimentally opencode, Cursor, Grok Build,
Hermes Agent and the Antigravity CLI) that reads finished sessions and changes what later sessions
in the same repository pay for: micro-skills, tool pruning, and a loop guard.
See `README.md` for the overview and the method, `docs/PLUGIN.md` for the design and the verified
agent behavior, and `docs/ARCHITECTURE.md` for how the package fits together.

Expand All @@ -12,7 +12,7 @@ agent behavior, and `docs/ARCHITECTURE.md` for how the package fits together.
- `toolprune/` — unused-tool evidence and the deny-list proposal; Codex capability packages
- `loopguard/` — the per-call failure-loop guard and its per-repository envelope
- `trace/` — each agent's session-log format (Claude Code, Codex, Copilot CLI, Pi, opencode,
Cursor, Grok Build, Hermes Agent)
Cursor, Grok Build, Hermes Agent, Antigravity CLI)
- `plugin/` — the runtime: hook dispatch, per-repository state, settings, the `te` CLI
- `config.py`, `ledger.py`, `pricing.py`, `domain.py`, `stage.py` — shared by all three
- `plugin/` — the installable plugin directory: manifests per agent, hook files, launchers
Expand Down
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ mechanisms:
itself.

TokenEconomizer is a plugin for **Claude Code**, **Codex**, the **GitHub Copilot CLI** and **Pi**,
with experimental support for **opencode**, **Cursor Agent**, **Grok Build** and **Hermes Agent**. Each italic
with experimental support for **opencode**, **Cursor Agent**, **Grok Build**, **Hermes Agent** and
the **Antigravity CLI**. Each italic
letter above is a setting, shown with its default ([Settings](#settings)), and each mechanism can be turned on or
off. The plugin announces each action in one line, and if any part of it fails, your session
carries on as if it were not installed. Its model calls (the fact proposer, and the judge with the
Expand Down Expand Up @@ -192,6 +193,21 @@ Confirm `tokeneconomizer` is enabled in `grok plugin list`, start `grok`, and ch
The learned facts arrive with the session's first tool call, not at its start
([its limits](plugin/README.md#grok-build)).

**Antigravity CLI** (`agy`; experimental; micro-skills' LLM-free facts only)

```sh
python scripts/build_plugin.py --out dist/marketplace
agy plugin install dist/marketplace/tokeneconomizer
```

Start `agy` and send a prompt in a repository, then check with
`~/.tokeneconomizer/bin/te --host antigravity status`. `agy` has no plugin commands, so the
plugin's commands run from a terminal. The plugin makes no model call through `agy`, which has no
option that runs a prompt with every tool off, so the paid proposer and the loop guard are off
and tool pruning is not available. macOS and Linux only:
on Windows `agy` runs hook commands through `cmd /c`, and this plugin's launcher is a POSIX shell
script. See [its limits](plugin/README.md#antigravity-cli).

**opencode** (experimental)

```sh
Expand Down Expand Up @@ -228,6 +244,7 @@ To update:
|---|---|
| Claude Code, Copilot CLI, opencode | `git pull` in the clone |
| Hermes Agent | `git pull` in the clone, then `hermes gateway restart` |
| Antigravity CLI | build the bundle again and `agy plugin install` it |
| Codex | `git pull` in the clone, then the `codex plugin add` line again |
| Pi | `pi update --extensions` |

Expand All @@ -246,6 +263,7 @@ uninstalling, using Copilot with your own model key, and troubleshooting.
| Grok Build (experimental) | 1.0.70 | not tested |
| opencode (experimental) | 1.19.5 and 2.2.0 | not tested |
| Hermes Agent (experimental) | 0.22.5 | not tested |
| Antigravity CLI (experimental) | agy 1.5.1, macOS and Linux | not tested |

The commands above were tested on the oldest and newest version in each range; newer versions
have not been tested yet.
Expand All @@ -265,6 +283,9 @@ have not been tested yet.
- **Grok Build** support is experimental: it was verified on 1.0.70 only, against its documented
hook contract and live hook payloads. Learned facts reach the model with the session's first tool
call, and tool pruning is not available. See [its limits](plugin/README.md#grok-build).
- **Antigravity CLI** support is experimental: it was written against agy 1.5.1's hook contract
and transcript format, which are not a public interface, and only micro-skills' LLM-free facts
are supported: the plugin makes no model call through `agy`. See [its limits](plugin/README.md#antigravity-cli).
- **Hermes Agent** support is experimental: it was tested on 0.22.5 only, with a scripted local
model and one free real model, on the classic CLI and one-shot runs only. Micro-skills and a
redirect reaching a real model are verified there; the still-stuck notice reaching a person is
Expand All @@ -286,13 +307,14 @@ commands. They have the same names on every agent; only the way you type them di
| Cursor Agent | from a terminal: `~/.tokeneconomizer/bin/te --host cursor <command>` |
| Grok Build | from a terminal: `~/.tokeneconomizer/bin/te --host grok <command>` |
| Hermes Agent | from a terminal: `~/.tokeneconomizer/bin/te --host hermes <command>` |
| Antigravity CLI | from a terminal: `~/.tokeneconomizer/bin/te --host antigravity <command>` |
| a terminal, in the repository | `~/.tokeneconomizer/bin/te <command>` |

| Command | What it does |
|---|---|
| `status` | what it learned and did here, and what your sessions cost |
| `microskills` | the facts it injects, and those still forming |
| `toolprune` | the tools it left out, and the evidence (not on Pi, opencode or Hermes Agent) |
| `toolprune` | the tools it left out, and the evidence (not on Pi, opencode, Hermes Agent or the Antigravity CLI) |
| `toolprune restore` | give them back; they will not be removed again |
| `config` | every setting in effect |
| `config set microskills=on` | turn a mechanism on (or `=off`) in this repository; add `--global` for every repository |
Expand Down Expand Up @@ -375,6 +397,7 @@ what it can leave out differs:
| Grok Build | nothing yet | — |
| opencode | nothing yet | — |
| Hermes Agent | nothing yet | — |
| Antigravity CLI | nothing yet | — |

Tool pruning adds only its own entries and never touches deny rules you wrote; a settings file it
creates is kept out of git (`.git/info/exclude`). On Claude Code, the session-start line that says
Expand Down
21 changes: 20 additions & 1 deletion docs/PLUGIN.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# The plugin: design and verified agent behaviour

How the plugin runs the three mechanisms inside your own Claude Code, Codex, Copilot CLI, Pi,
opencode, Cursor, Grok Build and Hermes Agent sessions, through the hooks (on Pi, the extension events) each agent
opencode, Cursor, Grok Build, Hermes Agent and Antigravity CLI sessions, through the hooks (on Pi, the extension events) each agent
exposes: what it does at each hook, what differs from the experiments and why, the agent
behaviour each choice rests on, where its state lives, and its known limitations. The code is `tokeneconomizer/plugin/` (what
the hooks run) and `plugin/` (the packaging for each agent). To install and use it, see
Expand Down Expand Up @@ -763,6 +763,25 @@ open-vocabulary. On a repository you do not trust, leave micro-skills off (the d
* **Hermes Agent** — experimental: micro-skills and the loop guard, on the classic CLI and one-shot
runs, verified with a scripted model and one free real model. Its limits are listed in
`plugin/README.md`.
* **Antigravity CLI (`agy`, experimental)** — micro-skills' LLM-free facts, written against
agy 1.5.1 and its own installed hook documentation; tool pruning is not implemented. The
plugin makes no model call through `agy`, which has no option that runs a prompt with every tool
off (`sidecall.NO_SIDE_CALLS`), so the paid proposer and the loop guard's judge never run. What
was captured live: hooks come from a `hooks.json` at the plugin root, run through `sh -c` in
that directory, with camelCase payloads that name no event (the hook file's command does,
`--event`) and leave out a zero (`invocationNum` 0, the first model call of a prompt). A
`PreToolUse` hook that prints `{}` makes agy deny the tool, so none is registered;
`PostToolUse` carries no tool result and a matcher `"*"` never matches, so the results are read
from the conversation's `transcript_full.jsonl` at the next `PreInvocation` and at `Stop`, where
every result of the previous model call is already written (`trace/antigravity.py`). There is no
prompt event and no `SessionEnd`: a prompt is the `PreInvocation` with `invocationNum` 0, and a
conversation is folded by the next session start in its repository once its transcript has been
quiet for ten minutes. Context goes back as `injectSteps`: a persistent `systemMessage` at
`SessionStart`, an `ephemeralMessage` (dropped after the turn) at `PreInvocation`. Calls a subagent
makes are not in the transcript and are not seen. Transcript token fields are absent from older
agy versions (unknown, not zero), and the transcript names no model, so session cost is priced
on the ledger's labelled fallback. macOS and Linux only: agy runs hook commands through
`cmd /c` on Windows, and the launcher is a POSIX shell script.
* **Known gaps:**
* `codex exec` prints no hook messages, so a headless Codex run shows no notice; `te status`
counts it afterwards. On Claude Code the notice reaches the conversation and `claude -p`'s
Expand Down
10 changes: 10 additions & 0 deletions plugin/.antigravity-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "tokeneconomizer",
"version": "0.1.0",
"description": "Learn repository facts and redirect coding-agent turns that appear stuck.",
"author": {
"name": "TokenEconomizer authors"
},
"repository": "https://github.com/microsoft/TokenEconomizer",
"license": "Apache-2.0"
}
47 changes: 45 additions & 2 deletions plugin/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# TokenEconomizer plugin

How to install and use TokenEconomizer in Claude Code, Codex, the GitHub Copilot CLI, Pi, Cursor
(experimental), Grok Build (experimental), opencode (experimental) and Hermes Agent (experimental). What the plugin does and why is in the [main README](../README.md); its
(experimental), Grok Build (experimental), opencode (experimental), Hermes Agent (experimental)
and the Antigravity CLI (experimental). What the plugin does and why is in the [main README](../README.md); its
design and the verified behaviour of each agent are in [`docs/PLUGIN.md`](../docs/PLUGIN.md).

- [Before you start](#before-you-start)
- Install and use it on [Claude Code](#claude-code) · [Codex](#codex) ·
[Copilot CLI](#copilot-cli) · [Pi](#pi) · [Cursor](#cursor) · [Grok Build](#grok-build) · [opencode](#opencode) ·
[Hermes Agent](#hermes-agent)
[Hermes Agent](#hermes-agent) · [Antigravity CLI](#antigravity-cli)
- [What to expect](#what-to-expect) · [Commands](#commands) · [Settings](#settings)
- [Repository map](#repository-map) · [Using with rtk](#using-with-rtk) ·
[Model calls and API keys](#model-calls-and-api-keys) · [Troubleshooting](#troubleshooting)
Expand Down Expand Up @@ -539,6 +540,47 @@ log a warning for the empty section of a session with no facts.
**Uninstall.** `hermes plugins disable tokeneconomizer`, `rm ~/.hermes/plugins/tokeneconomizer`,
`hermes gateway restart`. Optional: `rm -rf ~/.tokeneconomizer`.


## Antigravity CLI

Experimental: **micro-skills' LLM-free facts**, written against `agy` 1.5.1 on macOS and Linux
(agy runs hook commands through `cmd /c` on Windows, and the launcher is a POSIX shell script).

**1. Install.** Build the self-contained plugin, which copies the package into it, and install the
directory:

```bash
python scripts/build_plugin.py --out dist/marketplace
agy plugin install dist/marketplace/tokeneconomizer
```

`agy plugin validate dist/marketplace/tokeneconomizer` checks it. agy reads the plugin's hooks
from `hooks.json` at the plugin root; the `hooks/hooks.json` beside it is Claude Code's, and agy's
validator says it is never loaded.

**2. Check it.** Run a session, then `~/.tokeneconomizer/bin/te --host antigravity status` in the
repository. agy plugins load no slash commands, so every command runs from a terminal. Micro-skills
is off by default: `te --host antigravity config set microskills=envfacts`.

**How it works, and what it does not do.**

- Three hooks are registered: `SessionStart` (injects the learned facts), `PreInvocation` (before
every model call: opens a turn at a new prompt and reads the tool results since the last call)
and `Stop`.
- It never registers `PreToolUse`: a `PreToolUse` hook that prints `{}` makes agy deny the tool.
`PostToolUse` is unused: its payload holds no tool result, so the results are read from the
conversation's `transcript_full.jsonl` instead. A cursor into it is kept in
`~/.tokeneconomizer/antigravity-sessions/`, private to you.
- agy has no `SessionEnd`: a conversation is folded by the next session start in that repository,
once its transcript has been quiet for 10 minutes.
- Tool pruning is not available. Calls a subagent makes are not in the transcript and are not seen.
The transcript names no model, so session cost is priced on a labelled fallback, and older agy
versions leave token counts out of most of it.
- The plugin makes no model call through `agy`: it has no option that runs a prompt with every
tool off, and such a call's prompt holds text a repository controls. So micro-skills' paid
proposer never runs, and the loop guard, which needs a judge's verdict to act, never redirects
a turn.

## What to expect

The plugin works session by session: what it learns from a repository's earlier sessions is
Expand Down Expand Up @@ -623,6 +665,7 @@ How to run them:
| opencode | none (run from a terminal) | `~/.tokeneconomizer/bin/te --host opencode <command>` |
| Grok Build | none (run from a terminal) | `~/.tokeneconomizer/bin/te --host grok <command>` |
| Hermes Agent | none (run from a terminal) | `~/.tokeneconomizer/bin/te --host hermes <command>` |
| Antigravity CLI | none (run from a terminal) | `~/.tokeneconomizer/bin/te --host antigravity <command>` |

`doctor`, `history` and `repomap` run from a terminal (or as `/te …` on Pi); there is no slash command or
Codex skill for them.
Expand Down
13 changes: 13 additions & 0 deletions plugin/hooks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"tokeneconomizer": {
"SessionStart": [
{ "type": "command", "command": "./scripts/te-hook --host antigravity --event SessionStart", "timeout": 15 }
],
"PreInvocation": [
{ "type": "command", "command": "./scripts/te-hook --host antigravity --event PreInvocation", "timeout": 10 }
],
"Stop": [
{ "type": "command", "command": "./scripts/te-hook --host antigravity --event Stop", "timeout": 10 }
]
}
}
Loading
Loading