Codex CLIチートシート:開発者向けコマンド完全ガイド

#Tech

Codex CLIチートシート:開発者向けコマンド完全ガイド Codex CLIによる開発

Codex CLIは、ターミナルUIを通じて大規模言語モデルとの高度な対話を実現する開発者向けツールです。

対話的セッション、非対話型スクリプト実行、および様々なスラッシュコマンドを提供し、コーディングやレビューを効率化します。

また、MCPサーバー、サブエージェント、プラグインなどの機能を通じて、AIによる複雑なワークフローの自動化を可能にします。

各種グローバルフラグや設定ファイルにより、モデルやサンドボックス設定を柔軟にカスタマイズできます。

原文の冒頭を表示(英語・3段落のみ)

Printable single-page A4 JPEG reference for developersLast updated: 09/05/2026Concise reference for the Codex CLI: terminal UI, codex exec, local config, MCP, skills, subagents, hooks, rules, and automation.🚀 Start HereCommandUsecodexOpen the interactive terminal UI in the current directorycodex "prompt"Start an interactive session with an initial instructioncodex exec "prompt" / codex e "prompt"Run Codex non-interactively for scripts or CIcodex resumePick and resume a previous interactive sessioncodex resume --lastResume the latest session for this directorycodex fork --lastFork the latest session into a new threadcodex loginSign in with ChatGPT OAuthcodex login --device-authSign in on remote/headless machinescodex login --with-api-keyStore API-key auth from stdin, e.g. pipe OPENAI_API_KEYcodex login statusCheck auth; exits 0 when logged incodex logoutRemove cached credentialscodex updateCheck/apply a CLI update when supportedcodex completion <shell>Generate completions for bash, zsh, fish, power-shell, or elvish🖥️ Interactive TUIInputAction@Fuzzy file search; insert a path into the prompt/commandRun a slash command!cmdRun a local shell command under current approvals/sandboxCtrl+C or /exitExit the sessionCtrl+LClear/redraw screen without starting a new conversationCtrl+O or /copyCopy latest completed Codex outputCtrl+RSearch prompt historyCtrl+GOpen prompt in $VISUAL or $EDITORTab while Codex runsQueue follow-up prompt, slash command, or ! commandEnter while Codex runsInject instructions into the current turnEsc Esc on empty composerEdit previous user message; keep pressing Esc to go further back⚡ Slash CommandsUse /help in the TUI for the exact command list in your installed version.CommandUse/statusInspect current session state, workspace, and session id/permissionsSwitch approval/sandbox mode/clearClear current conversation context/compactSummarize long context; Codex can also auto-compact/resumeResume a saved conversation from the TUI/forkBranch a new thread from the current transcript/sideStart a side conversation/modelSwitch model and reasoning choices/fast on, /fast off, /fast statusToggle or inspect Fast mode/planEnter Plan mode before implementation/review [focus]Run local code review presets/mcpShow active MCP servers/agentSwitch/inspect active subagent threads/appsUse enabled ChatGPT app/connectors from the CLI/pluginsBrowse, install, uninstall, or toggle plugins/skills or $skill-nameBrowse or explicitly invoke skills/themePreview/save syntax theme to tui.theme/mentionAttach a specific file as context/experimentalToggle experimental features into config/personalityChange supported-model communication style/feedbackSend feedback, unless disabled by config⚙️ Global FlagsFlagUse--model <model>, -mOverride configured model, e.g. gpt-5.5 or gpt-5.4--profile <name>, -pLoad [profiles.<name>] from config.toml--config key=value, -c key=valueOne-off config override; value is parsed as TOML--cd <path>, -C <path>Set workspace root before Codex starts--add-dir <path>Grant extra writable roots; repeatable--image <path[,path...]>, -iAttach image files to the first prompt--sandbox <mode>, -sread-only, workspace-write, or danger-full-access--ask-for-approval <mode>, -auntrusted, on-request, or never--searchUse live web search instead of cached search--ossUse local OSS provider; requires Ollama or configured local provider--enable <feature> / --disable <feature>Force feature flag on/off for this run--no-alt-screenDisable alternate-screen TUI rendering--remote ws://host:portConnect TUI to a remote app server--remote-auth-token-env ENVRead remote WebSocket bearer token from env var--yoloAlias for --dangerously-bypass-approvals-and-sandbox ⚠️🤖 codex execCommand / FlagUsecodex exec "prompt"Run once; progress on stderr, final answer on stdoutcodex exec -Read the full prompt from stdincodex exec "instruction" with piped stdinTreat command output as extra contextcodex exec resume --last "prompt"Continue latest non-interactive sessioncodex exec resume <SESSION_ID> "prompt"Resume a specific exec session--jsonEmit JSONL events: turns, items, tools, plans, errors--output-last-message <file>, -o <file>Save final assistant message--output-schema <file>Require final output matching JSON Schema--ephemeralDo not persist session rollout files--ignore-user-configSkip $CODEX_HOME/config.toml--ignore-rulesSkip user/project .rules files--skip-git-repo-checkAllow running outside a Git repo--color always, never, or autoControl ANSI colorCODEX_API_KEY=... codex exec ...API-key auth for a single exec workflow🔐 Approvals & SandboxSettingMeaning--sandbox read-onlyRead files only; no edits or commands without approval--sandbox workspace-writeRead/edit inside workspace and --add-dir roots--sandbox danger-full-accessNo filesystem sandbox; use only in isolated environments--ask-for-approval untrustedPrompt before untrusted commands--ask-for-approval on-requestPrompt when Codex requests escalation--ask-for-approval neverNever prompt; best for non-interactive, tightly sandboxed runsapprovals_reviewer = "auto_review"Route eligible approvals through automatic reviewapproval_policy = { granular = { ... } }Allow/deny categories such as sandbox, rules, MCP, skillsdefault_permissions = ":workspace"Use built-in permission profiledefault_permissions = "custom"Use [permissions.custom] profileRecommended default: codex --sandbox workspace-write --ask-for-approval on-request.Protected in workspace-write mode: .git/, .codex/, and .agents/ are read-only when present. Use --add-dir or named permission profiles before reaching for full access.🧩 Config Files & KeysPath / KeyUse~/.codex/config.tomlUser config.codex/config.tomlProject config; loaded only for trusted projects/etc/codex/config.tomlUnix system config, if presentCODEX_HOMEOverrides ~/.codex state/config root~/.codex/auth.jsonFile credential cache; treat like a password~/.codex/history.jsonlLocal history when enabled~/.codex/log/Local logs such as codex-tui.logrequirements.tomlAdmin-enforced constraintsPrecedence: CLI flags/-c > profile > project .codex/config.toml > user config > system config > defaults.Common KeyValues / UsemodelDefault modelreview_modelModel override for /reviewmodel_providerProvider id, default openaiopenai_base_urlProxy/data-residency base URL for built-in OpenAI providermodel_reasoning_effortminimal, low, medium, high, xhighplan_mode_reasoning_effortPlan-mode-specific effort overridemodel_reasoning_summaryauto, concise, detailed, nonemodel_verbositylow, medium, highpersonalitynone, friendly, pragmaticservice_tierflex or fastweb_searchcached, live, or disabledproject_root_markersRoot detection markers, e.g. [".git", ".hg"]project_doc_max_bytesMax bytes read from AGENTS.md guidanceproject_doc_fallback_filenamesExtra instruction filenamesfile_openervscode, cursor, windsurf, vscode-insiders, nonehistory.persistencesave-all or noneanalytics.enabledLocal analytics togglefeedback.enabledEnable /feedbackcli_auth_credentials_storefile, keyring, or auto🧠 Models, Speed, SearchFeatureHowRecommended modelUse gpt-5.5 when available; otherwise gpt-5.4Switch model in TUI/modelSet model for runcodex --model gpt-5.5Fast mode/fast on, /fast off, /fast statusPersist fast modeservice_tier = "fast" and [features].fast_mode = trueCodex-Sparkgpt-5.3-codex-spark, fast research-preview model for Pro usersCached searchDefault local web search modeLive search--search or web_search = "live"Disable searchweb_search = "disabled"📁 AGENTS.md GuidanceLocationPurpose~/.codex/AGENTS.mdGlobal personal guidance~/.codex/AGENTS.override.mdTemporary global override<repo>/AGENTS.mdRepo-level shared instructions<subdir>/AGENTS.override.mdLocal override for a subtreeproject_doc_fallback_filenamesTreat other files as instruction filesDiscovery order: global first, then project root down to current directory. In each directory Codex prefers AGENTS.override.md, then AGENTS.md, then fallback filenames. Later, closer files win.Use /init to scaffold a starter AGENTS.md.🔌 MCPCommand / ConfigUse/mcpView active MCP servers in TUIcodex mcp list [--json]List configured serverscodex mcp get <name> [--json]Show one servercodex mcp add <name> -- <command...>Add stdio servercodex mcp add <name> --url https://...Add streamable HTTP servercodex mcp remove <name>Remove servercodex mcp login <name>OAuth login for supported HTTP serverscodex mcp logout <name>Remove stored MCP OAuth credentialscodex mcp-serverRun Codex itself as an MCP server over stdiomcp_servers.<id> KeyUsecommand, args, env, env_vars, cwdStdio server launchurl, bearer_token_env_varStreamable HTTP serverhttp_headers, env_http_headersStatic/env-backed HTTP headersenabled = falseDisable without deletingrequired = trueFail startup/resume if server cannot initializestartup_timeout_sec, tool_timeout_secServer/tool timeoutsenabled_tools, disabled_toolsTool allow/deny listsmcp_oauth_callback_port, mcp_oauth_callback_urlOAuth callback overrides🛠️ Skills & PluginsSurfaceUse$skill-nameExplicitly invoke a skill/skillsBrowse available skills$skill-creatorScaffold a new skill$skill-installer <name>Install curated/local skills[[skills.config]] path = ".../SKILL.md"; enabled = falseDisable a skill/pluginsBrowse/install/uninstall/toggle plugins in CLIcodex plugin marketplace add <source>Add plugin marketplacecodex plugin marketplace upgrade [name]Refresh marketplace(s)codex plugin marketplace remove <name>Remove marketplaceSkill LocationScope.agents/skills/<name>/SKILL.mdRepo/team skill, searched from CWD up to repo root$HOME/.agents/skills/<name>/SKILL.mdUser skill/etc/codex/skills/<name>/SKILL.mdAdmin/system skillBundled skillsBuilt into CodexSKILL.md requires name and description. Optional folders: scripts/, references/, assets/, and agents/openai.yaml. Package reusable skills as plugins when you want distribution plus optional apps/MCP config.👥 SubagentsConceptUseBuilt-insdefault, worker, explorer/agentSwitch between active agent threadsExplicit promptCodex only spawns subagents when you askagents.max_threadsConcurrent open agent cap; default 6agents.max_depthSpawn nesting depth; default 1agents.job_max_runtime_secondsDefault timeout for CSV fan-out workersspawn_agents_on_csvExperimental batch fan-out from CSVCustom agents live in ~/.codex/agents/*.toml or .codex/agents/*.toml and require:name = "reviewer"

description = "PR reviewer focused on correctness, security, and missing tests."

developer_instructions = "Review code like an owner. Lead with real risks."

※ 著作権に配慮し、引用は冒頭3段落までです。続きは元記事をご覧ください。

元記事を読む ↗