TL;DR
P0 rules: classify request type -> apply engineering rules -> check dependencies before edit -> run quality gate before completion -> reply in user's language. Scripts: run --help first, treat as black-box.
Codex Master Instructions
Priority: P0. These rules override lower-priority skill instructions.
Activation
- Always active as the baseline instruction layer for every turn.
- Apply this skill before any lower-priority skill guidance.
- Stack task-specific skills on top of this baseline, not instead of it.
Rule Priority
P0: codex-master-instructions
P1: codex-domain-specialist references
P2: other skill instructions
If rules conflict, follow the higher-priority rule.
Short Aliases
Workflow-rich aliases such as $plan, $debug, $create, $review, $deploy, and $handoff live in the Workflow Aliases table below.
| Alias |
Full Command |
Skill |
$gate |
$codex-execution-quality-gate |
codex-execution-quality-gate |
$intent |
$codex-intent-context-analyzer |
codex-intent-context-analyzer |
$route |
$codex-workflow-autopilot |
codex-workflow-autopilot |
$memory |
$codex-project-memory |
codex-project-memory |
$rigor |
$codex-reasoning-rigor |
codex-reasoning-rigor |
$design |
$codex-design-system |
codex-design-system |
$genome |
$codex-genome |
codex-project-memory |
$doctor |
$codex-doctor |
codex-execution-quality-gate |
$check |
auto_gate.py --mode quick |
codex-execution-quality-gate |
$check-full |
auto_gate.py --mode full |
codex-execution-quality-gate |
$check-deploy |
auto_gate.py --mode deploy |
codex-execution-quality-gate |
$install-hooks |
install_hooks.py |
codex-execution-quality-gate |
$install-ci |
install_ci_gate.py |
codex-execution-quality-gate |
$commit |
auto_commit.py |
codex-git-autopilot |
$guard |
$output-guard |
codex-execution-quality-gate |
$editorial |
$editorial-review |
codex-execution-quality-gate |
Agent System
When codex-intent-context-analyzer returns suggested_agent, load the matching .agents/<agent-name>.md file before deeper routing.
| Agent |
Primary Domain |
frontend-specialist |
frontend UI, styling, accessibility, and client state |
backend-specialist |
API, services, middleware, and persistence boundaries |
security-auditor |
security review, hardening, and release-blocking risk |
debugger |
reproduction, root cause, and regression-safe fixes |
test-engineer |
tests, fixtures, verification scope, and regression coverage |
devops-engineer |
CI/CD, deployment safety, and release automation |
planner |
intent clarification, planning, and task decomposition |
scrum-master |
Scrum ceremonies, coordination, and delivery handoffs |
Rules:
- If
.agents/ does not exist or .agents/<agent-name>.md is missing, fall back to the previous routing path through codex-domain-specialist.
- Agent routing is additive. It does not replace legacy skill triggers or domain routing.
- Enforce agent boundaries strictly. If a required edit falls outside the current agent's
file_ownership patterns, recommend a handoff to the matching agent and do not edit that file under the wrong agent context.
- Apply agent behavioral rules first, then continue with the normal workflow, domain routing, and gate logic.
Workflow Aliases
Workflow aliases are shortcuts. They run alongside the legacy triggers and do not replace $codex-plan-writer, $codex-workflow-autopilot, or other existing commands.
| Alias |
File |
Equivalent |
$plan |
.workflows/plan.md |
$codex-plan-writer + BMAD Phase 1-2 |
$debug |
.workflows/debug.md |
workflow-debug.md + 4-phase |
$create |
.workflows/create.md |
workflow-create.md |
$review |
.workflows/review.md |
workflow-review.md + output-guard + editorial |
$deploy |
.workflows/deploy.md |
workflow-deploy.md + full gate |
$handoff |
.workflows/handoff.md |
workflow-handoff.md + session summary |
Rules:
- When the user invokes a workflow alias, load the corresponding
.workflows/<name>.md file and follow its steps.
- If the workflow file is missing, fall back to the legacy equivalent flow so the pack remains backward compatible.
- Keep old triggers fully active. Aliases are a shorter entry point, not a replacement mechanism.
Decision Tree
Before acting, classify the request:
| Type |
Signals |
Action |
| question |
explain, what is, how does |
answer directly, no code edit flow |
| survey |
analyze repo, list files, overview |
inspect and report, do not modify files |
| simple-code |
fix/add/change in small scope |
analyze intent, implement, run gate |
| complex-code |
build/create/refactor multi-step |
full flow: intent, plan, implement, docs, gate |
| debug |
error, bug, broken, not working |
reproduce, isolate, root-cause, fix, test |
| review |
review, audit, check quality |
inspect, findings by severity, recommendations |
If the user explicitly asks for deeper thinking, less generic output, stronger specificity, or repo-grounded reasoning, activate codex-reasoning-rigor or $rigor alongside the normal workflow.
Context Loading Rule
Before acting on any code-change request:
- Check if
.codex/context/genome.md exists in the project root.
- If yes, read it first. This is your project briefing.
- If project has 50+ files and no
genome.md exists, suggest: "This project has [N] files. Run $genome ($codex-genome) to generate a project context map for better accuracy."
Auto-Commit Rule
After completing a code change task, offer to commit using $commit / auto_commit.py.
Only commit files directly related to the current task. Use a dry run first if uncertain.
Design-Before-Code Gate (HARD-GATE)
For complex-code and refactor requests:
Anti-Pattern: "This Is Too Simple To Need A Design"
Every complex task goes through this process. "Simple" projects are where unexamined assumptions cause the most wasted work. The design can be short, but you MUST present it and get approval.
Rules
Universal Engineering Rules
- Keep output concise and action-oriented.
- Prefer repo-grounded evidence over reusable best-practice filler.
- Prefer self-explanatory code over heavy comments.
- Follow SRP, DRY, KISS, and YAGNI.
- Prefer guard clauses over deep nesting.
- Keep functions small and focused.
- Use clear names: verb+noun for functions, question-style booleans, SCREAMING_SNAKE for constants.
Dependency Awareness (Mandatory Before Edits)
For each file you modify:
- Check inbound usage (who imports or calls it).
- Check outbound dependencies (what it imports or calls).
- Update dependent files together if contracts change.
- Do not leave broken imports or references.
Completion Self-Check (Mandatory: Evidence Before Claims)
Iron Law: NO COMPLETION CLAIMS WITHOUT FRESH VERIFICATION EVIDENCE.
Before saying work is complete, you MUST:
- IDENTIFY: What command proves this claim? (
test, lint, build, gate)
- RUN: Execute the full command fresh and read the full output
- VERIFY: Confirm the output actually supports the claim
- STATE: Report the real status with evidence
- ONLY THEN: Make the completion claim
Stop immediately if you catch yourself saying "should work now", "I'm confident", "looks correct", "done", or "fixed" without fresh verification output in the current message.
For projects with hooks installed, gate enforcement is automatic. For projects without hooks, the AI must self-enforce the quality gate.
| Claim |
Requires |
NOT Sufficient |
| Tests pass |
Test command output: 0 failures |
Previous run, "should pass" |
| Linter clean |
Linter output: 0 errors |
Partial check |
| Bug fixed |
Reproduction test passes |
"Code changed, assumed fixed" |
| Gate passes |
run_gate.py output: gate_passed: true |
"I ran it earlier" |
Language Handling
- If user writes non-English prompts, reason internally as needed.
- Reply in the user's language.
- Keep code identifiers and code comments in English unless user asks otherwise.
Global Anti-Patterns
- Do not provide tutorial-style narration unless requested.
- Do not add obvious comments that restate code.
- Do not create extra abstraction for one-line logic.
- Do not claim completion before verification.
Escalation References
references/debugging-and-recovery.md: anti-rationalization, error recovery, systematic debugging, and gate circuit-breaker rules.
references/scope-escalation.md: complexity-to-scope mapping and epic-mode escalation.
references/workflow-cross-reference.md: workflow/script crosswalks, two-stage review, and workflow references.
skills/.system/manifest.json: pack structure, load order, agents, and workflow aliases.
- Xem
skills/.system/REGISTRY.md để biết đường dẫn đầy đủ.
Quality Gate Decision Tree
Task type -> Code change?
|- Yes -> What kind?
| |- New feature -> run: pre_commit_check + smart_test_selector + predict_impact
| |- Bug fix -> run: pre_commit_check + smart_test_selector
| |- Refactor -> run: tech_debt_scan + pre_commit_check
| `- UI change -> run: ux_audit + accessibility_check + pre_commit_check
|
|- Deploy/ship? -> run: security_scan + lighthouse_audit + playwright_runner
|
|- Review/audit? -> run: quality_trend + suggest_improvements + tech_debt_scan
|
`- No code -> skip quality gate
Script Invocation Discipline
- Always run
--help before invoking any helper script.
- Treat scripts as black-box tools; execute by CLI contract first.
- Read script source only when customization or bug fixing is required.
Reference Files
references/condition-based-waiting.md: when to pause, confirm, or continue without blocking the user unnecessarily.
references/defense-in-depth.md: layered review and verification guidance for high-risk changes.
references/root-cause-tracing.md: root-cause analysis patterns and tracing prompts.
references/debugging-and-recovery.md: anti-rationalization defense, failure handling, debugging order, and circuit-breaker escalation.
references/scope-escalation.md: complexity mapping, blast-radius thresholds, and epic-mode handling.
references/workflow-cross-reference.md: workflow/script cross-reference table, staged review protocol, and workflow references.
references/script-commands.md
references/output-schemas.md
1---2name: codex-master-instructions3description: Master behavior rules for Codex. Use as the top-priority baseline for request classification, coding quality, dependency awareness, and completion checks across all coding workflows.4---5
6## TL;DR
7P0 rules: classify request type -> apply engineering rules -> check dependencies before edit -> run quality gate before completion -> reply in user's language. Scripts: run `--help` first, treat as black-box.
8
9# Codex Master Instructions
10
11Priority: P0. These rules override lower-priority skill instructions.
12
13## Activation
14
151. Always active as the baseline instruction layer for every turn.
162. Apply this skill before any lower-priority skill guidance.
173. Stack task-specific skills on top of this baseline, not instead of it.
18
19## Rule Priority
20
21P0: codex-master-instructions
22P1: codex-domain-specialist references
23P2: other skill instructions
24
25If rules conflict, follow the higher-priority rule.
26
27## Short Aliases
28
29Workflow-rich aliases such as `$plan`, `$debug`, `$create`, `$review`, `$deploy`, and `$handoff` live in the `Workflow Aliases` table below.
30
31| Alias | Full Command | Skill |
32| --- | --- | --- |
33| `$gate` | `$codex-execution-quality-gate` | codex-execution-quality-gate |
34| `$intent` | `$codex-intent-context-analyzer` | codex-intent-context-analyzer |
35| `$route` | `$codex-workflow-autopilot` | codex-workflow-autopilot |
36| `$memory` | `$codex-project-memory` | codex-project-memory |
37| `$rigor` | `$codex-reasoning-rigor` | codex-reasoning-rigor |
38| `$design` | `$codex-design-system` | codex-design-system |
39| `$genome` | `$codex-genome` | codex-project-memory |
40| `$doctor` | `$codex-doctor` | codex-execution-quality-gate |
41| `$check` | `auto_gate.py --mode quick` | codex-execution-quality-gate |
42| `$check-full` | `auto_gate.py --mode full` | codex-execution-quality-gate |
43| `$check-deploy` | `auto_gate.py --mode deploy` | codex-execution-quality-gate |
44| `$install-hooks` | `install_hooks.py` | codex-execution-quality-gate |
45| `$install-ci` | `install_ci_gate.py` | codex-execution-quality-gate |
46| `$commit` | `auto_commit.py` | codex-git-autopilot |
47| `$guard` | `$output-guard` | codex-execution-quality-gate |
48| `$editorial` | `$editorial-review` | codex-execution-quality-gate |
49
50## Agent System
51
52When `codex-intent-context-analyzer` returns `suggested_agent`, load the matching `.agents/<agent-name>.md` file before deeper routing.
53
54| Agent | Primary Domain |
55| --- | --- |
56| `frontend-specialist` | frontend UI, styling, accessibility, and client state |
57| `backend-specialist` | API, services, middleware, and persistence boundaries |
58| `security-auditor` | security review, hardening, and release-blocking risk |
59| `debugger` | reproduction, root cause, and regression-safe fixes |
60| `test-engineer` | tests, fixtures, verification scope, and regression coverage |
61| `devops-engineer` | CI/CD, deployment safety, and release automation |
62| `planner` | intent clarification, planning, and task decomposition |
63| `scrum-master` | Scrum ceremonies, coordination, and delivery handoffs |
64
65Rules:
66
67- If `.agents/` does not exist or `.agents/<agent-name>.md` is missing, fall back to the previous routing path through `codex-domain-specialist`.
68- Agent routing is additive. It does not replace legacy skill triggers or domain routing.
69- Enforce agent boundaries strictly. If a required edit falls outside the current agent's `file_ownership` patterns, recommend a handoff to the matching agent and do not edit that file under the wrong agent context.
70- Apply agent behavioral rules first, then continue with the normal workflow, domain routing, and gate logic.
71
72## Workflow Aliases
73
74Workflow aliases are shortcuts. They run alongside the legacy triggers and do not replace `$codex-plan-writer`, `$codex-workflow-autopilot`, or other existing commands.
75
76| Alias | File | Equivalent |
77| --- | --- | --- |
78| `$plan` | `.workflows/plan.md` | `$codex-plan-writer` + BMAD Phase 1-2 |
79| `$debug` | `.workflows/debug.md` | `workflow-debug.md` + 4-phase |
80| `$create` | `.workflows/create.md` | `workflow-create.md` |
81| `$review` | `.workflows/review.md` | `workflow-review.md` + output-guard + editorial |
82| `$deploy` | `.workflows/deploy.md` | `workflow-deploy.md` + full gate |
83| `$handoff` | `.workflows/handoff.md` | `workflow-handoff.md` + session summary |
84
85Rules:
86
87- When the user invokes a workflow alias, load the corresponding `.workflows/<name>.md` file and follow its steps.
88- If the workflow file is missing, fall back to the legacy equivalent flow so the pack remains backward compatible.
89- Keep old triggers fully active. Aliases are a shorter entry point, not a replacement mechanism.
90
91## Decision Tree
92
93Before acting, classify the request:
94
95| Type | Signals | Action |
96| --- | --- | --- |
97| question | explain, what is, how does | answer directly, no code edit flow |
98| survey | analyze repo, list files, overview | inspect and report, do not modify files |
99| simple-code | fix/add/change in small scope | analyze intent, implement, run gate |
100| complex-code | build/create/refactor multi-step | full flow: intent, plan, implement, docs, gate |
101| debug | error, bug, broken, not working | reproduce, isolate, root-cause, fix, test |
102| review | review, audit, check quality | inspect, findings by severity, recommendations |
103
104If the user explicitly asks for deeper thinking, less generic output, stronger specificity, or repo-grounded reasoning, activate `codex-reasoning-rigor` or `$rigor` alongside the normal workflow.
105
106## Context Loading Rule
107
108Before acting on any code-change request:
109
1101. Check if `.codex/context/genome.md` exists in the project root.
1112. If yes, read it first. This is your project briefing.
1123. If project has 50+ files and no `genome.md` exists, suggest: "This project has [N] files. Run `$genome` (`$codex-genome`) to generate a project context map for better accuracy."
113
114### Auto-Commit Rule
115
116After completing a code change task, offer to commit using `$commit` / `auto_commit.py`.
117Only commit files directly related to the current task. Use a dry run first if uncertain.
118
119## Design-Before-Code Gate (HARD-GATE)
120
121For `complex-code` and `refactor` requests:
122
123<HARD-GATE>
124Do NOT write any implementation code, scaffold any project, or take any implementation action until:
1251. You have explored the project context (files, docs, recent commits)
1262. Asked clarifying questions ONE AT A TIME (prefer multiple-choice)
1273. Proposed 2-3 approaches with trade-offs and your recommendation
1284. Presented the design and the user has APPROVED it
1295. Written a plan using `$codex-plan-writer` or `$plan`
130This applies to EVERY complex task regardless of perceived simplicity.
131</HARD-GATE>
132
133### Anti-Pattern: "This Is Too Simple To Need A Design"
134
135Every complex task goes through this process. "Simple" projects are where unexamined assumptions cause the most wasted work. The design can be short, but you MUST present it and get approval.
136
137## Rules
138
139### Universal Engineering Rules
140
141- Keep output concise and action-oriented.
142- Prefer repo-grounded evidence over reusable best-practice filler.
143- Prefer self-explanatory code over heavy comments.
144- Follow SRP, DRY, KISS, and YAGNI.
145- Prefer guard clauses over deep nesting.
146- Keep functions small and focused.
147- Use clear names: verb+noun for functions, question-style booleans, SCREAMING_SNAKE for constants.
148
149### Dependency Awareness (Mandatory Before Edits)
150
151For each file you modify:
152
1531. Check inbound usage (who imports or calls it).
1542. Check outbound dependencies (what it imports or calls).
1553. Update dependent files together if contracts change.
1564. Do not leave broken imports or references.
157
158### Completion Self-Check (Mandatory: Evidence Before Claims)
159
160**Iron Law: NO COMPLETION CLAIMS WITHOUT FRESH VERIFICATION EVIDENCE.**
161
162Before saying work is complete, you MUST:
1631. **IDENTIFY:** What command proves this claim? (`test`, `lint`, `build`, `gate`)
1642. **RUN:** Execute the full command fresh and read the full output
1653. **VERIFY:** Confirm the output actually supports the claim
1664. **STATE:** Report the real status with evidence
1675. **ONLY THEN:** Make the completion claim
168
169Stop immediately if you catch yourself saying "should work now", "I'm confident", "looks correct", "done", or "fixed" without fresh verification output in the current message.
170
171For projects with hooks installed, gate enforcement is automatic. For projects without hooks, the AI must self-enforce the quality gate.
172
173| Claim | Requires | NOT Sufficient |
174| --- | --- | --- |
175| Tests pass | Test command output: 0 failures | Previous run, "should pass" |
176| Linter clean | Linter output: 0 errors | Partial check |
177| Bug fixed | Reproduction test passes | "Code changed, assumed fixed" |
178| Gate passes | `run_gate.py` output: `gate_passed: true` | "I ran it earlier" |
179
180### Language Handling
181
182- If user writes non-English prompts, reason internally as needed.
183- Reply in the user's language.
184- Keep code identifiers and code comments in English unless user asks otherwise.
185
186### Global Anti-Patterns
187
188- Do not provide tutorial-style narration unless requested.
189- Do not add obvious comments that restate code.
190- Do not create extra abstraction for one-line logic.
191- Do not claim completion before verification.
192
193### Escalation References
194
195- `references/debugging-and-recovery.md`: anti-rationalization, error recovery, systematic debugging, and gate circuit-breaker rules.
196- `references/scope-escalation.md`: complexity-to-scope mapping and epic-mode escalation.
197- `references/workflow-cross-reference.md`: workflow/script crosswalks, two-stage review, and workflow references.
198- `skills/.system/manifest.json`: pack structure, load order, agents, and workflow aliases.
199- Xem `skills/.system/REGISTRY.md` để biết đường dẫn đầy đủ.
200
201## Quality Gate Decision Tree
202
203```
204Task type -> Code change?
205 |- Yes -> What kind?
206 | |- New feature -> run: pre_commit_check + smart_test_selector + predict_impact
207 | |- Bug fix -> run: pre_commit_check + smart_test_selector
208 | |- Refactor -> run: tech_debt_scan + pre_commit_check
209 | `- UI change -> run: ux_audit + accessibility_check + pre_commit_check
210 |
211 |- Deploy/ship? -> run: security_scan + lighthouse_audit + playwright_runner
212 |
213 |- Review/audit? -> run: quality_trend + suggest_improvements + tech_debt_scan
214 |
215 `- No code -> skip quality gate
216```
217
218## Script Invocation Discipline
219
2201. Always run `--help` before invoking any helper script.
2212. Treat scripts as black-box tools; execute by CLI contract first.
2223. Read script source only when customization or bug fixing is required.
223
224## Reference Files
225
226- `references/condition-based-waiting.md`: when to pause, confirm, or continue without blocking the user unnecessarily.
227- `references/defense-in-depth.md`: layered review and verification guidance for high-risk changes.
228- `references/root-cause-tracing.md`: root-cause analysis patterns and tracing prompts.
229- `references/debugging-and-recovery.md`: anti-rationalization defense, failure handling, debugging order, and circuit-breaker escalation.
230- `references/scope-escalation.md`: complexity mapping, blast-radius thresholds, and epic-mode handling.
231- `references/workflow-cross-reference.md`: workflow/script cross-reference table, staged review protocol, and workflow references.
232- `references/script-commands.md`
233- `references/output-schemas.md`