Skip to content

Latest commit

 

History

History
2127 lines (1639 loc) · 50.5 KB

File metadata and controls

2127 lines (1639 loc) · 50.5 KB

Codex Integration Guide

Tutorial Links

Quick Start & Learning Paths

New to Codex? Start here for a 5-minute introduction:

Complete Beginner Guide:

Visual Learning:

Problem Solving:

Recommended Learning Paths

Path Duration For Start With
New User 35 min First-time users Quick StartBeginner Guide
Migrating from Claude Code 40 min Claude Code users Feature ParityWorkflow Diagrams
CI/CD Integration 30 min Automation focus Quick StartFeature Parity
Advanced User 45 min Power users Workflow DiagramsFeature Parity

Quick Reference Card

Action Command Notes
Start Session ./amplify-codex.sh Full automation with wrapper
Manual Start codex --profile development Direct Codex launch
Quality Check codex> check_code_quality with file_paths ["file.py"] MCP tool
Save Transcript codex> save_current_transcript with format "both" Export session
Spawn Agent codex exec --agent bug-hunter "task" Manual agent execution
Task Management codex> create_task with title "Fix bug" and description "..." New MCP tool
Web Research codex> search_web with query "topic" and num_results 5 New MCP tool

Need Help? Check the Troubleshooting Tree or main Codex Integration Guide.

Prerequisites

System Requirements

  • Codex CLI: Latest version installed and configured
  • Python: Version 3.11 or higher
  • uv: Package manager for Python dependencies
  • Virtual Environment: Project uses uv-managed virtual environment
  • Unix-like Shell: Bash or compatible shell for wrapper script

Verify Codex CLI installation

codex --version

Verify uv package manager

uv --version

Verify Python version

python --version

Verify project setup

make check

First-Time Setup

  1. Clone and setup the project:
git clone <repository-url>
cd amplifier-project
make install
  1. Configure Codex:
# Initialize Codex configuration
codex --config .codex/config.toml

# Verify configuration
codex --profile development --help
  1. Test MCP servers:
# Test session manager
uv run python .codex/mcp_servers/session_manager/server.py --help

# Test quality checker
uv run python .codex/mcp_servers/quality_checker/server.py --help

# Test transcript saver
uv run python .codex/mcp_servers/transcript_saver/server.py --help

Hello World Example

# Start Codex with Amplifier integration
./amplify-codex.sh

# In Codex session, use MCP tools:
codex> initialize_session with prompt "Hello world project"

codex> check_code_quality with file_paths ["hello.py"]

codex> save_current_transcript with format "both"

# Exit Codex (Ctrl+D)

The wrapper script automatically handles session initialization, MCP server management, and cleanup.

Architecture Overview

MCP Server Architecture

Codex uses the Model Context Protocol (MCP) for tool integration, where each tool is implemented as a separate server process communicating via stdio with JSON-RPC messages.

MCP Server Components:

  • FastMCP Framework: Minimal boilerplate for server implementation
  • Stdio Communication: JSON-RPC over standard input/output
  • Tool Registration: Decorators for automatic tool discovery
  • Error Isolation: Server failures don't crash Codex

Server Lifecycle:

  1. Codex spawns server subprocess
  2. Server registers tools via MCP protocol
  3. Codex invokes tools with JSON-RPC calls
  4. Server processes requests and returns responses
  5. Server exits when Codex session ends

New MCP Servers

Task Tracker Server (TodoWrite Equivalent)

The task_tracker MCP server provides task management capabilities, replicating Claude Code's TodoWrite functionality for tracking development tasks within Codex sessions.

Purpose: Enable task-driven development workflows by allowing creation, management, and tracking of development tasks directly in Codex sessions.

Key Features:

  • Session-scoped task persistence (tasks cleared on new session)
  • Full CRUD operations (Create, Read, Update, Delete)
  • Task filtering and status management
  • Export capabilities (Markdown and JSON formats)
  • Priority levels and completion tracking

Configuration:

[mcp_servers.amplifier_tasks]
command = "uv"
args = ["run", "python", ".codex/mcp_servers/task_tracker/server.py"]
env = { AMPLIFIER_ROOT = "." }
timeout = 30

[mcp_server_config.task_tracker]
task_storage_path = ".codex/tasks/session_tasks.json"
max_tasks_per_session = 50

Tool Reference:

  • create_task(title, description, priority) - Create new task
  • list_tasks(filter_status) - List tasks with optional filtering
  • update_task(task_id, updates) - Update task properties
  • complete_task(task_id) - Mark task as complete
  • delete_task(task_id) - Remove task
  • export_tasks(format) - Export to markdown or JSON

Web Research Server (WebFetch Equivalent)

The web_research MCP server provides web search and content fetching capabilities, replicating Claude Code's WebFetch functionality for research-assisted development.

Purpose: Enable web research workflows by allowing web searches, URL content fetching, and content summarization directly in Codex sessions.

Key Features:

  • DuckDuckGo-based web search (no API key required)
  • URL content fetching with optional text extraction
  • Content summarization with configurable length limits
  • File-based caching with TTL for performance
  • Respectful rate limiting to avoid overwhelming sources
  • Graceful fallback for HTML parsing (uses beautifulsoup4 if available)

Configuration:

[mcp_servers.amplifier_web]
command = "uv"
args = ["run", "python", ".codex/mcp_servers/web_research/server.py"]
env = { AMPLIFIER_ROOT = "." }
timeout = 60

[mcp_server_config.web_research]
cache_enabled = true
cache_ttl_hours = 24
max_results = 10
rate_limit_per_minute = 30

Tool Reference:

  • search_web(query, num_results) - Search web and return results
  • fetch_url(url, extract_text) - Fetch and optionally extract text from URL
  • summarize_content(content, max_length) - Summarize provided content

