codex-memory-trim

codex-memory-trim is a skill for Codex from Yu-Xiao-Sheng/codex-memory-trim. It costs 108 tokens per session (792 once invoked), scanned A, original, MIT.

A procedure for managing Codex's global memory, including removing duplicates, shortening verbose entries, and adding user-defined rules or preferences.

In plain words
What is it for?
Use it when cleaning up, compressing, or adding to Codex's global memory while preserving its source records and backups.
Why use it?
It keeps stored memories more concise, relevant, and easier for future sessions to use.

Skill for Codex

Written for Codex: reads ~/.codex or $CODEX_HOME. Also seen: mentions Codex.

Good fit Use it when cleaning up, compressing, or adding to Codex's global memory while preserving its source records and backups.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/yu-xiao-sheng/codex-memory-trim/skill
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add Yu-Xiao-Sheng/codex-memory-trim --skill skill
Clone the repo
git clone --depth 1 https://github.com/Yu-Xiao-Sheng/codex-memory-trim

Made for: Codex.

Wrote 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.

agentmods badge for codex-memory-trim

README.md
[![agentmods](https://agentmods.dev/badge/skills/yu-xiao-sheng/codex-memory-trim/skill.svg)](https://agentmods.dev/skills/yu-xiao-sheng/codex-memory-trim/skill)
Your own site
<a href="https://agentmods.dev/skills/yu-xiao-sheng/codex-memory-trim/skill"><img src="https://agentmods.dev/badge/skills/yu-xiao-sheng/codex-memory-trim/skill.svg" alt="Measured on agentmods" height="20"></a>
Per session 108 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 792 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector warn 7 Sept 2026
SkillSpector: 1 finding, up to medium

These are SkillSpector’s own severities. On a checked sample its high-severity flags on skills were ~96% false positives — a documented command, a public API, a “never do X” rule — so we show them as a caution to read, not a verdict. Why →

  • medium Rogue Agent · line 23
    Skill establishes unauthorized persistence across sessions via cron jobs, startup scripts, or state files. Session persistence allows an attacker to maintain access beyond the current interaction.
    Fix: Remove any persistence mechanisms (cron jobs, startup scripts, state files). Skills should not maintain state across sessions without explicit user consent.
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

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.

ModelPer sessionOnce invoked
Fable 5.1 $0.00108 $0.00792
Opus 5 $0.00054 $0.00396
Sonnet 5 $0.00022 $0.00158
Haiku 4.5 $0.00011 $0.00079

Measured 8d ago against content hash f71cd65737d4, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

codex-memory-trim 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 8d ago.

The scan reads SKILL.md. This mod also ships 2 executable files (scripts/auto-trim.sh, scripts/collect.py), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

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.

skill/SKILL.md · 31 lines

What it actually says

Codex 全局记忆管理(trim / compress / add-global)

按用户需求只读取对应子技能文件执行,不要全量加载:

用户意图 读取
清理/去重/删除过期记忆 subskills/trim.md
压缩冗长表达、简化措辞 subskills/compress.md
添加自定义全局记忆/规则 subskills/add-global.md

共享事实(所有子技能依赖,不要重新推导)

  • 分层:sessions/*.jsonl(不可变原始证据)→ raw_memories.md / rollout_summaries/(整理输入,由 ~/.codex/memories_1.sqlitestage1_outputs 重新渲染,手改会被还原)→ MEMORY.md(检索层)/ memory_summary.md(会话启动时注入的快照,文件头 v1)。
  • usage_count(stage1_outputs 列)= 检索命中次数,是保留/删除的核心依据。
  • ~/.codex/memories/.git 是整理基线:Phase 2 以 HEAD→工作区 diff 决定巩固内容。任何手工修改必须以 git 提交收尾,且提交前工作区若不干净、或 git log 顶部是新的 "Initialize Codex git baseline"(刚跑过自动整理),必须先读 diff 合并新内容,禁止覆盖。
  • 巡检脚本(只读):python3 ~/.codex/skills/codex-memory-trim/scripts/collect.py
  • 记忆快照是会话启动时一次性注入;修改只对新会话(或 codex fork)生效。
  • 备份模板:mkdir -p ~/.codex/backups && TS=$(date +%Y%m%d-%H%M%S) && tar czf ~/.codex/backups/memories-before-trim-$TS.tar.gz -C ~/.codex memories && cp ~/.codex/memories_1.sqlite ~/.codex/backups/memories_1-before-trim-$TS.sqlite

共享红线

  • 永不动 sessions/*.jsonlextensions/ad_hoc/notes/ 既有文件内容(note 只能新增或按用户原话修订)、.git 内部对象(正常 commit 除外)。
  • 禁用 codex debug clear-memories(全量重置)。整理任务(collect.py 中 consolidate_global)运行中不写文件。
  • 动手前必备份,结束必提交:cd ~/.codex/memories && git add -A && git -c user.name="Codex" -c user.email="[email protected]" commit -m "<一句话>",收尾 git status --short 必须为空。
  • 本 skill 自身按效率优先执行:单次完成,不循环重复校验。
Files

What ships with it

5 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

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.

  1. 8d ago First seen · 31 lines · 108 tokens per session scan A f71cd65737d4

Subscribe to this mod's changes

codex-memory-trim is a skill published in the GitHub repository Yu-Xiao-Sheng/codex-memory-trim (103 stars, last pushed 14d ago), licensed MIT. It adds 108 tokens to every session and 792 once invoked, about $0.0005 per session on Opus 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-30.