OpenAI Codex CLI 的 slash commands 用来不离开终端就控制会话:切换模型、调整权限、查看状态、清理上下文、审查改动和切换辅助线程。常用命令包括 /model/fast/personality/permissions/approve/diff/status/compact;任务运行中可输入命令后按 Tab 进入队列,等当前轮次结束再执行。

OpenAI Codex CLI Slash Commands

在 OpenAI Codex CLI 里,输入 / 可以打开 slash popup,从命令列表里直接选择操作。适合想快速切换模型、修改审批策略、附加上下文、查看 Git diff,或者在长对话后压缩上下文的场景。

内置 slash commands

Codex 自带下面这些命令。打开 slash popup 后继续输入命令名,可以过滤列表。

当任务已经在运行时,你可以输入 slash command 再按 Tab,把它排到下一轮执行。Codex 会在当前轮结束后才解析这些 queued slash commands,所以命令菜单和错误提示也会在那之后出现。slash completion 仍然可以在你把命令排队之前使用。

Command Purpose When to use it
/permissions Set what Codex can do without asking first. Relax or tighten approval requirements mid-session, such as switching between Auto and Read Only.
/ide Include open files, current selection, and other IDE context. Pull editor context into the next prompt without re-explaining what’s open in your IDE.
/keymap Remap TUI keyboard shortcuts. Inspect and persist custom shortcut bindings in config.toml.
/vim Toggle Vim mode for the composer. Switch between Vim normal/insert behavior and the default composer editing mode.
/sandbox-add-read-dir Grant sandbox read access to an extra directory (Windows only). Unblock commands that need to read an absolute directory path outside the current readable roots.
/agent Switch the active agent thread. Inspect or continue work in a spawned subagent thread.
/apps Browse apps (connectors) and insert them into your prompt. Attach an app as $app-slug before asking Codex to use it.
/plugins Browse installed and discoverable plugins. Inspect plugin tools, install suggested plugins, or manage plugin availability.
/hooks Review lifecycle hooks. Inspect configured hooks, trust new or changed hooks, or disable non-managed hooks before they run.
/clear Clear the terminal and start a fresh chat. Reset the visible UI and conversation together when you want a fresh start.
/compact Summarize the visible conversation to free tokens. Use after long runs so Codex retains key points without blowing the context window.
/copy Copy the latest completed Codex output. Grab the latest finished response or plan text without manually selecting it. You can also press Ctrl+O.
/diff Show the Git diff, including files Git isn’t tracking yet. Review Codex’s edits before you commit or run tests.
/exit Exit the CLI (same as /quit). Alternative spelling; both commands exit the session.
/experimental Toggle experimental features. Enable optional features such as subagents from the CLI.
/approve Approve one retry of a recent auto review denial. Retry a command or action that the auto reviewer denied.
/memories Configure memory use and generation. Turn memory injection or memory generation on or off without leaving the TUI.
/skills Browse and use skills. Improve task-specific behavior by selecting a relevant local skill.
/hooks View and manage lifecycle hooks. Inspect hook configuration loaded into the current session.
/feedback Send logs to the Codex maintainers. Report issues or share diagnostics with support.
/init Generate an AGENTS.md scaffold in the current directory. Capture persistent instructions for the repository or subdirectory you’re working in.
/logout Sign out of Codex. Clear local credentials when using a shared machine.
/mcp List configured Model Context Protocol (MCP) tools. Check which external tools Codex can call during the session; add verbose for server details.
/mention Attach a file to the conversation. Point Codex at specific files or folders you want it to inspect next.
/model Choose the active model (and reasoning effort, when available). Switch between general-purpose models (gpt-4.1-mini) and deeper reasoning models before running a task.
/fast Toggle a Fast service tier when the model catalog exposes one. Turn the current model’s Fast tier on or off, or check whether the thread is using it.
/plan Switch to plan mode and optionally send a prompt. Ask Codex to propose an execution plan before implementation work starts.
/goal Set, pause, resume, view, or clear a task goal. Give Codex a persistent target to track while a larger task runs.
/personality Choose a communication style for responses. Make Codex more concise, more explanatory, or more collaborative without changing your instructions.
/ps Show experimental background terminals and their recent output. Check long-running commands without leaving the main transcript.
/stop Stop all background terminals. Cancel background terminal work started by the current session.
/fork Fork the current conversation into a new thread. Branch the active session to explore a new approach without losing the current transcript.
/side Start an ephemeral side conversation. Ask a focused follow-up without disrupting the main thread’s transcript.
/raw Toggle raw scrollback mode. Make terminal selection and copying less formatted while reviewing long output.
/resume Resume a saved conversation from your session list. Continue work from a previous CLI session without starting over.
/new Start a new conversation inside the same CLI session. Reset the chat context without leaving the CLI when you want a fresh prompt in the same repo.
/quit Exit the CLI. Leave the session immediately.
/review Ask Codex to review your working tree. Run after Codex completes work or when you want a second set of eyes on local changes.
/status Display session configuration and token usage. Confirm the active model, approval policy, writable roots, and remaining context capacity.
/debug-config Print config layer and requirements diagnostics. Debug precedence and policy requirements, including experimental network constraints.
/statusline Configure TUI status-line fields interactively. Pick and reorder footer items (model/context/limits/git/tokens/session) and persist in config.toml.
/title Configure terminal window or tab title fields interactively. Pick and reorder title items such as project, status, thread, branch, model, and task progress.
/theme Choose a syntax-highlighting theme. Preview and persist a terminal syntax-highlighting theme.