Backend Abstraction Layer

The amplifier/core/backend.py module provides a unified API for both Claude Code and Codex backends:

from amplifier import get_backend

# Get appropriate backend based on AMPLIFIER_BACKEND env var
backend = get_backend()

# Unified API regardless of backend
result = backend.initialize_session("Working on feature")
result = backend.run_quality_checks(["file.py"])
result = backend.export_transcript()

Key Benefits:

  • Backend Agnostic: Same code works with both backends
  • Easy Switching: Change backends via environment variable
  • Testability: Mock backends for comprehensive testing
  • Extensibility: Add new backends without changing code

Wrapper Script

The amplify-codex.sh bash script provides hook-like functionality for Codex:

Features:

  • Validates prerequisites (Codex CLI, uv, virtual environment)
  • Runs session initialization automatically
  • Starts Codex with appropriate profile
  • Displays MCP tool guidance
  • Handles session cleanup on exit
  • Provides error handling and user feedback

Usage:

# Full workflow automation
./amplify-codex.sh --profile development

# Skip initialization
./amplify-codex.sh --no-init

# Custom profile
./amplify-codex.sh --profile ci

Session Lifecycle

With Wrapper Script (Recommended):

  1. User runs ./amplify-codex.sh
  2. Script validates environment
  3. Script runs session_init.py (loads memories)
  4. Script starts Codex with MCP servers
  5. User works in Codex session
  6. User exits Codex
  7. Script runs session_cleanup.py (extracts memories, exports transcript)

Manual Workflow:

  1. Run session_init.py manually
  2. Start Codex: codex --profile development
  3. Use MCP tools explicitly during session
  4. Run session_cleanup.py manually

MCP Tool Integration:

  • initialize_session - Load context at start
  • check_code_quality - Validate changes during work
  • save_current_transcript - Export progress
  • create_task - Track development tasks
  • search_web - Research during development
  • finalize_session - Extract memories at end

Configuration Guide

config.toml Structure

Codex uses TOML format for configuration, stored in .codex/config.toml:

# Model and basic settings
model = "claude-3-5-sonnet-20241022"
approval_policy = "on-request"

# MCP server configurations
[mcp_servers.amplifier_session]
command = "uv"
args = ["run", "python", ".codex/mcp_servers/session_manager/server.py"]
env = { "MEMORY_SYSTEM_ENABLED" = "true" }

[mcp_servers.amplifier_quality]
command = "uv"
args = ["run", "python", ".codex/mcp_servers/quality_checker/server.py"]

[mcp_servers.amplifier_transcripts]
command = "uv"
args = ["run", "python", ".codex/mcp_servers/transcript_saver/server.py"]

[mcp_servers.amplifier_tasks]
command = "uv"
args = ["run", "python", ".codex/mcp_servers/task_tracker/server.py"]
env = { AMPLIFIER_ROOT = "." }
timeout = 30

[mcp_servers.amplifier_web]
command = "uv"
args = ["run", "python", ".codex/mcp_servers/web_research/server.py"]
env = { AMPLIFIER_ROOT = "." }
timeout = 60

# Profile definitions
[profiles.development]
mcp_servers = ["amplifier_session", "amplifier_quality", "amplifier_transcripts", "amplifier_tasks", "amplifier_web"]

[profiles.ci]
mcp_servers = ["amplifier_quality"]

[profiles.review]
mcp_servers = ["amplifier_quality", "amplifier_transcripts", "amplifier_tasks"]

Profiles

Development Profile:

  • Purpose: Full-featured development workflow
  • Servers: All MCP servers enabled (session, quality, transcripts, tasks, web)
  • Use Case: Interactive development with memory system, quality checks, task tracking, and research capabilities

CI Profile:

  • Purpose: Automated quality assurance
  • Servers: Quality checker only
  • Use Case: CI/CD pipelines, automated testing

Review Profile:

  • Purpose: Code review and documentation
  • Servers: Quality checker + transcript saver + task tracker
  • Use Case: Code reviews, documentation generation, task management

Environment Variables

Core Variables:

  • AMPLIFIER_BACKEND=codex - Select Codex backend
  • CODEX_PROFILE=development - Default profile to use
  • MEMORY_SYSTEM_ENABLED=true - Enable/disable memory system

MCP Server Variables:

  • AMPLIFIER_ROOT - Project root directory (auto-detected)
  • VIRTUAL_ENV - Python virtual environment path
  • PATH - System executable path

Configuration Overrides:

# Override profile
CODEX_PROFILE=ci ./amplify-codex.sh

# Disable memory system
MEMORY_SYSTEM_ENABLED=false codex --profile development

# Custom project root
AMPLIFIER_ROOT=/custom/path codex

Configuration Precedence

  1. Command Line Arguments: Highest precedence (--profile ci)
  2. Environment Variables: Override config file (CODEX_PROFILE=ci)
  3. Config File: .codex/config.toml settings
  4. Defaults: Built-in fallback values

Advanced Configuration

Custom MCP Server:

[mcp_servers.custom_tool]
command = "python"
args = ["custom_server.py"]
env = { "CUSTOM_CONFIG" = "value" }

Profile Inheritance:

[profiles.base]
mcp_servers = ["amplifier_session"]

[profiles.extended]
mcp_servers = ["amplifier_session", "amplifier_quality", "custom_tool"]

MCP Tools Reference

Session Manager Tools

initialize_session

Load relevant memories at session start.

Parameters:

  • prompt (string): Session prompt for memory search
  • context (optional string): Additional context information

Returns:

{
  "memories": [
    {
      "content": "Previous work on authentication...",
      "timestamp": "2024-01-01T10:00:00Z",
      "source": "session_123"
    }
  ],
  "metadata": {
    "memoriesLoaded": 5,
    "source": "amplifier_memory"
  }
}

