Skip to main content
Guide · AI & LLM

OpenAI Codex for Flutter: Setup, AGENTS.md, MCP & Safe Use

Set up OpenAI Codex for Flutter: install the Dart plugin, write a Codex-ready AGENTS.md, connect the Dart MCP server and pick safe sandbox settings.

Afaq Zahir, author

Afaq Zahir

Flutter mobile product engineer

Published Updated 13 min read

On this page
  1. What is OpenAI Codex, and which part should a Flutter developer use?
  2. How do I install Codex CLI and the official Dart and Flutter plugin?
  3. How should a Flutter AGENTS.md for Codex look?
  4. How do I connect the Dart and Flutter MCP server to Codex?
  5. Can Codex hot reload a running Flutter app?
  6. Which sandbox and approval settings are safe for a Flutter project?
  7. Why do flutter test and flutter analyze hang inside the Codex sandbox?
  8. What does a safe Codex session on a Flutter feature look like?
  9. Can Codex review Flutter pull requests or run in CI?
  10. Where does Codex fit next to Antigravity and Claude Code?
  11. Frequently Asked Questions

Quick answer

Install Codex CLI, add the official Dart and Flutter plugin (codex plugin marketplace add flutter/agent-plugins, then codex plugin add dart-flutter@dart-flutter), put your project rules in AGENTS.md, and run Codex in workspace-write with on-request approvals and network off. Never use full access on client code.

