Guide

OpenAI Codex CLI Guide for GTM Teams

Install to first shipped workflow on Codex CLI. The same job, the same patterns, on OpenAI's runtime.

OpenAI Codex CLI Guide for GTM Teams
OpenAI Codex CLI Guide for GTM Teams

What the Codex CLI Is

OpenAI Codex ships as four surfaces sharing one model and one account: terminal CLI (open source, Rust), IDE extension (VS Code, JetBrains), cloud agent (delegated from ChatGPT), and GitHub bot. The CLI is what most GTM Engineers reach for first because it fits the terminal-native workflow that GTM Engineering work demands.

The CLI runs codex for interactive sessions and codex exec for headless runs. Configuration lives in ~/.codex/config.toml. Project context lives in AGENTS.md at the project root. MCP servers wire into the config.toml for integration with external tools.

For the Codex-on-IDE pattern, see the Cursor vs Codex comparison. For the Claude Code equivalent setup, see how to set up Claude Code for GTM outbound.

Step 1: Install Codex CLI

On macOS:

brew install openai/codex/codex

On Ubuntu/Debian:

apt install codex (after adding the OpenAI apt repository per the docs).

On Windows: download the installer from developers.openai.com/codex/cli or use WSL with the apt path.

Authenticate:

codex login

This opens a browser window for OAuth. Use your OpenAI account credentials. The token gets stored locally. You can verify the install worked:

codex --version

Step 2: Set Up the Project

Create a project directory for your GTM workflows. Most teams use ~/gtm-agents/ or a Git repo in your team's GitHub org.

mkdir ~/gtm-agents && cd ~/gtm-agents && git init

Inside, you'll add an AGENTS.md (project context), a ~/.codex/config.toml (MCP wiring), and subdirectories for each workflow.

Step 3: Write the AGENTS.md

AGENTS.md is the open standard for agent project context. Codex reads it automatically at session start. Six sections matter for GTM teams.

Company context (10-15 lines). What your company does, your product, your market position.

ICP definition (30-50 lines). Primary and secondary ICP rules with specific firmographic thresholds.

Voice and style (15-30 lines). Tone, sentence length, banned phrases.

Glossary (10-20 lines). Terms your team uses with specific meanings.

Workflow conventions (10-25 lines). How drafts are staged, how CRM writes are tagged, where outputs go.

Guardrails (10-20 lines). Hard rules the agent should never break.

For the full template, see the CLAUDE.md template for GTM teams. The same structure works for AGENTS.md, since the format is shared.

Step 4: Wire MCP Servers in config.toml

Open ~/.codex/config.toml and add MCP server blocks.

For HubSpot:

[mcp_servers.hubspot]
url = "https://mcp.hubspot.com/anthropic"
bearer_token_env_var = "HUBSPOT_OAUTH_TOKEN"

For Clay:

[mcp_servers.clay]
url = "https://api.clay.com/mcp"
bearer_token_env_var = "CLAY_TOKEN"

For a local stdio server (database, custom script):

[mcp_servers.warehouse]
command = "npx"
args = ["-y", "@bytebase/dbhub", "--dsn", "postgresql://readonly:pass@host:5432/leads"]

Store tokens in environment variables (export in your shell rc file). Reference the variable names in config.toml. Never commit secrets.

For the Codex MCP HubSpot deep dive, see Codex MCP HubSpot.

Step 5: Run Your First Interactive Session

From your project directory:

cd ~/gtm-agents && codex

This opens an interactive session. Codex loads AGENTS.md and the configured MCP servers. Prompt it: "Help me build a workflow that reads a list of company domains from a Clay table called 'research_queue' and writes a research brief to each company's HubSpot record."

The agent walks through the structure. You iterate. After 30 to 45 minutes you have a working workflow saved as a runbook in your project. Test it on 10 real companies. Verify the output.

Step 6: Schedule with codex exec

Once a workflow runs cleanly, automate it. codex exec is the non-interactive mode.

codex exec "process the research queue from HubSpot, writing summaries back to each company"

Schedule as a cron job on a small VM. For a workflow that runs every weekday at 7 AM:

0 7 * * 1-5 cd ~/gtm-agents && codex exec "process research queue" >> logs/research.log 2>&1