Usage Examples:

# Basic initialization
codex> initialize_session with prompt "Working on user authentication"

# With additional context
codex> initialize_session with prompt "Refactoring API" and context "Following REST principles"

Error Handling:

  • Returns empty memories array if memory system disabled
  • Graceful degradation if memory search fails
  • Logs errors but doesn't break session

finalize_session

Extract and store memories from session.

Parameters:

  • messages (array): Session conversation messages
  • context (optional string): Additional context

Returns:

{
  "metadata": {
    "memoriesExtracted": 3,
    "source": "amplifier_extraction"
  }
}

Usage Examples:

# Extract memories from conversation
codex> finalize_session with recent conversation messages

# With context
codex> finalize_session with messages and context "Completed authentication refactor"

Error Handling:

  • Continues if extraction fails (logs error)
  • Partial success if some memories extracted
  • Timeout protection (60 second limit)

health_check

Verify server and memory system status.

Parameters: None

Returns:

{
  "status": "healthy",
  "memory_enabled": true,
  "modules_available": ["memory", "search", "extraction"]
}

Usage Examples:

codex> health_check

Quality Checker Tools

check_code_quality

Run make check on specified files.

Parameters:

  • file_paths (array): Files to check
  • tool_name (optional string): Specific tool to run
  • cwd (optional string): Working directory

Returns:

{
  "passed": true,
  "output": "All checks passed\nLint: OK\nType check: OK\nTests: 15 passed",
  "issues": [],
  "metadata": {
    "tools_run": ["ruff", "pyright", "pytest"],
    "execution_time": 2.3
  }
}

Usage Examples:

# Check specific files
codex> check_code_quality with file_paths ["src/auth.py", "tests/test_auth.py"]

# Check after editing
codex> check_code_quality with file_paths ["modified_file.py"]

Error Handling:

  • Continues with partial results if some tools fail
  • Captures stderr output in issues array
  • Handles missing Makefile gracefully

run_specific_checks

Run individual quality tools.

Parameters:

  • check_type (string): Type of check ("lint", "type", "test")
  • file_paths (optional array): Specific files to check
  • args (optional array): Additional arguments

Returns:

{
  "passed": true,
  "output": "15 tests passed, 0 failed",
  "tool": "pytest",
  "issues": []
}

Usage Examples:

# Run only linting
codex> run_specific_checks with check_type "lint"

# Run tests on specific files
codex> run_specific_checks with check_type "test" and file_paths ["test_auth.py"]

validate_environment

Check development environment setup.

Parameters: None

Returns:

{
  "valid": true,
  "issues": [],
  "environment": {
    "venv_exists": true,
    "makefile_exists": true,
    "uv_available": true
  }
}

Transcript Saver Tools

save_current_transcript

Export current session transcript.

Parameters:

  • session_id (optional string): Specific session ID
  • format (string): Export format ("standard", "extended", "both", "compact")
  • output_dir (optional string): Custom output directory

Returns:

{
  "exported_path": ".codex/transcripts/2024-01-01-10-00-AM__project__abc123/",
  "metadata": {
    "file_size": 15432,
    "event_count": 127,
    "format": "both"
  }
}

Usage Examples:

# Save current session
codex> save_current_transcript with format "both"

# Save with custom directory
codex> save_current_transcript with output_dir "./exports" and format "compact"

save_project_transcripts

Batch export project sessions.

Parameters:

  • project_dir (string): Project directory
  • format (string): Export format
  • incremental (boolean): Skip already exported sessions

Returns:

{
  "exported_sessions": ["session1", "session2"],
  "skipped": ["already_exported"],
  "metadata": {
    "total_sessions": 15,
    "exported_count": 2
  }
}

list_available_sessions

Discover exportable sessions.

Parameters:

  • project_only (boolean): Filter to current project
  • limit (integer): Maximum sessions to return

Returns:

{
  "sessions": [
    {
      "session_id": "abc123",
      "start_time": "2024-01-01T10:00:00Z",
      "cwd": "/project",
      "message_count": 45
    }
  ],
  "total_count": 15,
  "project_sessions": 8
}

convert_transcript_format

Convert between transcript formats.

Parameters:

  • session_id (string): Session to convert
  • from_format (string): Source format
  • to_format (string): Target format
  • output_path (optional string): Custom output path

Returns:

{
  "converted_path": ".data/transcripts/compact_20240101_100000_abc123.txt",
  "metadata": {
    "original_format": "codex",
    "target_format": "claude"
  }
}

Task Tracker Tools

create_task

Create a new development task.

Parameters:

  • title (string): Task title
  • description (optional string): Detailed description
  • priority (optional string): Priority level ("low", "medium", "high")

Returns:

{
  "task_id": "task_123",
  "task": {
    "title": "Implement user authentication",
    "description": "Add login/logout functionality",
    "priority": "high",
    "status": "pending",
    "created_at": "2024-01-01T10:00:00Z"
  }
}

Usage Examples:

# Create basic task
codex> create_task with title "Fix login bug"

# Create detailed task
codex> create_task with title "Implement user auth" and description "Add OAuth2 support" and priority "high"

list_tasks

List tasks with optional filtering.

Parameters:

  • filter_status (optional string): Filter by status ("pending", "completed", "all")

Returns:

{
  "tasks": [
    {
      "id": "task_123",
      "title": "Fix login bug",
      "status": "pending",
      "priority": "high",
      "created_at": "2024-01-01T10:00:00Z"
    }
  ],
  "count": 1,
  "filter_applied": "pending"
}

Usage Examples:

# List all pending tasks
codex> list_tasks