/quit/exit 都会退出 CLI。重要工作先保存或提交,再执行这两个命令。

/permissions 调整 Codex 在不询问的情况下能做什么。只有在自动审查拒绝了最近一次动作、你确实需要重试时,才用 /approve

用 slash commands 控制当前会话

下面这些工作流可以让你不重启 Codex 也把会话保持在正确轨道上。

/model 切换当前模型

  1. 启动 Codex 并打开 composer。
  2. 输入 /model,然后按 Enter。
  3. 在 popup 里选择一个模型,比如 gpt-4.1-minigpt-4.1

Expected: Codex 会在 transcript 中确认新模型。再运行 /status 可以验证是否切换成功。

/fast 切换 Fast mode

  1. 输入 /fast on/fast off/fast status
  2. 如果你希望设置持久化,在 Codex 提示保存时确认更新。

Expected: Codex 会报告当前线程的 Fast service tier 是 on 还是 off。你也可以在 TUI footer 里用 /statusline 加一个 Fast mode 状态项。

Fast tier 命令由 catalog 决定。如果当前模型没有公开 Fast tier,Codex 不会显示 /fast

/personality 设置沟通风格

/personality 可以改变 Codex 的表达方式,而不用重写提示词。

  1. 在当前对话里输入 /personality,然后按 Enter。
  2. 从 popup 里选择一种 style。

Expected: Codex 会在 transcript 中确认新风格,并在之后的回复里继续使用它。

Codex 支持 friendlypragmaticnone personalities。用 none 可以关闭 personality 指令。

如果当前模型不支持 personality-specific instructions,Codex 会隐藏这个命令。

/plan 切换到 plan mode

  1. 输入 /plan 并按 Enter,把当前对话切换到 plan mode。
  2. 可选:直接附加 prompt 文本,例如 /plan Propose a migration plan for this service
  3. 你在使用 inline /plan 参数时,也可以粘贴内容或附加图片。

Expected: Codex 会进入 plan mode,并把可选的 inline prompt 作为第一条 planning request。

任务已经在运行时,/plan 会暂时不可用。

/goal 设置或查看任务目标

  1. 输入 /goal <objective> 设置目标,例如 /goal Finish the migration and keep tests green
  2. 直接输入 /goal 查看当前目标。
  3. /goal pause/goal resume/goal clear 暂停、恢复或移除目标。

Expected: Codex 会把 goal 绑定到当前线程,工作继续时仍会保留。