Pipe stdout to a log file. Pipe stderr to Slack via a small alert wrapper. Track tokens consumed per run and alert when it doubles.

Codex-Specific Features GTM Teams Use

Approval modes. Codex has tiered approval modes (auto, ask-once, ask-every) controlling how much it does without user confirmation. For outbound workflows, run in ask-every until trust is built, then move to ask-once or auto for low-risk steps.

Sandboxed execution. Codex runs shell commands in a sandbox by default. This limits what a runaway step can touch on the host. Keep the sandbox on for production workflows.

Cloud delegation. For long-running jobs (1000+ records), use the cloud agent surface delegated from ChatGPT. Kick off the job from chat, walk away, check results later. Useful for batched research and refactor jobs that would tie up local compute.

Per-server controls. config.toml exposes startup_timeout_sec, tool_timeout_sec, and enabled_tools/disabled_tools per server. Use the disabled_tools list to block destructive operations even if the OAuth scope permits them.

What to Build First

Same advice as for Claude Code. Start with account research. Read-only on customer data, immediate visible value, low risk if it breaks.

Week 2: pre-call brief generator. Week 3: enrichment workflow with CRM write-back. Week 4: reply triage. Don't try to ship 5 workflows in the first month.

For the full sales agent build pattern on Codex, see Build an AI Sales Agent with OpenAI Codex. For the AI SDR-specific build, see the equivalent AI SDR with Claude Code guide and substitute codex exec for claude -p. The patterns translate directly.

Authoritative References

For Codex CLI install, config.toml format, and codex exec, see OpenAI's Codex CLI documentation. For MCP setup specifically, see the Codex MCP guide. For the AGENTS.md format shared across runtimes, see the AGENTS.md specification.

Frequently Asked Questions

Is the Codex CLI different from Codex in the IDE or ChatGPT?

Same underlying model and account, different surface. The Codex CLI is the terminal-native version, open source and written in Rust. The IDE extension runs in VS Code and JetBrains. The cloud agent is the ChatGPT-delegated version. The GitHub bot acts on PRs and issues. All four share your OpenAI account and the same model tier. GTM Engineers usually live in the CLI and the cloud agent for production work, with the IDE extension as a backup for editor-centric tasks.

How do I install the OpenAI Codex CLI?

Through Homebrew on macOS, apt on Ubuntu/Debian, or the platform installer on Windows. The exact command is documented at developers.openai.com/codex/cli. After install, authenticate with your OpenAI account using codex login. The first command after auth should be codex --version to confirm it's working. Most GTM Engineers complete install and first run in under 15 minutes.

What is AGENTS.md and why does Codex use it?

AGENTS.md is the open standard for project-level agent context, similar in spirit to Claude Code's CLAUDE.md. Codex reads it automatically at the start of every session in the project directory. It's where you put company info, ICP rules, voice guidelines, and conventions. The standard is shared across agent runtimes, so the same file can context multiple tools. For GTM teams using both Codex and Claude Code, this means one file covers both.

How do I run a headless Codex workflow on a schedule?

codex exec is the non-interactive command that runs the task and exits. Schedule it as a cron job on a small always-on machine: 0 7 * * 1-5 cd ~/gtm-agents && codex exec "process today's research queue" >> logs/research.log. The job loads your config.toml, opens the necessary MCP connections, runs the task, and exits. Pipe stdout to a log file. Pipe failures to a Slack alert.

Is Codex CLI better for GTM teams than the cloud agent?

Different jobs. The CLI fits interactive build sessions where you want to watch the agent work and iterate fast. The cloud agent fits long-running delegated tasks where you queue work and review results later. Most GTM Engineers use the CLI for the daily build work and the cloud agent for batched jobs (research 500 accounts, refactor a pipeline). The decision per task is whether you're driving the work or delegating it.

Source: State of GTM Engineering Report 2026 (n=228). Salary data combines survey responses from 228 GTM Engineers across 32 countries with analysis of 3,342 job postings.

Get the Weekly Pulse

Salary shifts, tool intel, and job market data for GTM Engineers. Weekly playbooks for shipping Codex CLI workflows in GTM teams.