# List completed tasks
codex> list_tasks with filter_status "completed"

# List all tasks
codex> list_tasks with filter_status "all"

update_task

Update task properties.

Parameters:

  • task_id (string): Task identifier
  • updates (object): Properties to update (title, description, priority, status)

Returns:

{
  "task_id": "task_123",
  "updated": true,
  "task": {
    "title": "Updated task title",
    "status": "in_progress"
  }
}

Usage Examples:

# Update task status
codex> update_task with task_id "task_123" and updates {"status": "in_progress"}

# Update multiple properties
codex> update_task with task_id "task_123" and updates {"title": "New title", "priority": "low"}

complete_task

Mark task as completed.

Parameters:

  • task_id (string): Task identifier

Returns:

{
  "task_id": "task_123",
  "completed": true,
  "completed_at": "2024-01-01T11:00:00Z"
}

Usage Examples:

codex> complete_task with task_id "task_123"

delete_task

Remove a task.

Parameters:

  • task_id (string): Task identifier

Returns:

{
  "task_id": "task_123",
  "deleted": true
}

Usage Examples:

codex> delete_task with task_id "task_123"

export_tasks

Export tasks to external format.

Parameters:

  • format (string): Export format ("markdown", "json")

Returns:

{
  "exported_path": ".codex/tasks/tasks_export.md",
  "format": "markdown",
  "task_count": 5
}

Usage Examples:

# Export to markdown
codex> export_tasks with format "markdown"

# Export to JSON
codex> export_tasks with format "json"

Web Research Tools

search_web

Search the web using DuckDuckGo.

Parameters:

  • query (string): Search query
  • num_results (optional integer): Maximum results to return (default: 5)

Returns:

{
  "query": "python async best practices",
  "results": [
    {
      "title": "Async Best Practices",
      "url": "https://example.com/async-guide",
      "snippet": "Learn async programming patterns..."
    }
  ],
  "cached": false
}

Usage Examples:

# Basic search
codex> search_web with query "python async patterns"

# Limited results
codex> search_web with query "machine learning libraries" and num_results 3

fetch_url

Fetch content from a URL.

Parameters:

  • url (string): URL to fetch
  • extract_text (optional boolean): Extract readable text only (default: false)

Returns:

{
  "url": "https://example.com/guide",
  "content": "<html>...</html>",
  "text_content": "Extracted readable text...",
  "status_code": 200,
  "cached": true
}

Usage Examples:

# Fetch full HTML
codex> fetch_url with url "https://docs.python.org/3/library/asyncio.html"

# Extract text only
codex> fetch_url with url "https://example.com" and extract_text true

summarize_content

Summarize provided content.

Parameters:

  • content (string): Content to summarize
  • max_length (optional integer): Maximum summary length in words (default: 100)

Returns:

{
  "summary": "This guide covers async programming patterns including...",
  "original_length": 1500,
  "summary_length": 85
}

Usage Examples:

# Summarize fetched content
codex> summarize_content with content "Long article text..." and max_length 50

Workflow Patterns

Daily Development Workflow

  1. Start Session:
./amplify-codex.sh --profile development
  1. Initialize Context:
# Automatically loads relevant memories
# Displays available MCP tools
  1. Development Work:
# Edit code files
# Use Codex for assistance
  1. Quality Checks:
codex> check_code_quality with file_paths ["modified_files.py"]
  1. Task Management:
# Create tasks for work items
codex> create_task with title "Implement feature X" and description "Add new functionality"

# Track progress
codex> update_task with task_id "task_123" and updates {"status": "in_progress"}

# Complete tasks
codex> complete_task with task_id "task_123"
  1. Web Research:
# Research solutions
codex> search_web with query "best practices for feature X"

# Fetch documentation
codex> fetch_url with url "https://docs.example.com/feature" and extract_text true
  1. Save Progress:
codex> save_current_transcript with format "standard"
  1. End Session:
# Exit Codex (Ctrl+D)
# Wrapper automatically extracts memories and exports transcript

Task-Driven Development Workflow

  1. Plan Tasks:
# Start session and create initial tasks
./amplify-codex.sh
codex> create_task with title "Design API endpoints" and priority "high"
codex> create_task with title "Implement authentication" and priority "high"
codex> create_task with title "Add unit tests" and priority "medium"
  1. Work on Tasks:
# Update task status when starting work
codex> update_task with task_id "task_1" and updates {"status": "in_progress"}

# Develop code with Codex assistance
# Run quality checks as you work
codex> check_code_quality with file_paths ["api.py"]
  1. Research as Needed:
# Search for implementation details
codex> search_web with query "REST API best practices 2024"

# Fetch specific documentation
codex> fetch_url with url "https://restfulapi.net/" and extract_text true
  1. Complete and Track:
# Mark task complete
codex> complete_task with task_id "task_1"

# Review remaining tasks
codex> list_tasks with filter_status "pending"
  1. Export Task Status:
# Export tasks for documentation
codex> export_tasks with format "markdown"

Research-Assisted Development Workflow

  1. Identify Research Needs:
# Start with research question
./amplify-codex.sh
codex> search_web with query "modern web framework comparison"
  1. Gather Information:
# Fetch detailed content
codex> fetch_url with url "https://example.com/comparison" and extract_text true

# Summarize key points
codex> summarize_content with content "Fetched content..." and max_length 200
  1. Apply Research:
# Use findings in development
# Create tasks based on research
codex> create_task with title "Evaluate framework X" and description "Based on research findings"
  1. Iterate and Validate:
# Continue research as needed
codex> search_web with query "framework X migration guide"

# Validate implementation
codex> check_code_quality with file_paths ["implementation.py"]
  1. Document Findings:
# Save research session
codex> save_current_transcript with format "extended"