Goal objectives 必须非空,且最多 4,000 个字符。更长的指令请写入文件,再把 goal 指向那个文件。

/experimental 切换实验特性

  1. 输入 /experimental 并按 Enter。
  2. 打开你想启用的功能,比如 Apps 或 Smart Approvals,然后按提示重启 Codex。

Expected: Codex 会把功能选择写入 config,并在重启后生效。

/approve 重试被自动审查拒绝的操作

当自动审查拒绝了最近一次动作,而你希望 Codex 只重试一次时,用 /approve

  1. 输入 /approve
  2. 当 Codex 显示被拒绝的相关动作时,确认重试。

Expected: Codex 会在当前 session policy 下,对那次被拒绝的动作重试一次。

/memories 配置 memories

  1. 输入 /memories
  2. 选择 Codex 是否使用已有 memories、生成新的 memories,或者保持 memory 行为关闭。

Expected: Codex 会更新相关 memory 设置,并应用到后续 sessions。

/skills 使用 skills

  1. 输入 /skills
  2. 选择你希望 Codex 应用的 skill。

Expected: Codex 会插入所选 skill context,让下一次请求遵循该 skill 的指令。

/hooks 查看 lifecycle hooks

  1. 输入 /hooks
  2. 查看已加载的 lifecycle hook configuration。

Expected: Codex 会显示当前 session 可以运行的 hooks。

/clear 清空终端并开始新聊天

  1. 输入 /clear 并按 Enter。

Expected: Codex 会清空终端、重置可见 transcript,并在同一个 CLI session 里开始一段新的对话。

Ctrl+L 不同,/clear 会开启新的 conversation。

Ctrl+L 只会清空终端视图,不会结束当前 chat。Codex 在任务进行中会禁用这两个动作。

/permissions 更新权限

  1. 输入 /permissions 并按 Enter。
  2. 选择与你的接受程度匹配的 approval preset,例如 Auto 适合完全放手运行,Read Only 适合先审查编辑。

Expected: Codex 会宣布更新后的 policy。之后的动作会一直遵循新的 approval mode,直到你再次修改。

/ide 带入 IDE 上下文

  1. 输入 /ide
  2. 如果你想说明 Codex 应该如何处理当前 IDE selection 或 open files,可以附加可选的 inline text。

Expected: Codex 会把可用的 IDE context 带到下一条 prompt 中。

/vim 切换 Vim mode

  1. 输入 /vim
  2. 继续在 composer 中编辑。

Expected: Codex 会为当前 session 切换 composer 的 Vim mode。要让 Vim mode 成为新 session 的默认值,可以在 config.toml 里设置 tui.vim_mode_default = true

/copy 复制最新回复

  1. 输入 /copy 并按 Enter。

Expected: Codex 会把最近一次完成的输出复制到剪贴板。

如果某个 turn 还在运行,/copy 会复制最近已完成的输出,而不是进行中的回复。第一次完成输出之前,以及刚 rollback 之后,这个命令都不可用。

你也可以在主 TUI 里直接按 Ctrl+O,不用打开 slash command menu 就复制最新完成的回复。

/raw 切换 raw scrollback

  1. 输入 /raw/raw on/raw off

Expected: Codex 会切换 raw scrollback mode,让终端里的选择和复制更直接。你也可以使用默认的 Alt+R 绑定,或者把默认值持久化为 tui.raw_output_mode = true

/sandbox-add-read-dir 授予 sandbox 读权限

这个命令只在 Windows 本机运行 CLI 时可用。

  1. 输入 /sandbox-add-read-dir C:\absolute\directory\path 并按 Enter。
  2. 确认这个路径是已经存在的绝对目录。

Expected: Codex 会刷新 Windows sandbox policy,并为之后在 sandbox 中运行的命令授予该目录的读取权限。

/status 检查会话状态

  1. 在任意对话里输入 /status
  2. 查看输出里的 active model、approval policy、writable roots 和当前 token usage。

