Prompt Patterns

Reference intermediate

Prompt Patterns for Codex CLI

Pattern 1: The Surgical Fix

For precise, targeted bug fixes.

Fix the bug in [FILE PATH] where [DESCRIBE BUG].

The error is: [PASTE ERROR MESSAGE]

Expected behavior: [WHAT SHOULD HAPPEN]
Actual behavior: [WHAT ACTUALLY HAPPENS]

Do not change any other logic in the file.

Example:

Fix the bug in src/lib/pagination.ts where the offset calculation 
is wrong for page numbers greater than 1.

The error is: Page 2 shows the same results as page 1.

Expected: page 2 should skip the first 10 results.
Actual: page 2 starts at offset 0.

Do not change any other logic in the file.

Pattern 2: The Feature Addition

For adding new functionality to existing code.

Add [FEATURE] to [FILE/MODULE].

Requirements:
- [REQ 1]
- [REQ 2]
- [REQ 3]

Integrate with existing code by:
- [INTEGRATION POINT 1]
- [INTEGRATION POINT 2]

Write tests in [TEST FILE PATH].

Pattern 3: The Test-Driven Fix

Let Codex use tests as verification.

The test in [TEST FILE] is failing:

[PASTE TEST CODE]

Error output:
[PASTE ERROR]

Fix the implementation in [SOURCE FILE] to make this test pass.
Run the test to verify the fix works.

Pattern 4: The Batch Operation

For applying the same change across multiple files.

In every file matching [GLOB PATTERN]:
1. [CHANGE 1]
2. [CHANGE 2]
3. [CHANGE 3]

Do not modify files in [EXCLUSION].
Run the linter after all changes.

Example:

In every file matching src/api/**/*.ts:
1. Replace console.log with logger.info
2. Replace console.error with logger.error
3. Add import { logger } from '@/lib/logger' if not present

Do not modify files in src/api/__tests__/.
Run the linter after all changes.

Pattern 5: The Scaffold and Implement

For building new modules from scratch.

Create a new [MODULE TYPE] at [PATH] that handles [RESPONSIBILITY].

Structure:
- [FILE 1]: [PURPOSE]
- [FILE 2]: [PURPOSE]
- [FILE 3]: [PURPOSE]

It must:
- [REQUIREMENT 1]
- [REQUIREMENT 2]
- [REQUIREMENT 3]

Follow the same patterns used in [REFERENCE MODULE PATH].
Include unit tests with >80% coverage.

Pattern 6: The Error-Driven Debug

For when you have an error but do not know the cause.

My application crashes with this error:

[PASTE FULL ERROR WITH STACK TRACE]

This happens when [TRIGGER CONDITION].

Find the root cause and fix it. The relevant code is likely in 
[DIRECTORY/FILES] based on the stack trace.

Pattern 7: The Migration

For upgrading dependencies or changing patterns.

Migrate [WHAT] from [OLD VERSION/PATTERN] to [NEW VERSION/PATTERN].

Files affected: [LIST OR GLOB]

Key changes needed:
- [CHANGE 1: old way -> new way]
- [CHANGE 2: old way -> new way]
- [CHANGE 3: old way -> new way]

After migration:
- Run: [VERIFICATION COMMAND]
- All existing tests must still pass

Pattern 8: The Documentation Sprint

For generating documentation from code.

For all exported functions and classes in [DIRECTORY]:
1. Add JSDoc/docstring with:
   - Brief description
   - @param for each parameter with type and purpose
   - @returns description
   - @throws for error conditions
   - @example with realistic usage

Match the documentation style in [REFERENCE FILE].
Do not modify any implementation code.

Pattern 9: The Production Hardening

For making existing code production-ready.

Review and harden [FILE/DIRECTORY] for production:

1. Add input validation for all user-provided data
2. Ensure SQL queries use parameterized statements
3. Add rate limiting checks where appropriate
4. Verify authentication is checked before data access
5. Remove any hardcoded secrets or credentials
6. Add appropriate error handling (no stack traces to clients)

Report each problem found before fixing.