CI/CD Integration

GitHub Actions Example:

- name: Code Quality Check
  run: |
    export AMPLIFIER_BACKEND=codex
    export CODEX_PROFILE=ci
    codex exec "check_code_quality with file_paths ['src/', 'tests/']"

Pre-commit Hook:

#!/bin/bash
# .git/hooks/pre-commit

# Run quality checks
codex --profile ci exec "check_code_quality with file_paths [$(git diff --cached --name-only | tr '\n' ',')]"

Code Review Workflow

  1. Setup Review Environment:
./amplify-codex.sh --profile review
  1. Load Code for Review:
codex> read_file with path "src/feature.py"
  1. Run Quality Checks:
codex> check_code_quality with file_paths ["src/feature.py"]
  1. Generate Review Documentation:
codex> save_current_transcript with format "extended"
  1. Export Review Summary:
codex> convert_transcript_format with session_id "review_session" to "claude"

Batch Processing Workflow

Process Multiple Sessions:

# Export all project transcripts
codex> save_project_transcripts with project_dir "." and incremental true

# Convert to consistent format
for session in $(list_sessions.py); do
  codex exec "convert_transcript_format with session_id $session to claude"
done

Automated Quality Assurance:

# Check all Python files
find . -name "*.py" -exec codex exec "check_code_quality with file_paths [{}]" \;

# Generate quality report
codex exec "save_project_transcripts with format compact"

Enhanced Automation

Auto-Quality Checks

The enhanced wrapper script automatically detects modified files and runs quality checks after Codex sessions end.

Features:

  • File change detection using git status or filesystem monitoring
  • Automatic check_code_quality execution on modified files
  • Results display before final cleanup
  • Configurable via flags (--no-auto-checks to disable)

Workflow:

  1. User modifies files during Codex session
  2. Session ends (Ctrl+D)
  3. Wrapper detects changed files
  4. Runs quality checks automatically
  5. Displays results and summary
  6. Proceeds with cleanup

Configuration:

# Enable auto-checks (default)
./amplify-codex.sh

# Disable auto-checks
./amplify-codex.sh --no-auto-checks

Periodic Transcript Saves

Background process automatically saves transcripts at regular intervals during long sessions.

Features:

  • Saves every 10 minutes by default
  • Uses save_current_transcript MCP tool
  • Logs saves to .codex/logs/auto_saves.log
  • Continues session without interruption
  • Configurable interval

Benefits:

  • Prevents data loss in long sessions
  • Enables recovery from interruptions
  • Provides checkpoint backups

Configuration:

# Default 10-minute saves
./amplify-codex.sh

# Custom interval (not yet implemented)
# ./amplify-codex.sh --auto-save-interval 15

Smart Context Detection

Enhanced session initialization with intelligent context gathering.

Features:

  • Detects current git branch and includes in context
  • Finds recent commits and adds to memory search
  • Scans recently modified files for TODO comments
  • Includes project structure information
  • Adapts context based on working directory

Context Sources:

  • Git branch and recent commits
  • Modified files in last session
  • TODO/FIXME comments in codebase
  • Project structure and key files

Benefits:

  • More relevant memory loading
  • Contextual awareness for Codex
  • Improved session continuity

Command Shortcuts

Bash script providing quick commands for common Codex workflows.

Available Shortcuts:

  • codex-init [context] - Quick session initialization
  • codex-check [files...] - Run quality checks
  • codex-save - Save current transcript
  • codex-task-add [title] - Create task
  • codex-task-list - List tasks
  • codex-search [query] - Web search
  • codex-agent [agent-name] [task] - Spawn agent
  • codex-status - Show session status

Setup:

# Source shortcuts in shell
source .codex/tools/codex_shortcuts.sh

# Or add to ~/.bashrc
echo "source /path/to/project/.codex/tools/codex_shortcuts.sh" >> ~/.bashrc

Usage Examples:

# Quick session start
codex-init "Working on authentication"

# Fast quality check
codex-check src/auth.py tests/

# Rapid task creation
codex-task-add "Fix login validation"

# Quick web search
codex-search "oauth2 best practices"

Agent System

Agent Conversion

Agents are converted from Claude Code format using tools/convert_agents.py:

# Convert all agents
python tools/convert_agents.py

# Convert specific agent
python tools/convert_agents.py --agent bug-hunter

Conversion Process:

  1. Reads Claude Code agent from .claude/agents/
  2. Removes Task tool references
  3. Adapts tool array format
  4. Preserves methodology and description
  5. Saves to .codex/agents/

Available Agents by Category

Architecture & Design

  • zen-architect: Minimal complexity architecture design
  • database-architect: Database schema design
  • api-contract-designer: API contract design

Implementation

  • modular-builder: Modular code implementation
  • integration-specialist: System integration

Quality & Testing

  • bug-hunter: Bug investigation and fixing
  • test-coverage: Test coverage analysis
  • security-guardian: Security vulnerability identification

Analysis

  • analysis-engine: Deep code analysis
  • pattern-emergence: Pattern identification
  • insight-synthesizer: Insight synthesis

Knowledge

  • concept-extractor: Concept extraction
  • knowledge-archaeologist: Knowledge discovery
  • content-researcher: Information research

Invocation Methods

Automatic Selection

# Codex auto-selects based on description
codex exec "Find and fix the authentication bug"
# Routes to bug-hunter agent

Manual Selection

# Explicit agent selection
codex exec --agent zen-architect "Design the caching layer"

Programmatic Usage

from amplifier import spawn_agent

result = spawn_agent(
    agent_name="bug-hunter",
    task="Investigate memory leak",
    backend="codex"
)

Spawning Differences from Claude Code