Expected: 你会看到类似 shell 里 codex status 的摘要,确认 Codex 正在你预期的位置运行。

/debug-config 检查配置层

  1. 输入 /debug-config
  2. 查看 config layer order(lowest precedence first)、开关状态和 policy sources。

Expected: Codex 会打印 layer diagnostics,以及 allowed_approval_policiesallowed_sandbox_modesmcp_serversrulesenforce_residencyexperimental_network 等 policy details(如果已配置)。

当你想排查为什么实际生效的设置和 config.toml 不一致时,用这个输出。

/statusline 配置底部状态栏

  1. 输入 /statusline
  2. 用 picker 勾选、取消和调整顺序,然后确认。

Expected: 底部 status line 会立刻更新,并持久化到 config.tomltui.status_line

可用的 status-line items 包括 model、model+reasoning、context stats、rate limits、git branch、token counters、session id、current directory/project root 和 Codex version。

/title 配置终端标题

  1. 输入 /title
  2. 用 picker 勾选、取消和调整顺序,然后确认。

Expected: terminal window 或 tab title 会立刻更新,并持久化到 config.tomltui.terminal_title

可用的 title items 包括 app name、project、spinner、status、thread、git branch、model 和 task progress。

/theme 选择语法主题

  1. 输入 /theme
  2. 在 picker 里预览主题,然后确认。

Expected: Codex 会更新 syntax highlighting,并把选择写入 config.tomltui.theme

/keymap 重映射 TUI 快捷键

/keymap 可以检查、更新并持久化 TUI 的键位绑定。

  1. 输入 /keymap
  2. 选择你想修改的 shortcut context 和 action。
  3. 输入新的绑定,或者删除已有绑定。

Expected: Codex 会更新当前 keymap,并把自定义绑定写入 config.tomltui.keymap

键位名称使用 ctrl-ashift-enterpage-down 这类写法。context-specific bindings 会覆盖 tui.keymap.global;空的 binding list 会取消这个 action 的绑定。

/ps 检查后台终端

  1. 输入 /ps
  2. 查看后台终端列表和状态。

Expected: Codex 会显示每个后台终端的 command,以及最多三行最近的、非空输出,方便你快速判断进度。

当启用 unified_exec 时,后台终端才会出现;否则列表可能是空的。

/stop 停止后台终端

  1. 输入 /stop
  2. 如果 Codex 提示确认,再确认停止列表中的终端。

Expected: Codex 会停止当前 session 的所有后台终端。/clean 仍然可以作为 /stop 的别名使用。

/compact 保持转录精简

  1. 在长对话之后输入 /compact
  2. 当 Codex 提示压缩当前对话时,确认。

Expected: Codex 会用简短摘要替换前面的轮次,释放上下文,同时保留关键细节。

/diff 审查变更

  1. 输入 /diff 查看 Git diff。
  2. 在 CLI 里滚动查看已编辑和新增文件。

Expected: Codex 会显示你已经 staged 的更改、尚未 staged 的更改,以及 Git 还没开始追踪的文件,方便你决定保留哪些内容。

/mention 标记文件

  1. 输入 /mention 再跟一个路径,例如 /mention src/lib/api.ts
  2. 在 popup 里选择匹配结果。

Expected: Codex 会把该文件加入 conversation,让后续轮次直接引用它。

/new 开启新对话

  1. 输入 /new 并按 Enter。

Expected: Codex 会在同一个 CLI session 中开启一段新的 conversation,这样你可以不离开终端就切换任务。

/clear 不同,/new 不会先清空当前 terminal view。

/resume 恢复已保存会话

  1. 输入 /resume 并按 Enter。
  2. 从已保存会话的 picker 里选择你要继续的 session。

Expected: Codex 会重新加载所选 conversation 的 transcript,让你接着之前的进度继续做,且保留原始历史。

/fork 分叉当前对话

  1. 输入 /fork 并按 Enter。

Expected: Codex 会把当前 conversation 克隆成一个新的 thread,并生成新的 ID,原始 transcript 保持不变,方便你并行尝试另一种方案。

