Codex CLI Playbook

Use Codex for rapid code generation and refactors while staying aligned with the toolkit agents, prompts, and session logs.

Get Codex CLI ready

  1. Install Codex CLI and authenticate (follow the official quickstart or the bundled terminal guide for platform-specific steps).
  2. Keep the toolkit alongside your repository (AI-toolkit/). Export helpers:
    export CODEX_TOOLKIT=$PWD/AI-toolkit
    export CODEX_OUTPUT=$PWD/.codex
    mkdir -p "$CODEX_OUTPUT"
  3. Run codex config set default_workdir $(pwd) so commands use the project root.
  4. Symlink frequently used agents into .codex/agents if you prefer shorter paths.
  5. Verify everything by asking Codex to list files: codex ask "List $CODEX_TOOLKIT/prompts".

Launch a new initiative with Codex

  1. Seed context with codex prompt $CODEX_TOOLKIT/prompts/create_brief.md --input kickoff.md; copy the output into your Claude session.
  2. Generate an execution plan via codex agent $CODEX_TOOLKIT/agents/orchestration/tech-lead-orchestrator.md --input feature.md and file the plan in your engineering notes.
  3. For scaffolding, use codex agent $CODEX_TOOLKIT/agents/build-specialists/backend-developer.md or codex agent $CODEX_TOOLKIT/agents/build-specialists/frontend-developer.md to produce starter files, then stage them with git add.
  4. Schedule automated tests by having Codex write the command queue (e.g., npm test, pytest) and paste it into a Makefile or GitHub Action.
  5. Before code review, run the prompts and agents listed below to cross-check coverage, security, and docs.

Codex for legacy or refactor work

Agent recipes that shine in Codex

Use caseCommandWhat you get
Backend featurecodex agent $CODEX_TOOLKIT/agents/frameworks/django/django-expert.md --input feature.mdModels, serializers, URL patterns, migration checklist.
API contract designcodex agent $CODEX_TOOLKIT/agents/build-specialists/api-architect.md --input api-spec.yamlVersioning strategy, error shapes, integration tests.
User interface buildcodex agent $CODEX_TOOLKIT/agents/frameworks/react/react-component-architect.md --input ui-requirements.mdComponent structure, state plan, styling stub.
Performance tuningcodex agent $CODEX_TOOLKIT/agents/quality/performance-optimizer.md --input traces.logPrioritised remediation steps with instrumentation tips.
Documentation polishcodex agent $CODEX_TOOLKIT/agents/product-docs/documentation-specialist.md --input notes/*.mdSuggested edits, structure, and missing sections.

Multi-agent execution loops

  1. Orchestrate first: Use codex agent $CODEX_TOOLKIT/agents/orchestration/tech-lead-orchestrator.md --input epic.md to produce a sequenced plan that names each downstream agent.
  2. Validate staffing: Run team-configurator.md with the orchestrator output so responsibilities, escalation paths, and required artefacts are explicit.
  3. Chain commands: For each phase, feed the previous agent’s artefact to the next command (e.g. codex agent $CODEX_TOOLKIT/agents/frameworks/react/react-component-architect.md --input plan-phase2.md).
  4. Agent-driven handoffs: When Codex suggests delegating work, ask it to write a handoff note (via session-closer.md) and reuse that file with codex agent ... for the next specialist.
  5. Close with reviewers: Finish the chain by running code-reviewer.md, testing-expert.md, and reliability-commander.md; append their findings to /project:session-update.
Keep each agent’s output under $CODEX_OUTPUT/chain/ so you can re-run or parallelise specific phases without regenerating the entire plan.

Sample scenario: refactoring a legacy module

  1. Brief & plan: Use codex prompt $CODEX_TOOLKIT/prompts/create_brief.md --input legacy-notes.md followed by codex prompt $CODEX_TOOLKIT/prompts/plan_feature.md to understand scope and constraints. Paste both outputs into the Claude session.
  2. Chain specialists: Run tech-lead-orchestrator.md then team-configurator.md to identify the order: code-archaeologist.md (map code), code-refactorer.md (safe sequence), testing-expert.md (coverage requirements).
  3. Implement: Let code-archaeologist.md summarise the module, feed that file to code-refactorer.md, and follow its step-by-step git commands. Execute recommended commands locally and paste logs into /project:session-update.
  4. Review & validate: Run codex prompt $CODEX_TOOLKIT/prompts/code_review.md --diff git.diff and let brutal-critic.md in Claude highlight remaining risks. Finish with reliability-commander.md to ensure compliance.
  5. Documentation: Generate final docs with codex prompt $CODEX_TOOLKIT/prompts/write_docs.md and attach the resulting markdown to the session log and repository docs.
Keep a timeline of agent outputs (plan, refactor steps, tests, docs) in $CODEX_OUTPUT/timeline.md so reviewers can trace every decision.

Creation catalogue & CLI recipes

Code & automation

Documentation & knowledge

Testing & quality

Interfacing with other generators

Set CODEX_DEFAULT_MODEL in your shell to switch between models (e.g. export CODEX_DEFAULT_MODEL=codex-pro) and keep reusable command wrappers in a justfile for one-liners.

Prompt workflows

PromptCommand patternMaximize impact
@plan_feature.mdcodex prompt $CODEX_TOOLKIT/prompts/plan_feature.md --input feature.txtInclude links to design docs + acceptance criteria so Codex suggests precise file edits.
@code_review.mdgit diff main...HEAD > /tmp/review.patch && codex prompt $CODEX_TOOLKIT/prompts/code_review.md --diff /tmp/review.patchAsk for severity scoring and test ideas; paste results into PR description.
@write_docs.mdcodex prompt $CODEX_TOOLKIT/prompts/write_docs.md --input release-notes.mdFeed in plan + review output for a comprehensive changelog.
@create_brief.mdcodex prompt $CODEX_TOOLKIT/prompts/create_brief.md --input kickoff-notes.mdReuse the brief in tickets and Claude sessions to align the organisation.

Stay aligned with Claude sessions

Read the latest log

codex ask --file .claude/sessions/current.log "Summarise blockers and TODOs"

Propose fixes

Let Codex draft remediation actions, then paste them into /project:session-update for team visibility.

Escalate risks

Use codex prompt $CODEX_TOOLKIT/prompts/code_review.md to highlight outstanding issues and attach to Jira/GitHub.

Discipline-specific playbooks

Terminal and tooling integration

Best practices for Codex