Aspect Claude Code Codex
Invocation Task(agent_name, task) codex exec --agent <name> "<task>"
Tool Access Task, TodoWrite, WebFetch Read, Grep, Glob, Bash, Write
Execution Automatic via Task tool Explicit codex exec command
Context Automatic conversation context Manual context passing
Output Integrated in conversation Separate command output

Agent Context Bridge

Context Serialization

The agent context bridge enables passing conversation context to agents, allowing seamless handoff from main Codex sessions to specialized agents.

Purpose: Bridge the gap between interactive Codex sessions and agent execution by serializing relevant context for agent consumption.

Key Features:

  • Serializes recent conversation messages
  • Includes current task information
  • Captures relevant file references
  • Compresses context to fit token limits
  • Saves to .codex/agent_context.json

Context Components:

  • Recent messages (configurable count)
  • Current working directory
  • Open/modified files
  • Active tasks from task tracker
  • Session metadata

Context Injection

Automatic Integration:

  • Modified CodexAgentBackend.spawn_agent() to use bridge
  • Serializes context before agent execution
  • Passes context via --context-file argument
  • Cleans up context files after execution

Usage:

from .codex.tools.agent_context_bridge import inject_context_to_agent

# Inject context before spawning
context_file = inject_context_to_agent(
    agent_name="bug-hunter",
    task="Fix authentication bug",
    messages=conversation_messages
)

# Spawn with context
result = backend.spawn_agent_with_context("bug-hunter", "Fix auth bug", messages, context_file)

Result Integration

Agent Output Processing:

  • Extracts agent results from execution output
  • Formats for display in main session
  • Saves to .codex/agent_results/[agent_name]_[timestamp].md
  • Includes context metadata

Integration Flow:

  1. Main session serializes context
  2. Agent executes with context
  3. Agent produces output
  4. Bridge extracts and formats results
  5. Results integrated back into main session

Example:

# In main session
codex> spawn_agent_with_context "bug-hunter" "Fix login issue" using recent context

# Agent executes with full context
# Results formatted and displayed
# Saved to agent_results/bug-hunter_20240101_120000.md

Configuration

Context Limits:

[agent_context_bridge]
max_messages = 20
max_tokens = 8000
compression_enabled = true
context_ttl_hours = 1

File Locations:

  • Context files: .codex/agent_context/[session_id].json
  • Results: .codex/agent_results/[agent]_[timestamp].md
  • Logs: .codex/logs/agent_bridge.log

Benefits

Improved Agent Effectiveness:

  • Agents receive full conversation context
  • Better task understanding
  • Reduced context loss during handoff

Seamless Workflow:

  • No manual context copying
  • Automatic result integration
  • Session continuity maintained

Enhanced Debugging:

  • Context preservation for troubleshooting
  • Result logging for audit trails
  • Performance metrics tracking

Transcript Management

Transcript Formats

Standard Format (transcript.md)

  • Purpose: Conversation-focused markdown
  • Content: User/assistant messages with tool interactions
  • Use Case: Human-readable session review

Extended Format (transcript_extended.md)

  • Purpose: Detailed session analysis
  • Content: All events, raw JSON, metadata, statistics
  • Use Case: Debugging, detailed analysis

Compact Format

  • Purpose: Space-efficient storage
  • Content: Condensed conversation without metadata
  • Use Case: Archival, bulk processing

Storage Locations

Backend Location Structure
Codex Global ~/.codex/transcripts/ Session directories
Codex Local .codex/transcripts/ Project-specific exports
Claude Code .data/transcripts/ Individual files

Session Directory Structure

2024-01-01-10-00-AM__project__abc123/
├── transcript.md              # Standard format
├── transcript_extended.md     # Extended format
├── history.jsonl             # Raw event log
└── meta.json                 # Session metadata

Working with Transcripts

Using Transcript Manager

# List all transcripts
python tools/transcript_manager.py list

# Load specific transcript
python tools/transcript_manager.py load abc123

# Search across backends
python tools/transcript_manager.py search "error handling"

# Convert formats
python tools/transcript_manager.py convert abc123 --from codex --to claude

Direct Codex Tools

# Export current session
codex> save_current_transcript with format "both"

# List available sessions
codex> list_available_sessions

# Batch export project
codex> save_project_transcripts with project_dir "."

Format Conversion

Codex to Claude Code:

python tools/transcript_manager.py convert session_id --from codex --to claude

Claude Code to Codex:

python tools/transcript_manager.py convert session_id --from claude --to codex

Bidirectional Conversion:

  • Preserves conversation content
  • Adapts metadata format
  • Maintains tool interaction details
  • Handles format-specific features

Session Management

Wrapper Script Usage

Basic Usage:

./amplify-codex.sh

Profile Selection:

./amplify-codex.sh --profile ci
./amplify-codex.sh --profile review

Manual Control:

# Skip initialization
./amplify-codex.sh --no-init

# Skip cleanup
./amplify-codex.sh --no-cleanup

Manual Session Management

Initialize Session:

uv run python .codex/tools/session_init.py --prompt "Working on feature"

Start Codex:

codex --profile development

Use MCP Tools During Session:

codex> initialize_session with prompt "Continue working"
codex> check_code_quality with file_paths ["file.py"]
codex> create_task with title "New task"
codex> search_web with query "research topic"
codex> save_current_transcript

Cleanup Session:

uv run python .codex/tools/session_cleanup.py

Session Lifecycle

  1. Initialization Phase:

    • Load relevant memories
    • Create session context
    • Start MCP servers
  2. Active Session Phase:

    • User interacts with Codex
    • MCP tools called as needed
    • Progress saved periodically
  3. Cleanup Phase:

    • Extract memories from conversation
    • Export transcript
    • Clean up temporary files

MCP Tool Integration

Session Start:

codex> initialize_session with prompt "Starting new feature"

During Work:

codex> check_code_quality with file_paths ["modified.py"]
codex> create_task with title "Implement feature"
codex> search_web with query "best practices"
codex> save_current_transcript with format "standard"

Session End:

codex> finalize_session with recent messages

Backend Abstraction

Programmatic Usage

from amplifier import get_backend, set_backend

# Set backend
set_backend("codex")

# Get backend instance
backend = get_backend()

# Unified API
result = backend.initialize_session("Working on feature")
result = backend.run_quality_checks(["file.py"])
result = backend.export_transcript(format="extended")
result = backend.manage_tasks("create", title="New task")
result = backend.search_web("query", num_results=5)

Configuration Management

from amplifier.core.config import get_backend_config

config = get_backend_config()
print(f"Backend: {config.amplifier_backend}")
print(f"Profile: {config.codex_profile}")

Integration Examples

Custom Script:

#!/usr/bin/env python3
from amplifier import get_backend

def development_workflow():
    backend = get_backend()

    # Initialize
    result = backend.initialize_session("New feature development")
    print(f"Loaded {result['metadata']['memoriesLoaded']} memories")

    # Quality checks
    result = backend.run_quality_checks(["src/feature.py"])
    if not result["success"]:
        print("Quality checks failed!")
        return

    # Task management
    result = backend.manage_tasks("create", title="Implement feature", description="Add new functionality")
    task_id = result["task_id"]

    # Web research
    result = backend.search_web("best practices for feature", num_results=3)
    print(f"Found {len(result['results'])} research results")

    # Export transcript
    result = backend.export_transcript()
    print(f"Transcript saved to {result['data']['path']}")

if __name__ == "__main__":
    development_workflow()

CI/CD Integration:

# ci_check.py
from amplifier import get_backend

def ci_quality_check():
    backend = get_backend()

    # Get changed files
    import subprocess
    result = subprocess.run(["git", "diff", "--name-only", "HEAD~1"],
                          capture_output=True, text=True)
    files = result.stdout.strip().split('\n')

    # Run checks
    result = backend.run_quality_checks(files)
    return result["success"]

if __name__ == "__main__":
    success = ci_quality_check()
    exit(0 if success else 1)

Advanced Topics

Custom MCP Servers

Create New Server:

# .codex/mcp_servers/custom/server.py
from mcp.server.fastmcp import FastMCP
from ..base import MCPLogger

logger = MCPLogger("custom")
mcp = FastMCP("amplifier_custom")

@mcp.tool()
def custom_tool(param: str) -> dict:
    """Custom tool description"""
    # Implementation
    return {"result": "custom output"}

if __name__ == "__main__":
    mcp.run()

Add to Configuration:

[mcp_servers.amplifier_custom]
command = "uv"
args = ["run", "python", ".codex/mcp_servers/custom/server.py"]

[profiles.custom]
mcp_servers = ["amplifier_session", "amplifier_custom"]

Extending Existing Servers

Add Tool to Session Manager:

# In session_manager/server.py
@mcp.tool()
def custom_memory_search(query: str, limit: int = 5) -> dict:
    """Search memories with custom logic"""
    # Custom search implementation
    return {"memories": [], "count": 0}

Performance Optimization

Memory System Tuning:

# Disable memory system for faster startup
MEMORY_SYSTEM_ENABLED=false codex --profile development

# Use compact transcripts for faster export
codex> save_current_transcript with format "compact"

MCP Server Optimization:

  • Keep tool implementations lightweight
  • Use async operations where possible
  • Cache expensive computations
  • Implement proper error handling

Profile Optimization:

[profiles.fast]
mcp_servers = ["amplifier_quality"]  # Minimal servers

Troubleshooting

Installation Issues

Codex CLI not found:

# Check installation
which codex

# Reinstall Codex
# Follow: https://docs.anthropic.com/codex/installation

# Add to PATH
export PATH="$HOME/.codex/bin:$PATH"

uv not available:

# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# Verify installation
uv --version

Python version issues:

# Check Python version
python --version  # Should be 3.11+

# Use specific Python
uv run --python 3.11 python --version

Configuration Issues

Config file not found:

# Create config directory
mkdir -p .codex

# Initialize config
codex --config .codex/config.toml --init

# Verify config
cat .codex/config.toml

Profile not working:

# List available profiles
codex --list-profiles

# Check profile syntax
codex --profile development --validate-config

Environment variables not recognized:

# Check variable setting
echo $AMPLIFIER_BACKEND

# Set in current session
export AMPLIFIER_BACKEND=codex
export CODEX_PROFILE=development

MCP Server Issues

Server startup failures:

# Check server logs
tail -f .codex/logs/session_manager.log

# Test server directly
uv run python .codex/mcp_servers/session_manager/server.py

# Verify imports
python -c "from amplifier.memory import MemoryStore"

Tool registration errors:

# Check MCP protocol
mcp-inspector uv run python .codex/mcp_servers/session_manager/server.py

# Validate tool definitions
python -c "from .codex.mcp_servers.session_manager.server import mcp; print(mcp.list_tools())"

Communication failures:

# Test stdio communication
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}' | \
uv run python .codex/mcp_servers/session_manager/server.py

