codex-refactor-memory
Consolidate Codex project memory and perform controlled, in-place normalization of knowledge, guidelines, skills, and agent wiring.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Consolidate Codex project memory and perform controlled, in-place normalization of knowledge, guidelines, skills, and agent wiring.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
Execute an approved dated spec mission from .codex/specs/ autonomously until final review — self-plan runnable tasks, delegate under the active harness policy, verify acceptance, record ROADMAP dispositions and evidence, and offer session rotation at phase boundaries.
Create a dated mission-scale spec workspace in .codex/specs/ — interview the user, freeze the intent in a reviewable POC artifact, then write a decision-complete SPEC + ROADMAP that a later (often cheaper) session can execute autonomously via $codex-spec-run.
Bulk-maintain Codex current state, task/spec indexes, JOURNAL history, and eligible durable project knowledge at a session boundary.
Run a read-only Codex installation health check using the knowledge checker plus semantic audits of memory and workflow wiring.
Write a single-slot session baton (.codex/HANDOFF.md) that distills this session's reasoning state — objective, hypothesis, evidence, dead ends, exact next step — so a fresh session can resume seamlessly. Run when the context window is nearly full or when pausing mid-investigation.
Run a behavior-first Codex retrospective, strengthen relevant guidelines, and route any durable descriptive facts to the canonical knowledge workflow.
| name | codex-refactor-memory |
| description | Consolidate Codex project memory and perform controlled, in-place normalization of knowledge, guidelines, skills, and agent wiring. |
Refactor the repository-local Codex operating layer without losing project context or curated routing. Use the existing files as live state, make deterministic repairs before semantic ones, and preserve user-authored bodies unless evidence supports an explicit content change.
For a knowledge contract upgrade, use this sequence:
$codex-doctor
$codex-refactor-memory
$codex-doctor
The first doctor run establishes a read-only baseline; refactor performs one controlled in-place normalization; the final doctor run verifies the result.
git status --short. Preserve unrelated user changes and stop for direction only when overlapping edits make the refactor unsafe.AGENTS.md; the CLAUDART source template may use .codex/AGENTS.md as the installer source. If both differ and local evidence does not identify the owner, ask before overwriting either..codex/CONTEXT.md, .codex/JOURNAL.md, guidelines, knowledge, tasks, specs, skills, agents, and recent Git history. Never read .env or expose secrets..codex/guidelines/knowledge-management.md in full before inspecting or changing knowledge..codex/scripts/knowledge-check.sh. If it is missing, report a High-severity installation problem and stop before knowledge writes.bash .codex/scripts/knowledge-check.sh --root . and retain its pre-change findings. Exit 1 is a finding baseline; exit 2 is a checker usage/runtime failure, so stop before knowledge writes.AGENTS.md: concise entrypoint and routing pointers, preferably under 100 lines..codex/guidelines/: durable prescriptive behavior..codex/knowledge/: durable descriptive project facts and reference pointers..codex/CONTEXT.md: small declarative state true now..codex/JOURNAL.md: append-only history, never auto-loaded..codex/tasks/ and .codex/specs/: working plans, proposals, acceptance state, and mission-local discoveries..codex/HANDOFF.md: optional single-use conversational baton..agents/skills/ and .codex/agents/: executable workflows and bounded specialist roles.Route content by meaning before reorganizing files. Do not move WIP or a proposed future state into knowledge. Do not turn a descriptive fact into a guideline merely to keep it always loaded.
AGENTS.md.AGENTS.md, deprecated memory files, current guidelines, and stable decisions in CONTEXT. Split candidates by type before moving them: behavior → guideline; fact → knowledge; WIP/proposal → task/spec/CONTEXT..codex/guidelines/ exists, then extract detailed behavior into the smallest set of domain guidelines with clear ownership and useful paths:. Do not create files for symmetry or force a weak concept into an unrelated owner. Use .codex/guidelines/*.md for semantic guidance; never place it in .codex/rules/, whose optional *.rules files are reserved for Codex permission or environment rules..env values into any memory tier.AGENTS.md to project identity, selective context loading, core workflows, security/repository-wide constraints, and pointers. Never require reading every guideline blindly. Keep it under 100 lines where practical; if it still exceeds 150 lines, flag that explicitly in the final report.AGENTS.md and the full contract in knowledge-management.md.paths:, description:, when_to_use:, and tags: frontmatter and a clear owner. Keep flow-style paths/tags..codex/CONTEXT.md, the universal behavior guideline, every globally relevant workflow guideline, and the knowledge root router from AGENTS.md. Never auto-load JOURNAL, HANDOFF, task bodies, or knowledge details.ai-behavior.md exists without overwriting user customizations. Follow the active harness policy for delegation; keep decomposition, disjoint ownership, non-overlap, parent validation, and durable result recording in agent-delegation.md instead of inventing a conflicting permission rule.## Agent Self-Evolution & Context Maintenance remains in AGENTS.md: project-wide behavior updates its owner guideline, new guideline owners get indexed, eligible descriptive facts use the knowledge contract, global Codex behavior updates AGENTS.md, and live state uses checkpoint.Semantic audit results must identify guidelines changed, stale rules fixed, source debt left in code/docs, split/merge actions, and decisions still requiring the user.
Read every topic frontmatter, the root router, domain maps, and route targets. Use the canonical grammar and mutation rules from knowledge-management.md; do not restate or improvise a second schema.
For each topic:
status: active only when current evidence was actually checked. Record last_verified as the evidence-check date and ensure active topics have sources or verify.status: review-needed with a precise status_note; do not present uncertainty as active truth.superseded or retired only with clear repository evidence or user confirmation. Never infer lifecycle from age or absence from the map.Store-wide rules:
_maps/<domain>.md from existing scope/grouping evidence while preserving curated and external routes; if ownership cannot be grouped safely, report the decision instead of guessing.After the normalization batch, run bash .codex/scripts/knowledge-check.sh --root . --fail-on warning. Fix only supported mechanical failures; exit 2 blocks completion. Then repeat the normalization scan without changing inputs: it must produce no further diff. If a second pass would churn formatting or metadata, the refactor is not idempotent; stop and report the cause.
.codex/CONTEXT.md only through checkpoint semantics, keep it under 150 lines, and ensure AGENTS.md references it.rg, and remove any instruction that auto-loads it..gitkeep only when a real archived Markdown file already makes it redundant, and report the removal.SKILL.md frontmatter and confirm the workflow remains executable with its referenced guidelines and one-hop resources. Repair stale references and generated markers without making skills duplicate canonical guideline contracts..codex/agents/*.toml, require name, description, model, model_reasoning_effort, sandbox_mode, and developer_instructions. Keep reviewers/explorers read-only unless the agent is explicitly a worker.When the repository is a distributable template:
.codex/ and .agents/ as generic payload, not live maintainer state..codex/AGENTS.md and the downstream root AGENTS.md.Before completion:
AGENTS.md line count and links; verify live state and guideline targets exist and that JOURNAL, HANDOFF, task bodies, and knowledge details are not auto-loaded.agent-delegation.md is wired when agents exist..codex/config.toml retains a conservative positive concurrency cap unless a higher value is explicitly documented.git diff --stat, git diff --check, git status --short, line/token estimates for the active memory index and CONTEXT, and relevant repository formatters.Summarize files created/changed, cross-tier moves, final AGENTS.md size, checker results before/after, semantic findings and source debt, skills/agents audited, candidates left review-needed, ambiguous unindexed files preserved, removed placeholders/deprecated files, validation run, and decisions still needed. Suggest reviewing the full diff. Do not commit, push, merge, rebase, tag, or trigger CI/CD without explicit user permission.