Borrowing it
Nothing to install: this file belongs to Davidcreador/codex-token-guard. Take a copy, put it at the same path in your own repository, and replace the rules that are about this project with yours.
curl -O https://raw.githubusercontent.com/Davidcreador/codex-token-guard/main/AGENTS.mdgit clone --depth 1 https://github.com/Davidcreador/codex-token-guardWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/instructions/davidcreador/codex-token-guard/agents-md)<a href="https://agentmods.dev/instructions/davidcreador/codex-token-guard/agents-md"><img src="https://agentmods.dev/badge/instructions/davidcreador/codex-token-guard/agents-md/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/instructions/davidcreador/codex-token-guard/agents-md"><img src="https://agentmods.dev/badge/instructions/davidcreador/codex-token-guard/agents-md.svg" alt="Reviewed on agentmods" width="80" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.01001 | $0.01001 |
| Opus 5.5 | $0.00400 | $0.00400 |
| Sonnet 5.5 | $0.00200 | $0.00200 |
| Haiku 4.5 | $0.00100 | $0.00100 |
Grade A, and why
codex-token-guard AGENTS.md scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2mo ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 240 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Build codex-token-guard, a plug-and-play Codex plugin that reduces token usage during Codex sessions without reducing output quality.
The plugin should use Codex lifecycle hooks where possible, especially:
- PreToolUse
- PostToolUse
- PreCompact
- PostCompact
- UserPromptSubmit
- Stop
The plugin must be measurable. It should track token savings, blocked commands, compressed outputs, session summaries, and quality impact.
Product Requirements
Main goal
Reduce unnecessary context and tool-output tokens in Codex sessions.
Non-goals
- Do not rewrite Codex internals.
- Do not depend on unsupported Codex APIs.
- Do not aggressively remove information required for task success.
- Do not make Codex worse at coding.
Architecture
Create this structure:
codex-token-guard/
.codex-plugin/
plugin.json
hooks/
hooks.json
pre-tool-use.ts
post-tool-use.ts
pre-compact.ts
post-compact.ts
user-prompt-submit.ts
stop.ts
src/
cli.ts
config.ts
token-estimator.ts
command-policy.ts
output-compressor.ts
session-memory.ts
metrics.ts
benchmark.ts
quality.ts
skills/
token-guard/
SKILL.md
benchmarks/
fixtures/
tasks/
.codex-token-guard/
metrics.jsonl
session.md
decisions.md
files-touched.json
errors.md
Plugin behavior
1. PreToolUse
Before Bash commands run, inspect the command and classify it:
safe
expensive
dangerous
needs_confirmation
Block or warn on:
cat large files
tree
find .
grep -r
npm test
pnpm test
yarn test
bun test
large log dumps
recursive ls
printing lockfiles
printing generated files
printing node_modules
printing dist/build/.next
Suggest cheaper alternatives:
cat file.ts -> sed -n '1,160p' file.ts
find . -> rg --files | head -200
grep -r "x" . -> rg "x"
npm test -> pnpm test path/to/specific.test.ts
tree -> rg --files | sed -n '1,200p'
2. PostToolUse
Compress noisy outputs.
keep:
errors
stack traces
file paths
line numbers
failed assertions
test names
compiler errors
diff summaries
important warnings
Remove:
repeated lines
progress bars
install noise
ANSI colors
huge successful logs
dependency tree spam
duplicated stack frames
3. PreCompact
Generate a clean session summary:
# Session State
## Goal
## Current Status
## Key Decisions
## Files Touched
## Bugs / Errors
## Important Context To Preserve
## Next Steps
4. Stop
Persist durable session memory:
.codex-token-guard/session.md
.codex-token-guard/decisions.md
.codex-token-guard/files-touched.json
.codex-token-guard/errors.md
.codex-token-guard/metrics.jsonl
Metrics
Track:
estimated_raw_tokens
estimated_sent_tokens
estimated_saved_tokens
savings_percentage
commands_blocked
commands_rewritten
outputs_compressed
raw_output_tokens
compressed_output_tokens
compression_ratio
session_duration
quality_flags
Expose CLI commands:
codex-token-guard init
codex-token-guard install
codex-token-guard mode safe
codex-token-guard mode balanced
codex-token-guard mode aggressive
codex-token-guard stats
codex-token-guard snapshot
codex-token-guard restore
codex-token-guard benchmark
Modes
safe
Only block obvious waste.
balanced
Default mode. Compress noisy output and suggest targeted commands.
aggressive
Strict budgets, strong output compression, more blocking.
Quality protection
Never remove:
actual error messages
file paths
line numbers
API names
function names
test names
user instructions
recent edits
architecture decisions
If uncertain, preserve the content.
Benchmarking
Add a benchmark runner that compares:
vanilla Codex
vs
Codex + Token Guard
Metrics:
token savings %
task success
latency
number of retries
number of failed attempts
Generate:
benchmarks/results/report.md
Implementation Requirements
Use TypeScript.
Use fast local token estimation. If exact tokenizer is unavailable, use a configurable approximation:
1 token ≈ 4 characters
Store metrics as JSONL so they are easy to inspect.
Keep hook scripts fast. Any hook should fail open unless in aggressive mode.
Important product rule: **default to quality over savings**.
The MVP should prove this:
```txt
20–40% fewer wasted tokens
near-zero quality loss
easy install
visible savings dashboard
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 2mo ago First seen · 240 lines · 1,001 tokens per session scan A 690cbac4f4bf
codex-token-guard AGENTS.md is an instructions file published in the GitHub repository Davidcreador/codex-token-guard (2 stars, last pushed 5mo ago), licensed MIT. It adds 1,001 tokens to every session, about $0.0040 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.
codex-token-guard AGENTS.md compared with instructions from other repositories
| Mod | Type | Stars | Last push | Licence | Scan | Tokens | Works with |
|---|---|---|---|---|---|---|---|
| codex-token-guard AGENTS.mdDavidcreador/codex-token-guard | Instructions file | 2 | 5mo ago | MIT | A | 1,001 | Claude Code, Codex, OpenCode |
| vscode buildNext.instructions.mdmicrosoft/vscode | Instructions file | 195k | today | MIT | A | 9,719 | GitHub Copilot |
| vscode oss-third-party-notices.instructions.mdmicrosoft/vscode | Instructions file | 195k | today | MIT | A | 5,516 | GitHub Copilot |
| next.js AGENTS.mdvercel/next.js | Instructions file | 143k | today | MIT | A | 7,461 | Codex, OpenCode |
| langchain AGENTS.mdlangchain-ai/langchain | Instructions file | 149k | today | MIT | A | 4,680 | Codex, OpenCode |
| vscode copilot-instructions.mdmicrosoft/vscode | Instructions file | 195k | today | MIT | A | 3,093 | GitHub Copilot |
| vscode model-prompts.instructions.mdmicrosoft/vscode | Instructions file | 195k | today | MIT | A | 2,022 | GitHub Copilot |