# Check for JSON parsing errors
tail -f .codex/logs/*.log | grep -i error

Memory System Issues

Memory loading failures:

# Check memory system status
python -c "from amplifier.memory import MemoryStore; print('Memory system OK')"

# Verify memory files exist
ls .data/memories/

# Check memory system enabled
echo $MEMORY_SYSTEM_ENABLED

Memory extraction timeouts:

# Increase timeout (if configurable)
# Check logs for timeout details
tail -f .codex/logs/session_manager.log

# Run extraction manually
uv run python .codex/tools/session_cleanup.py --no-timeout

Quality Check Issues

make check not found:

# Verify Makefile exists
ls Makefile

# Check make target
make check

# Verify uv available in PATH
which uv

Tool execution failures:

# Test tools individually
uv run ruff check .
uv run pyright
uv run pytest

# Check tool installation
uv pip list | grep -E "(ruff|pyright|pytest)"

Worktree environment issues:

# Check VIRTUAL_ENV
echo $VIRTUAL_ENV

# Temporarily unset for worktree
unset VIRTUAL_ENV
make check

Transcript Issues

Session not found:

# List available sessions
codex> list_available_sessions

# Check session directory
ls ~/.codex/sessions/

# Verify session ID format
ls ~/.codex/sessions/ | head -5

Export failures:

# Check write permissions
touch .codex/transcripts/test.txt

# Verify session data
ls ~/.codex/sessions/session_id/

# Check logs for export errors
tail -f .codex/logs/transcript_saver.log

Format conversion issues:

# Test conversion tool
python tools/transcript_manager.py convert session_id --from codex --to claude

# Check source transcript exists
ls .codex/transcripts/session_id/

# Verify conversion logs
tail -f .codex/logs/conversion.log

Agent Issues

Agent not found:

# List available agents
ls .codex/agents/

# Check agent file format
head .codex/agents/bug-hunter.md

# Verify YAML frontmatter
python -c "import yaml; print(yaml.safe_load(open('.codex/agents/bug-hunter.md')))"

Agent execution failures:

# Test agent spawning
codex exec --agent bug-hunter "test task"

# Check Codex logs
codex --log-level debug exec --agent bug-hunter "test"

# Verify tool permissions
cat .codex/config.toml | grep -A 5 "tool_permissions"

Wrapper Script Issues

Script not executable:

# Make executable
chmod +x amplify-codex.sh

# Check permissions
ls -la amplify-codex.sh

Prerequisite checks failing:

# Test prerequisites manually
./amplify-codex.sh --check-only

# Check Codex installation
codex --version

# Check virtual environment
ls .venv/

# Check uv
uv --version

Session initialization failures:

# Run initialization manually
uv run python .codex/tools/session_init.py --verbose

# Check logs
cat .codex/logs/session_init.log

# Verify memory system
echo $MEMORY_SYSTEM_ENABLED

Best Practices

When to Use Codex

Choose Codex when:

  • Working in headless environments (servers, CI/CD)
  • Needing programmatic control over AI interactions
  • Using editors other than VS Code
  • Requiring custom MCP server integrations
  • Working in team environments with mixed IDE preferences

Choose Claude Code when:

  • Primary development in VS Code
  • Preferring automatic hook-based workflows
  • Needing TodoWrite and WebFetch tools
  • Wanting seamless IDE integration

Workflow Recommendations

Daily Development:

  1. Use wrapper script for full automation
  2. Start with memory loading via initialize_session
  3. Run quality checks after significant changes
  4. Create and manage tasks with task tracker
  5. Research as needed with web tools
  6. Save transcripts periodically
  7. Let cleanup handle memory extraction

CI/CD Integration:

  1. Use minimal profiles (ci/review)
  2. Run quality checks on changed files
  3. Export transcripts for audit trails
  4. Fail builds on quality check failures

Code Review:

  1. Use review profile with quality + transcript + task servers
  2. Load code under review
  3. Run comprehensive quality checks
  4. Create review tasks
  5. Generate detailed transcripts for documentation

Performance Tips

Optimize Memory System:

# Disable memory system for faster startup
MEMORY_SYSTEM_ENABLED=false codex --profile development

# Use compact transcripts for faster export
codex> save_current_transcript with format "compact"

MCP Server Optimization:

  • Keep tool implementations lightweight
  • Use async operations where possible
  • Cache expensive computations
  • Implement proper error handling

Profile Optimization:

[profiles.fast]
mcp_servers = ["amplifier_quality"]  # Minimal servers

Feature Parity

Overall Parity Score:

  • Before Changes: 85% feature parity with Claude Code
  • After Changes: 95% feature parity with Claude Code
  • Improvement: +10% through new MCP servers and enhancements

Feature Comparison:

Feature Category Claude Code Codex (Before) Codex (After) Status
Memory System ✅ Full ✅ Full ✅ Full Complete
Quality Checks ✅ Full ✅ Full ✅ Full + Auto Enhanced
Transcript Management ✅ Full ✅ Full ✅ Full + Periodic Enhanced
Agent Spawning ✅ Full ⚠️ Manual ✅ Context Bridge Major Improvement
Task Tracking ✅ TodoWrite ❌ None ✅ Full MCP Server New Feature
Web Research ✅ WebFetch ❌ None ✅ Full MCP Server New Feature
Automation ✅ Hooks ⚠️ Script ✅ Enhanced Script Improved
Command System ✅ Slash Commands ❌ None ✅ Bash Shortcuts New Feature
IDE Integration ✅ VS Code Native ❌ None ❌ None Architectural Gap

Key Improvements:

  • Task Tracking: Complete TodoWrite equivalent with session-scoped task management
  • Web Research: Full WebFetch equivalent with search, fetch, and summarization
  • Agent Context Bridge: Seamless context passing from sessions to agents
  • Enhanced Automation: Auto-quality checks, periodic saves, smart context detection
  • Command Shortcuts: Bash functions for common workflows

Remaining Gaps (5%):

  • VS Code native integration (deep IDE hooks)
  • Real-time notifications
  • Rich command completion
  • Automatic file watching
  • Native slash command system

Recommendation: Use Codex for 95% of workflows with Claude Code reserved for VS Code-native features requiring deep IDE integration.