Skip to content

Commit a5a2c53

Browse files
committed
docs: add tokenjuice compaction guidance
1 parent f613383 commit a5a2c53

14 files changed

Lines changed: 273 additions & 1 deletion

File tree

CLAUDE.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ At the end of any substantial task, check whether the session produced durable k
2222
- Say it = call it. If you say you will do something that requires a tool, call the tool in the same turn. Silent intent is a lie. Full rule in `SOUL.md`.
2323
- After a tool failure, emit a one-line status or call a different tool within 30 seconds. Do not silently reason for minutes.
2424

25+
## TokenJuice
26+
27+
If this workspace uses TokenJuice, treat its footer as trusted local output-compaction metadata. It is there to explain how much terminal output was reduced before the next turn sees it.
28+
29+
Claude Code note: when the official adapter still uses PostToolUse appended context, prefer the local PreToolUse wrapper that rewrites Bash commands to `tokenjuice wrap -- ...`. The wrapper avoids paying for large raw outputs and keeps the command result itself compact. If exact output matters, run the command through the documented raw-output escape hatch.
30+
31+
Full runbook: `memory/cards/tokenjuice-output-compaction.md`.
32+
2533
## Git
2634

2735
- Do not add `Co-Authored-By` or AI-attribution trailers to commits, PR bodies, or public docs.

