Codex-Grade Coding
Enforces verification-driven coding with strict protocols to reduce errors and ensure correctness.
When to Use
- When writing new functionality that must be correct (financial calculations, auth, data integrity)
- When the user asks for "careful", "production-grade", or "bulletproof" code
- For any code that handles sensitive data or has no room for error
Process
Before Writing Code
- State the contract: What are the inputs, outputs, and invariants?
- Identify edge cases: Empty, null, boundary, concurrent, malformed
- Choose the verification strategy: Types, tests, assertions, or formal checks
While Writing Code
- Write in small, verifiable units: Each function does one thing
- Assert preconditions: Validate inputs at boundaries
- Handle all branches: No unhandled cases, no silent failures
- Make state changes explicit: Avoid hidden mutations or side effects
After Writing Code
- Verify correctness:
- Run the code mentally with edge case inputs
- Write or update tests covering the contract
- Check that error paths are tested too
- Review for common traps:
- Off-by-one errors
- Null/undefined propagation
- Resource leaks (unclosed handles, uncleared timers)
- Race conditions in async code
- Integer overflow / floating point issues
Rules
- Prefer compile-time/type-level safety over runtime checks where possible
- Every public function should have at least one test
- Never swallow errors silently — log, throw, or return explicitly
- If you're not sure the code is correct, don't ship it — verify first
- Favor readability over cleverness