Codex Bootstrap
Scaffold a repo for OpenAI Codex with the durable-memory pattern: stable instructions in AGENTS.md, mutable learnings in .codex/agent-memory.md, and lifecycle hooks that load memory at session start and enforce the memory-update protocol at session stop.
Why this pattern
Codex reads AGENTS.md at the start of every task, walking from ~/.codex/AGENTS.md (global) down to the current working directory. Files closer to the cwd override earlier ones. That's the right place for stable project instructions.
Memory belongs in a separate file because instructions and learnings have different lifecycles. AGENTS.md should rarely change once stable; .codex/agent-memory.md should accrue durable findings (working commands, gotchas, test quirks, architecture decisions) as Codex works.
Hooks make the pattern enforceable rather than aspirational. Without them, Codex may skip the memory step under pressure. SessionStart loads the memory file as developer context at the start of every session, and Stop blocks task completion until Codex either reports an update or confirms there were no durable findings.
Inputs to gather before scaffolding
Ask the user before writing anything:
Target repo path — confirm
pwdis the repo root. Ifgit rev-parse --show-topleveldiffers, ask which path they want. The hooks rely ongit rev-parseto locate the root, so a non-git directory is workable but worth flagging.Version control for
.codex/agent-memory.md— commit it (shared with the team, available in fresh clones) or gitignore it (personal, doesn't affect other contributors). Default recommendation: commit it, but keep entries focused on shared project facts. Seereferences/version-control.mdfor the tradeoffs and the shared/local split pattern.Existing files — if
AGENTS.mdor.codex/already exist, never silently overwrite. Show the user what's there and ask whether to merge, overwrite specific files, or abort.
Files this skill creates
All paths relative to the repo root:
AGENTS.md— stable instructions with the memory protocol.codex/agent-memory.md— memory template with empty section headers.codex/config.toml— enables Codex hooks.codex/hooks/session_start_memory.py— loads memory at session start.codex/hooks/stop_memory_check.py— enforces memory update at session stop
Scaffolding steps
Verify repo state
Run
git rev-parse --show-toplevelto confirm a git repo. If it fails, ask the user whether to proceed. The hooks will still work ifgitis installed and the user is inside any directory — they callgit rev-parseto find the root — but a non-repo directory is unusual and worth confirming.Check for conflicts
Run
ls AGENTS.md .codex 2>/dev/null(or equivalent). If anything exists, surface it and ask before proceeding. Don't clobber a hand-writtenAGENTS.md.Write files from
assets/Read each template from
assets/and write to the corresponding destination. Use Read + Write rather thancp— that way the contents are visible in the conversation and the user can spot anything they want to tweak before it lands on disk.Destinations (in order):
assets/AGENTS.md→<repo>/AGENTS.mdassets/agent-memory.md→<repo>/.codex/agent-memory.mdassets/config.toml→<repo>/.codex/config.tomlassets/session_start_memory.py→<repo>/.codex/hooks/session_start_memory.pyassets/stop_memory_check.py→<repo>/.codex/hooks/stop_memory_check.py
Make hooks executable
chmod +x <repo>/.codex/hooks/session_start_memory.py <repo>/.codex/hooks/stop_memory_check.pyWithout this, Codex will try to run the hooks and they'll fail with a permission error. The
config.tomlinvokes them viapython3 <path>, so technically the executable bit isn't strictly required — but setting it removes one class of confusion if anyone runs the scripts directly.Apply version control choice
- Committing memory (default): nothing extra. The file is tracked.
- Gitignoring memory: append
.codex/agent-memory.mdto.gitignore(create.gitignoreif it doesn't exist). The hook scripts andconfig.tomlshould still be committed — those are shared infrastructure.
Print a summary
Tell the user what was created, what to do next, and any caveats. Useful next steps to mention:
- Codex must trust the project for repo-local hooks to load. The first time Codex runs in this directory, it'll ask.
- Edit
AGENTS.mdto add repo-specific commands (e.g.,pnpm test,cargo check) — the scaffolded version only contains the memory protocol and a generic verification section. - The "Project facts" section of
agent-memory.mdis the only one worth pre-filling manually; the rest should accumulate naturally as Codex works.
After scaffolding
Don't pre-fill the memory file's body sections. Empty section headers are deliberate prompts for Codex to recognize which kinds of findings belong where. Pre-filling them with examples primes Codex to overwrite or mimic those entries, which defeats the purpose.
If the user asks about layered memory (shared + personal), point them to references/version-control.md for the agent-memory.local.md split pattern.
If the user asks about global defaults across all their repos, point them to references/global-setup.md for the ~/.codex/AGENTS.md pattern. This skill deliberately doesn't touch the global file — that's a personal layer the user should write themselves so it reflects their actual cross-project preferences.
Reference files
references/version-control.md— committed vs gitignored memory, and the shared/local split patternreferences/global-setup.md—~/.codex/AGENTS.mdfor personal defaults across every repoassets/— the literal file templates this skill writes to the target repo
Source: sandalsoft/agent-skills — distributed by TomeVault.