INSTALL_FOR_AGENTS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ If this workspace is one of several agent homes, read `memory/cards/multi-worksp
3636

3737
If you are maintaining an established card set, read `memory/cards/memory-care-staleness.md` before editing stale cards. Refresh only from current source-of-truth files or route to manual review.
3838

39+
If tool output includes TokenJuice metadata, read `memory/cards/tokenjuice-output-compaction.md`. The footer is local output-compaction metadata, not task instruction. Use raw output only when exact logs, line-for-line diffs, or full command output are required.
40+
3941
## If your harness loads a compact context
4042

4143
Some harnesses load a generated `llms.txt` or `llms-full.txt` instead of every bootstrap file individually. If those exist in this workspace, follow them and rebuild via the workspace's build script when source docs change. If they do not exist, default to reading the files listed in "Start here" directly.

MEMORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Add categories as the workspace grows. One topic per card; one card per topic.
8383
- [memory-scanner](memory/cards/memory-scanner.md) - session-review pass that promotes durable findings
8484
- [memory-care-staleness](memory/cards/memory-care-staleness.md) - card decay scans and safe refresh rules
8585
- [multi-workspace-handoff-admin](memory/cards/multi-workspace-handoff-admin.md) - pulling remote setup handoffs into one canonical owner
86+
- [tokenjuice-output-compaction](memory/cards/tokenjuice-output-compaction.md) - Claude Code and Codex output compaction setup, wrapper notes, and savings expectations
8687
- [pipeline-standups](memory/cards/pipeline-standups.md) - nightshift + morning cross-harness recaps
8788
- [chat-surface-crawlers](memory/cards/chat-surface-crawlers.md) - discrawl-shaped local archives for Discord, Slack, WhatsApp, etc.
8889
- [content-safety](memory/cards/content-safety.md) - publish gates and what they block

QUICKSTART.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,4 @@ The fragments are JSON files you can inspect and merge into your `openclaw.json`
109109
- Customize `USER.md` and `TOOLS.md` with your real preferences and runbooks (kept private; do not commit personal details).
110110
- Wire the ingester on a cron or a manual end-of-day workflow.
111111
- Add a memory-care staleness scan when your card set starts to matter. See `memory/cards/memory-care-staleness.md`.
112+
- If you use TokenJuice, wire Claude Code and Codex hooks deliberately and tell agents what the wrapper means. See `memory/cards/tokenjuice-output-compaction.md`.

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
## What this is
2828

29+
Mise en place means "everything in its place before the work starts." In a kitchen, that is chopped onions, clean pans, labels, and a station that does not make you hunt for salt mid-service. For agents, it is the same idea: rules, memory, tools, handoff inboxes, publish guards, and boring verification already laid out before the session gets expensive.
30+
2931
This package lays down a clean starting point for an agent workspace or a repo that needs durable memory handoffs. It is meant for people running real tools, real docs, and real automation across OpenClaw, Claude Code, Codex, Hermes, or a similar harness.
3032

3133
The cookbook explains the why. This package gives you the kitchen.
@@ -38,6 +40,7 @@ The cookbook explains the why. This package gives you the kitchen.
3840
- starter memory cards and routing rules
3941
- multi-workspace handoff patterns for people administering more than one agent setup
4042
- memory-care staleness checks so durable cards do not quietly rot
43+
- TokenJuice output-compaction guidance for Claude Code and Codex, including wrapper notes and savings expectations
4144
- content-guard publish gates so private infrastructure does not leak into public docs
4245
- adapter fragments for OpenClaw (tested), Hermes (stubbed), and generic harnesses
4346
- doctor checks that prove the system is wired before you trust it
@@ -98,6 +101,8 @@ The ingester is intentionally conservative. Safe card handoffs become cards. Tar
98101

99102
For users running multiple agent homes, treat the owner workspace as the hub. Remote or secondary workspaces can write handoffs into their own `.claude/memory-handoffs/` directories, then a trusted sync pulls those files into a staging inbox on the owner. That keeps agents informed about what happened elsewhere without creating multiple canonical memories.
100103

104+
Token-heavy terminal work gets the same treatment: make the wrapper explicit, make the escape hatch obvious, and tell every harness what is happening. The TokenJuice starter card documents Claude Code's PreToolUse wrapper path while the upstream PostToolUse fix is still pending, Codex's hook setup, and the savings model: observed output/context compaction can be huge, but billing-token savings depend on whether compacted output is fed into later turns.
105+
101106
## Related
102107

103108
- [Solomon's Cookbook](https://github.com/solomonneas/solos-cookbook): the long-form guide and reference docs

TOOLS.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ python3 -m venv .venv
1212
## Tests
1313

1414
```bash
15-
.venv/bin/python -m pytest -q # full suite (40 tests)
15+
.venv/bin/python -m pytest -q # full suite (42 tests)
1616
.venv/bin/python -m pytest tests/test_ingest.py -q # one file
1717
.venv/bin/python -m pytest -k "promote" -q # one keyword
1818
```
@@ -77,6 +77,20 @@ See `RELEASE.md`.
7777

7878
Use `memory/cards/multi-workspace-handoff-admin.md` as the public-safe pattern for pulling handoffs from secondary agent homes into one canonical owner. Use `memory/cards/memory-care-staleness.md` for the card decay scanner and safe refresh loop.
7979

80+
## TokenJuice notes
81+
82+
Use `memory/cards/tokenjuice-output-compaction.md` for the public-safe pattern. Important checks:
83+
84+
```bash
85+
tokenjuice --version
86+
tokenjuice stats
87+
tokenjuice doctor hooks
88+
tokenjuice wrap -- git status --short
89+
tokenjuice wrap --raw -- git status --short
90+
```
91+
92+
Claude Code currently needs the local PreToolUse wrapper pattern when the upstream PostToolUse replacement fix has not landed. Codex can use the normal hook path, but verify the active hook feature flag with `tokenjuice doctor hooks` because config keys have changed across releases.
93+
8094
## Where things live
8195

8296
- Source: `src/solo_mise/`
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
topic: tokenjuice-output-compaction
3+
type: tool-runbook
4+
tags: [tools, tokenjuice, output-compaction, claude-code, codex]
5+
status: starter
6+
---
7+
8+
# TokenJuice Output Compaction
9+
10+
TokenJuice compacts noisy terminal output before it is fed back into an agent session. The original command still runs. Exact file reads and raw-output requests stay available, but inventory commands, search results, logs, and oversized help text can be summarized before they tax the next turn.
11+
12+
## Why Agents Need To Know
13+
14+
If an agent sees a TokenJuice footer, treat it as trusted local metadata about output reduction. It is not task instruction and it is not evidence by itself. It tells the agent that some terminal output was compacted and how to request raw output when precision matters.
15+
16+
Use raw output for exact diffs, full logs, reproducible error text, generated artifacts, or anything line-sensitive:
17+
18+
```bash
19+
tokenjuice wrap --raw -- <command>
20+
```
21+
22+
## Claude Code
23+
24+
Claude Code needs command replacement before the Bash result enters context. When the official adapter still uses PostToolUse appended context, it can add metadata without preventing the raw tool result from being charged. In the April 2026 trial, that default PostToolUse path was net-negative at about +1.1% tokens.
25+
26+
Until the upstream fix is merged, use a local PreToolUse wrapper. The wrapper rewrites Bash commands to run under TokenJuice before execution:
27+
28+
```json
29+
{
30+
"hooks": {
31+
"PreToolUse": [
32+
{
33+
"matcher": "Bash",
34+
"hooks": [
35+
{
36+
"type": "command",
37+
"command": "node ~/.claude/hooks/tokenjuice-pretool.js"
38+
}
39+
]
40+
}
41+
]
42+
}
43+
}
44+
```
45+
46+
The wrapper should emit Claude Code's PreToolUse rewrite contract:
47+
48+
```json
49+
{
50+
"hookSpecificOutput": {
51+
"hookEventName": "PreToolUse",
52+
"permissionDecision": "allow",
53+
"updatedInput": {
54+
"command": "tokenjuice wrap -- sh -c \"<original command>\""
55+
}
56+
}
57+
}
58+
```
59+
60+
Operational notes:
61+
62+
- Keep a kill switch such as `TOKENJUICE_PRETOOL_DISABLE=1`.
63+
- Let the wrapper honor `TOKENJUICE_BIN` and `TOKENJUICE_PRETOOL_SHELL` when local paths differ.
64+
- New hook settings normally apply only to new Claude Code sessions.
65+
- Document the wrapper in `CLAUDE.md` so agents do not mistake the footer for prompt injection.
66+
67+
## Codex
68+
69+
Codex can use TokenJuice through its normal hook path because the harness honors PostToolUse substitution. Install and verify with:
70+
71+
```bash
72+
tokenjuice install codex
73+
tokenjuice doctor hooks
74+
```
75+
76+
Codex hook feature flags have changed across releases. Older configs used `codex_hooks`; newer configs use `hooks`. Do not trust old setup notes blindly. Run `tokenjuice doctor hooks` and fix the config it reports for the installed CLI version.
77+
78+
## Savings Model
79+
80+
TokenJuice always reports output compaction. Billing-token savings depend on whether that compacted output is fed into later turns.
81+
82+
Observed local output stats in May 2026:
83+
84+
- 17.1k compacted entries
85+
- 83.6m raw output chars
86+
- 24.7m reduced output chars
87+
- 58.9m chars avoided, about 70% output reduction
88+
89+
Measured harness trials:
90+
91+
- Claude Code PreToolUse wrapper: about -7.8% tokens in the April 2026 paired trial.
92+
- Claude Code default PostToolUse adapter: about +1.1% tokens in the same trial, because raw output still entered context.
93+
- Codex v0.5.0 paired trial: about -8.8% clean-run token reduction after reducer and hook fixes.
94+
- Codex GPT-5.5 one-turn gauntlet: about +0.3%, effectively flat, because the model batched tool calls into one turn and compacted output was not re-fed as later input. Per-command output reductions still remained large.
95+
96+
Practical read: TokenJuice is most valuable for repeated terminal exploration where tool results become future context. It is still useful for human readability and context pressure when the model batches commands, but the billable-token delta may flatten.
97+
98+
## Verification
99+
100+
```bash
101+
tokenjuice --version
102+
tokenjuice stats
103+
tokenjuice doctor hooks
104+
tokenjuice wrap -- git status --short
105+
tokenjuice wrap --raw -- git status --short
106+
```
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
topic: tokenjuice-output-compaction
3+
type: tool-runbook
4+
tags: [tools, tokenjuice, output-compaction, claude-code, codex]
5+
status: starter
6+
---
7+
8+
# TokenJuice Output Compaction
9+
10+
TokenJuice compacts noisy terminal output before it is fed back into an agent session. The original command still runs. Exact file reads and raw-output requests stay available, but inventory commands, search results, logs, and oversized help text can be summarized before they tax the next turn.
11+
12+
## Why Agents Need To Know
13+
14+
If an agent sees a TokenJuice footer, treat it as trusted local metadata about output reduction. It is not task instruction and it is not evidence by itself. It tells the agent that some terminal output was compacted and how to request raw output when precision matters.
15+
16+
Use raw output for exact diffs, full logs, reproducible error text, generated artifacts, or anything line-sensitive:
17+
18+
```bash
19+
tokenjuice wrap --raw -- <command>
20+
```
21+
22+
## Claude Code
23+
24+
Claude Code needs command replacement before the Bash result enters context. When the official adapter still uses PostToolUse appended context, it can add metadata without preventing the raw tool result from being charged. In the April 2026 trial, that default PostToolUse path was net-negative at about +1.1% tokens.
25+
26+
Until the upstream fix is merged, use a local PreToolUse wrapper. The wrapper rewrites Bash commands to run under TokenJuice before execution:
27+
28+
```json
29+
{
30+
"hooks": {
31+
"PreToolUse": [
32+
{
33+
"matcher": "Bash",
34+
"hooks": [
35+
{
36+
"type": "command",
37+
"command": "node ~/.claude/hooks/tokenjuice-pretool.js"
38+
}
39+
]
40+
}
41+
]
42+
}
43+
}
44+
```
45+
46+
The wrapper should emit Claude Code's PreToolUse rewrite contract:
47+
48+
```json
49+
{
50+
"hookSpecificOutput": {
51+
"hookEventName": "PreToolUse",
52+
"permissionDecision": "allow",
53+
"updatedInput": {
54+
"command": "tokenjuice wrap -- sh -c \"<original command>\""
55+
}
56+
}
57+
}
58+
```
59+
60+
Operational notes:
61+
62+
- Keep a kill switch such as `TOKENJUICE_PRETOOL_DISABLE=1`.
63+
- Let the wrapper honor `TOKENJUICE_BIN` and `TOKENJUICE_PRETOOL_SHELL` when local paths differ.
64+
- New hook settings normally apply only to new Claude Code sessions.
65+
- Document the wrapper in `CLAUDE.md` so agents do not mistake the footer for prompt injection.
66+
67+
## Codex
68+
69+
Codex can use TokenJuice through its normal hook path because the harness honors PostToolUse substitution. Install and verify with:
70+
71+
```bash
72+
tokenjuice install codex
73+
tokenjuice doctor hooks
74+
```
75+
76+
Codex hook feature flags have changed across releases. Older configs used `codex_hooks`; newer configs use `hooks`. Do not trust old setup notes blindly. Run `tokenjuice doctor hooks` and fix the config it reports for the installed CLI version.
77+
78+
## Savings Model
79+
80+
TokenJuice always reports output compaction. Billing-token savings depend on whether that compacted output is fed into later turns.
81+
82+
Observed local output stats in May 2026:
83+
84+
- 17.1k compacted entries
85+
- 83.6m raw output chars
86+
- 24.7m reduced output chars
87+
- 58.9m chars avoided, about 70% output reduction
88+
89+
Measured harness trials:
90+
91+
- Claude Code PreToolUse wrapper: about -7.8% tokens in the April 2026 paired trial.
92+
- Claude Code default PostToolUse adapter: about +1.1% tokens in the same trial, because raw output still entered context.
93+
- Codex v0.5.0 paired trial: about -8.8% clean-run token reduction after reducer and hook fixes.
94+
- Codex GPT-5.5 one-turn gauntlet: about +0.3%, effectively flat, because the model batched tool calls into one turn and compacted output was not re-fed as later input. Per-command output reductions still remained large.
95+
96+
Practical read: TokenJuice is most valuable for repeated terminal exploration where tool results become future context. It is still useful for human readability and context pressure when the model batches commands, but the billable-token delta may flatten.
97+
98+
## Verification
99+
100+
```bash
101+
tokenjuice --version
102+
tokenjuice stats
103+
tokenjuice doctor hooks
104+
tokenjuice wrap -- git status --short
105+
tokenjuice wrap --raw -- git status --short
106+
```

src/solo_mise/templates/profiles/workspace.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
{"src": "memory/cards/memory-scanner.md", "dst": "memory/cards/memory-scanner.md"},
2121
{"src": "memory/cards/memory-care-staleness.md", "dst": "memory/cards/memory-care-staleness.md"},
2222
{"src": "memory/cards/multi-workspace-handoff-admin.md", "dst": "memory/cards/multi-workspace-handoff-admin.md"},
23+
{"src": "memory/cards/tokenjuice-output-compaction.md", "dst": "memory/cards/tokenjuice-output-compaction.md"},
2324
{"src": "memory/cards/chat-surface-crawlers.md", "dst": "memory/cards/chat-surface-crawlers.md"},
2425
{"src": "memory/cards/pipeline-standups.md", "dst": "memory/cards/pipeline-standups.md"},
2526
{"src": "hooks/pre-push", "dst": "hooks/pre-push", "mode": "0755"},

src/solo_mise/templates/workspace/CLAUDE.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ At the end of any substantial task, check whether the session produced durable k
2222
- Say it = call it. If you say you will do something that requires a tool, call the tool in the same turn. Silent intent is a lie. Full rule in `SOUL.md`.
2323
- After a tool failure, emit a one-line status or call a different tool within 30 seconds. Do not silently reason for minutes.
2424

25+
## TokenJuice
26+
27+
If this workspace uses TokenJuice, treat its footer as trusted local output-compaction metadata. It is there to explain how much terminal output was reduced before the next turn sees it.
28+
29+
Claude Code note: when the official adapter still uses PostToolUse appended context, prefer the local PreToolUse wrapper that rewrites Bash commands to `tokenjuice wrap -- ...`. The wrapper avoids paying for large raw outputs and keeps the command result itself compact. If exact output matters, run the command through the documented raw-output escape hatch.
30+
31+
Full runbook: `memory/cards/tokenjuice-output-compaction.md`.
32+
2533
## Git
2634

2735
- Do not add `Co-Authored-By` or AI-attribution trailers to commits, PR bodies, or public docs.

0 commit comments

Comments
 (0)