如果你想分叉的是已保存 session 而不是当前会话,可以在终端里运行 codex fork 打开 session picker。

/side 开一个旁路对话

/side 可以从当前对话开一个临时 fork,同时不切走主任务。

  1. 输入 /side 打开 side conversation。
  2. 可选:附加 inline text,例如 /side Check whether this plan has an obvious risk
  3. 结束这个聚焦的绕行后,回到 parent thread。

Expected: Codex 会打开一个与 parent thread transcript 分开的 side conversation。处于 side mode 时,TUI 仍会显示 parent-thread status,方便你确认主任务是否还在运行。

/side 在另一个 side conversation 内,以及 review mode 中都不可用。

/init 生成 AGENTS.md

  1. 在你希望 Codex 查找持久化指令的目录里运行 /init
  2. 查看生成的 AGENTS.md,再按仓库规范编辑它。

Expected: Codex 会创建一个 AGENTS.md scaffold,供你完善后提交给未来的 sessions 使用。

/review 请求工作区审查

  1. 输入 /review
  2. 如果你想查看确切的文件变更,再接着用 /diff

Expected: Codex 会总结它在 working tree 里发现的问题,重点关注行为变化和缺失测试。它默认使用当前 session model,除非你在 config.toml 里设置了 review_model

/mcp 列出 MCP 工具

  1. 输入 /mcp
  2. 查看列表,确认当前可用的 MCP servers 和 tools。

Expected: 你会看到本次 session 里 Codex 可以调用的 Model Context Protocol (MCP) tools。

/mcp verbose 可以包含更详细的 server diagnostics。如果你传入的参数不是 verbose,Codex 会显示该命令的用法。

/apps 浏览 apps

  1. 输入 /apps
  2. 从列表里选择一个 app。

Expected: Codex 会把 app mention 插入 composer,形式是 $app-slug,这样你可以马上要求 Codex 使用它。

/plugins 浏览插件

  1. 输入 /plugins
  2. 选择一个 marketplace tab,再挑选一个插件,查看它的 capabilities 或可用 actions。

Expected: Codex 会打开 plugin browser,让你查看已安装插件、配置允许发现的插件,以及已安装插件状态。对已安装插件按 Space 可以切换启用状态。

/hooks 查看 hooks

  1. 输入 /hooks
  2. 选择一个 hook event 来查看对应的 handlers。
  3. 按需要信任、禁用或重新启用非 managed hooks。

Expected: Codex 会打开 hook browser,让你查看已配置的 lifecycle hooks。managed hooks 会显示为 managed,不能从用户 hook browser 里禁用。

/agent 切换 agent threads

  1. 输入 /agent 并按 Enter。
  2. 从 picker 里选择你想切换到的 thread。

Expected: Codex 会切换 active thread,方便你查看或继续那个 agent 的工作。

/feedback 发送反馈

  1. 输入 /feedback 并按 Enter。
  2. 按提示附带 logs 或 diagnostics。

Expected: Codex 会收集所需 diagnostics,并提交给 maintainer。

/logout 退出登录

  1. 输入 /logout 并按 Enter。

Expected: Codex 会清除当前用户 session 的本地 credentials。

/quit/exit 退出 CLI

  1. 输入 /quit(或 /exit)并按 Enter。

Expected: Codex 会立即退出。重要工作先保存或提交。

常见问题

OpenAI Codex CLI 里怎么切换模型

输入 /model,然后在 popup 里选择 gpt-4.1-minigpt-4.1 等模型。切换后,运行 /status 可以确认当前 active model。

/quit/exit 有什么区别

没有区别。两者都会退出 OpenAI Codex CLI。退出前先保存或提交重要工作。

Windows 上怎么给 sandbox 额外目录读权限

只有在 CLI 以原生 Windows 方式运行时,/sandbox-add-read-dir 才可用。输入 C:\absolute\directory\path 这类已经存在的绝对目录,确认后 Codex 会把该目录加入后续 sandbox 命令的读取范围。