Key takeaways

  • The official plugin installs skills and the Dart MCP server but no rules, so your Flutter rules go in AGENTS.md.
  • Codex reads AGENTS.md from the Git root down, caps the combined text at 32 KiB, and rereads it only in a new session.
  • Use workspace-write with on-request approvals. Network is off by default, so pub get needs your approval.
  • flutter test and flutter analyze can hang inside the sandbox (issue #15038, open as of October 24, 2026). Fix it with narrow rules, not full access.
  • --force-roots-fallback is deprecated in the Dart MCP server; plain dart mcp-server is enough.

To use OpenAI Codex for Flutter, install the Codex CLI, add Flutter's official dart-flutter plugin, put your project rules in AGENTS.md, and run Codex in workspace-write with on-request approvals and network off. I have 4+ years of Flutter experience and 20+ shipped apps. Much of my work is taking over stalled client codebases, where an agent with too much access can do real damage, so this guide is about setup and guardrails. If you are still choosing a tool, read Antigravity vs Claude Code vs Cursor for Flutter first.

Checked against the Codex changelog on October 24, 2026 (latest entry: Codex CLI 0.164.0, October 23, 2026).

What is OpenAI Codex, and which part should a Flutter developer use?

OpenAI Codex is OpenAI's coding agent. It reads your project, edits files and runs commands inside a sandbox. It ships as the Codex CLI, the Codex IDE extension and Codex Cloud, and inside the ChatGPT desktop, mobile and web apps (Codex docs, sandboxing). For Flutter, use the CLI or the IDE extension, because the agent needs your local Flutter SDK and a running app.

  • CLI. OpenAI describes it as "a coding agent from OpenAI that runs locally on your computer". The repo is Apache-2.0 (openai/codex).
  • IDE extension. It works in VS Code, VS Code Insiders, Cursor and Windsurf. "Xcode and JetBrains IDEs provide their own integrations" (Codex IDE extension docs).
  • Cloud. Each task gets its own workspace from a published environment (Codex Cloud docs).
  • Plans. Codex is included in ChatGPT Free, Go, Plus, Pro, Business, Edu and Enterprise. Free and Go have limited access (Codex pricing).

How do I install Codex CLI and the official Dart and Flutter plugin?

Install the CLI, sign in with ChatGPT, then add Flutter's plugin from the flutter/agent-plugins marketplace. Two commands give Codex Flutter skills and the Dart MCP server. Start a new session afterwards.

  1. Install the CLI. Use one of curl -fsSL https://chatgpt.com/codex/install.sh | sh, npm install -g @openai/codex or brew install --cask codex. On Windows PowerShell: powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex" (openai/codex README).
  2. Sign in. Run codex login and complete the browser flow to sign in with ChatGPT. An API key also works, but it bills at standard API rates, and cloud features are limited or unavailable (Codex authentication docs).
  3. Add the marketplace. codex plugin marketplace add flutter/agent-plugins
  4. Install the plugin. codex plugin add dart-flutter@dart-flutter, then confirm it with codex plugin list (Flutter docs).
  5. Restart. Start a new session before using the plugin's skills or tools (Codex plugin docs).

The plugin manifest declares two things: skills, and an MCP server called dart-mcp-server that runs dart mcp-server. It declares no rules (plugin.json). Skills sit in .agents/skills. The assistant reads only each skill's name and description until one is relevant (how Flutter AI tools work). Examples include flutter-add-widget-test, flutter-add-integration-test and dart-run-static-analysis (skills folder).

On Windows, Codex runs natively in PowerShell with its own sandbox (Codex Windows sandbox docs). WSL1 is unsupported from Codex 0.115. In WSL2, keep repos in your Linux home, not /mnt/c (Codex WSL docs).

How should a Flutter AGENTS.md for Codex look?

Put your rules in AGENTS.md at the repo root. "Codex reads AGENTS.md files before doing any work", and the plugin ships no rules, so this file is where architecture, state management and the "done" commands live.

How Codex finds the file (Codex AGENTS.md guide):

  • Global first. ~/.codex/AGENTS.override.md if it exists, otherwise ~/.codex/AGENTS.md.
  • Then the project. From the Git root down to your current folder, one file per directory. Closer files win.
  • Size cap. Combined text stops at project_doc_max_bytes, 32 KiB by default.
  • Once per session. Restart Codex after editing. In the CLI, /init generates an AGENTS.md scaffold in the current directory, which you then review and edit (Codex CLI commands).

Flutter's docs differ. They tell you to put rule files in .agent/rules/ or append them to CODEX.md (Flutter docs). OpenAI's AGENTS.md guide mentions neither. Codex tries the names in project_doc_fallback_filenames only when a directory has no AGENTS.md (Codex config reference). My advice: put rules in AGENTS.md. If your team already keeps a CODEX.md, add project_doc_fallback_filenames = ["CODEX.md"] to config.toml rather than trusting it to load by itself. AGENTS.md is an open format stewarded by the Agentic AI Foundation under the Linux Foundation (agents.md).

Start from this Codex-specific block and put it on top of the full Flutter AGENTS.md template, which covers feature-first MVVM, Riverpod, theming and disposal. I default to MVVM and Riverpod because that is the architecture behind TourVista, which reached both app stores in 28 days.

# AGENTS.md
# Architecture, state and UI rules: see the full template linked in this post.

## Commands (run before saying a task is done)
- dart format lib test
- flutter analyze
- flutter test
- flutter pub get needs network: ask me first.

## Codex notes
- If a flutter or dart command hangs in the sandbox, stop and ask to run it
  outside the sandbox. Do not retry in a loop.
- Do not edit generated *.g.dart or *.freezed.dart files; run
  dart run build_runner build instead.
- Do not add packages to pubspec.yaml without asking.
- Never write API keys or secrets into Dart code or this file.
- If a Flutter app is running, use the Dart MCP hot_reload tool after
  edits under lib/.
- Use hot_restart instead after changes to initState, global/static state
  or main().

Command docs: Flutter CLI, dart format, build_runner, pub get. TourVista, Nest AI and Fluently AI keep LLM keys behind a backend proxy. Here is how to keep API keys out of the app.

How do I connect the Dart and Flutter MCP server to Codex?

If you installed the plugin, the server is already there. To add it by hand, run codex mcp add dart -- dart mcp-server, then type /mcp inside Codex to list its tools. Use one route, not both. The plugin already registers the server as dart-mcp-server (plugin.json). A manual codex mcp add dart adds a second entry, named dart, that launches the same dart mcp-server.

The server is experimental, needs Dart 3.9.0-163.0.dev or later, and talks over stdio (dart_mcp_server). For what each tool does and how to set it up in other agents, see my Dart and Flutter MCP server setup guide. This section covers only the Codex side. Codex stores the server as [mcp_servers.dart] in ~/.codex/config.toml, or in a trusted project's .codex/config.toml (Codex MCP docs).

[mcp_servers.dart]
command = "dart"
args = ["mcp-server"]
startup_timeout_sec = 60   # default is 10; raise it if the handshake times out
  • Timeouts. startup_timeout_sec defaults to 10 seconds and tool_timeout_sec to 60 (Codex config reference). Issue #13766 reported a handshake timeout with this server and was closed on March 13, 2026. The reporter's workaround was startup_timeout_sec = 120. A reasonable starting value is 60; it is not an official value.
  • Trim tools. enabled_tools and disabled_tools let you allow or block specific tools per server (Codex MCP docs).
  • Drop old flags. Older posts add --force-roots-fallback. The server's source now marks it deprecated because the roots tools are always available (arg_parser.dart).

A third-party option, Arenukvern/mcp_flutter, supports Codex and adds tools such as screenshots and taps. Read it before you install it.

Can Codex hot reload a running Flutter app?

Yes, through the Dart MCP server. The runtime tools need an active Dart Tooling Daemon (DTD) connection. Flutter apps register with DTD automatically when run in debug or profile mode, unless you pass --no-dds (Dart MCP server README). The MCP setup guide explains how that connection works.

Key tools, with defaults from the Dart MCP server README:

ToolWhat it does in a Flutter loopOn by default
analyze_filesRuns analyzer diagnostics on the projectYes
hot_reloadReloads the running app after code editsYes (needs DTD)
hot_restartRestarts the app and resets stateYes (needs DTD)
get_runtime_errorsReads errors from the running appYes (needs DTD)
widget_inspectorInspects the live widget treeYes (needs DTD)
run_testsRuns tests through the serverNo

launch_app is also off by default, so you start the app yourself with flutter run. Flutter's official rule says when to use each tool. Use hot_reload after UI or widget edits under lib/, and hot_restart after changes to initState, global or static state, or main() (Flutter hot reload rule). The plugin does not install that rule, so the AGENTS.md sample above repeats it. The plugin starts plain dart mcp-server with no --enable or --disable flags (plugin.json). That means the README defaults apply. Type /mcp to see the tools your session actually loaded.

Which sandbox and approval settings are safe for a Flutter project?

Use workspace-write with on-request approvals, and keep network off. OpenAI calls this preset "Auto" and recommends it for version-controlled folders. Codex asks before editing outside the workspace or using the network.

Sandbox modeWhat the agent can doWhen to use it
read-onlyInspect files; no edits or commands without approvalAuditing an inherited repo
workspace-writeEdit inside the workspace and run local commands thereNormal client work
danger-full-accessNo sandbox; "removes the filesystem and network boundaries"Never on client code

Mode descriptions: Codex sandboxing and Codex approvals and security. The "When to use it" column is my opinion.

  • Enforcement. Seatbelt on macOS, bubblewrap on Linux and WSL2, a native sandbox on Windows (Codex sandboxing).
  • Presets. Auto is --sandbox workspace-write --ask-for-approval on-request. Full access is --dangerously-bypass-approvals-and-sandbox, alias --yolo, and OpenAI marks it "not recommended" (Codex approvals and security).
  • Network. "By default, the agent runs with network access turned off." .git and .codex stay read-only (Codex approvals and security).
  • App and IDE names. "Ask for approval", "Approve for me" and "Full access". OpenAI's advice: "For most work, start with Ask for approval". In the desktop app or IDE extension, switch modes with the permissions control below the composer. In the CLI, enter /permissions. Which modes you see depends on app version, environment, local configuration and your organization's requirements (Codex permission modes).
  • Retired values. untrusted is no longer supported as an approval policy and on-failure is deprecated (Codex config reference).

A starting config.toml, using documented keys only (Codex sample config):

# ~/.codex/config.toml
# model = "gpt-6.1-sol"   # optional; leave unset to use the recommended default
approval_policy = "on-request"
sandbox_mode = "workspace-write"
approvals_reviewer = "user"

[sandbox_workspace_write]
network_access = false
writable_roots = []        # read the next section before adding anything here

# Skip this block if you installed the dart-flutter plugin.
[mcp_servers.dart]
command = "dart"
args = ["mcp-server"]
startup_timeout_sec = 60

GPT-6.1 Sol became the default model in Codex's bundled model catalog in CLI 0.161.0 (October 7, 2026). GPT-5.5 retired from Codex for ChatGPT sign-in on October 14, 2026, so update saved settings that still select gpt-5.5 (Codex changelog, Codex models). For a one-off session with network, run codex --config sandbox_workspace_write.network_access=true. Profiles are now separate ~/.codex/<name>.config.toml files picked with --profile. [profiles.*] tables are ignored from 0.134.0 (Codex advanced config). A project's own .codex/config.toml loads only if you trust the project (Codex config basics).

Recommended rules. These are my opinion, not OpenAI policy:

  1. On client repos, use workspace-write with on-request approvals, and start each task from a clean commit.
  2. Keep network off and approve pub get yourself.
  3. Start read-only on an inherited repo. My takeovers begin with a root-cause audit, and an audit needs no write access.
  4. Never use --yolo on client code. If you use it at all, use it in a throwaway container.
  5. "Approve for me" is optional. Its reviewer agent grants no new permissions (Codex auto-review).

Also check where your login lives. With file-based credential storage, Codex caches login details in a plaintext file at ~/.codex/auth.json. It can instead use your OS credential store (cli_auth_credentials_store set to keyring or auto) or keep them in memory only (ephemeral). OpenAI's advice: "treat ~/.codex/auth.json like a password: it contains access tokens. Don't commit it, paste it into tickets, or share it in chat." (Codex authentication docs).

Why do flutter test and flutter analyze hang inside the Codex sandbox?

It is a known bug, still open as of October 24, 2026. Issue #15038 reports flutter test and flutter analyze hanging in sandbox mode on Windows with CLI 0.115.0. A similar report, #16441, was closed by its author on April 15, 2026. An OpenAI maintainer said the tool "likely needs some resource that is not available by policy in the sandbox" (maintainer comment).

User-reported workarounds, narrowest first. None is official:

  1. An AGENTS.md line telling Codex to ask before running flutter or dart outside the sandbox (user comment). The AGENTS.md sample in this post does this.
  2. Command rules with prefix_rule, so known-safe commands stop prompting.
  3. Writable roots. One user added the Flutter SDK folder and the pub cache to writable_roots, together with allow rules for flutter and dart. They wrote: "With this setup codex is able to run all flutter and dart commands without asking for permissions" (user comment, September 26, 2026). The trade-off: Codex can now write into your SDK too.
  4. On Windows, one commenter switched from the unelevated to the elevated sandbox ([windows] sandbox = "elevated"). Full hangs became harder to reproduce, but bare flutter commands were still unreliable inside the sandbox. Their working fix was calling flutter.bat by its absolute path, for example & <USERPROFILE>\flutter\bin\flutter.bat analyze. A wrapper script that resolves Flutter explicitly and kills the process tree on timeout also worked for them (user comment).

Rules are experimental. They live in ~/.codex/rules/default.rules, or in <repo>/.codex/rules/ for trusted projects only. Each rule is allow, prompt or forbidden, and the most restrictive match wins. codex execpolicy check tests a command against them (Codex rules docs). The sandboxing docs prefer narrow rules over widening access (Codex sandboxing). Here is a narrow allowed-command list to start from. Test it with execpolicy check before relying on it:

# .codex/rules/default.rules  (experimental)
prefix_rule(pattern=["flutter", "analyze"], decision="allow")
prefix_rule(pattern=["flutter", "test"], decision="allow")
prefix_rule(pattern=["dart", "format"], decision="allow")
prefix_rule(pattern=["flutter", "pub", "get"], decision="prompt")

Rules decide whether Codex asks you. None of the reports linked here shows that rules alone stop the hang, so keep the AGENTS.md line too.

What does a safe Codex session on a Flutter feature look like?

Using Codex on a Flutter project safely comes down to five steps, from a clean commit to a device test. This is my prompt, plan, verify and review loop applied to Codex's commands (Codex CLI commands).

  1. Commit to a clean tree. Then the diff shows only Codex's changes, and one git restore undoes a bad run.
  2. Give one scoped task and start with /plan. Plan mode asks Codex to propose a plan before implementation starts. Check that the plan names the files it will touch, stays inside one feature, and adds no packages. If it plans to edit generated files or pubspec.yaml, correct it before it starts.
  3. Let Codex run the AGENTS.md "done" commands. If one fails, ask Codex to fix the cause, not to skip or delete the failing test. If a command hangs, stop it and run it yourself (see the sandbox hang section above). My guide to writing Flutter tests with AI agents covers how to judge the tests it writes.
  4. Run /review on uncommitted changes and check /diff. /review can check uncommitted changes (Codex code review), and /diff shows the Git diff, including files Git is not tracking yet (Codex CLI commands). Reject a finding that asks for changes outside the task or contradicts your AGENTS.md. Fix the rest before you commit.
  5. Read every diff yourself and test on a real device, the same routine as in my AI coding tools comparison. If something breaks at runtime, here is how I diagnose Flutter crashes.

Can Codex review Flutter pull requests or run in CI?

Yes. Mention @codex review on a GitHub pull request, where code review is generally available, or call codex exec from CI. Install the Flutter SDK in your CI workflow yourself.

  • PR review. "GitHub code review is generally available" (Codex code review). API-key sign-in gets no cloud features such as GitHub review (Codex pricing).
  • codex exec. It runs read-only by default. Pass --sandbox workspace-write to allow edits. --full-auto is "No longer supported" (Codex non-interactive mode).
  • Keys in CI. Set the key inline for the single call, never as a job-level variable in workflows that run repository code (Codex non-interactive mode). For example: CODEX_API_KEY=... codex exec --json "summarize the flutter analyze output".
  • GitHub Action. openai/codex-action@v1 takes a sandbox input (workspace-write, read-only or danger-full-access). Its safety-strategy input defaults to drop-sudo, which removes sudo before Codex runs. Windows runners must set safety-strategy: unsafe (Codex GitHub Action).

For which Flutter tests to gate a pull request on, see writing Flutter tests with AI agents.

Where does Codex fit next to Antigravity and Claude Code?

Codex fills the same role for Flutter as Antigravity and Claude Code: an agent in your terminal or IDE that edits the project and can call the Dart MCP server. Codex reads AGENTS.md, an open format that many coding agents support (agents.md).

If you are moving over from Claude Code, Codex's /import command can "Import Claude Code or Cursor setup, projects, and chats" into Codex configuration and local files (Codex CLI commands). Run it once, then check what it imported against the sandbox settings above. My Claude Code guide for Flutter developers covers the same setup on the Claude side.

I am not ranking these tools here. See Antigravity vs Claude Code vs Cursor for Flutter and my full AI workflow for Flutter.

Frequently Asked Questions

Does OpenAI Codex work with Flutter and Dart?

Yes. Flutter publishes an official Codex plugin, dart-flutter, that adds Flutter skills and the Dart MCP server. Codex can run flutter and dart commands in its sandbox, but network is off by default, so flutter pub get needs your approval. As of October 24, 2026, openai/codex issue #15038, where flutter test and flutter analyze hang in the sandbox, is still open.

How do I install OpenAI Codex for Flutter?

Install the Codex CLI, for example with npm install -g @openai/codex, and sign in with codex login. Then run codex plugin marketplace add flutter/agent-plugins and codex plugin add dart-flutter@dart-flutter. Confirm with codex plugin list and start a new session.

What is AGENTS.md?

AGENTS.md is an open format, a README for coding agents, with no required fields. Codex reads it before doing any work, from your global ~/.codex folder and then from the Git root down to your current folder.

Should Flutter rules go in AGENTS.md or CODEX.md for Codex?

AGENTS.md. OpenAI's docs say Codex reads AGENTS.md before doing any work and never mention CODEX.md or .agent/rules, which Flutter's docs suggest. If your team already uses CODEX.md, add it to project_doc_fallback_filenames in config.toml. Codex tries fallback names only when a folder has no AGENTS.md.

Do I still need --force-roots-fallback for the Dart MCP server?

No. Older blog posts still show it, but the Dart MCP server's source now marks the flag deprecated because the roots tools are always available. Run plain dart mcp-server, either through the official plugin or with codex mcp add dart -- dart mcp-server. Raise startup_timeout_sec if the handshake times out.

Is it safe to give Codex full access on a Flutter project?

Not on client code. Full access removes the filesystem and network boundaries, and OpenAI marks the --yolo flag not recommended. Use workspace-write with on-request approvals and network off, start each task from a clean commit, and approve pub get yourself. Keep full access for throwaway containers.

Which ChatGPT plan do I need to use Codex?

Codex is included in ChatGPT Free, Go, Plus, Pro, Business, Edu and Enterprise, with limited access on Free and Go. You can also sign in with an API key, which bills at standard API rates but limits or removes cloud features such as GitHub code review. Check OpenAI's pricing page for current limits.

Can I use Codex inside VS Code or Cursor for Flutter work?

Yes. The Codex IDE extension runs in VS Code, VS Code Insiders, Cursor and Windsurf, next to the Flutter and Dart extensions you already use. For hot reload through the Dart MCP server, run the app in debug mode.

Want Codex or another agent set up on your Flutter codebase, with rules, sandbox settings and a review process that keeps the code shippable? See my AI-assisted Flutter development service. You can also look at how I built TourVista, or get in touch.

Afaq Zahir

Written by

Afaq Zahir

Flutter mobile product engineer with 4+ years shipping 20+ apps to the App Store and Google Play. Led Flutter teams at Metasense and Apptex.

GitHub ↗LinkedIn ↗Last reviewed
Book a call