Episode 6 · AI Trading · Building a Complete Trading System

Installing Codex CLI, Antigravity CLI, Cursor or Copilot safely

Four routes to a coding agent, each with the right login, the lowest-permission first session, a spending cap and an EMA task with a known answer.

This post is for people whose main tool is not Claude Code. Take one of the four routes below. If you already use another agent, installing a second one is optional, and it only reads or reviews: it never edits the project.

A CLI is a program you drive by typing in a terminal (codex, agy, agent). An IDE is a code editor with a mouse interface, where the agent sits in a chat panel next to the code. If the terminal is new to you, pick an IDE: Cursor, or VS Code with Copilot.

Install commands of the form irm … | iex or curl … | sh download a script and run it immediately. Paste them only from the official page or from this post, and read the domain carefully (chatgpt.com, antigravity.google, cursor.com). Never run an install command from a video, a blog comment or a chat group. After installing anything, open a new terminal before checking it.

Before every task you hand to an agent: cd into trading-agent-lab, run git status and commit a checkpoint. Nothing here connects to a trading account. Later, any order connection uses an MT5 demo account only and you approve every order. No keys or passwords in an agent’s chat.

Codex CLI (OpenAI) Antigravity CLI (Google) Cursor VS Code + GitHub Copilot
Form Terminal; on Windows also inside the ChatGPT desktop app Terminal, command agy; separate desktop app IDE with an agent; CLI called agent Free IDE; Copilot from the status bar icon
Login ChatGPT account Personal Google account Cursor account GitHub account
Plans Free, Go: limited Codex; Plus: more; Pro: longer sessions Free accounts: weekly allowance; AI Pro, Ultra: refresh every 5 hours up to a weekly cap. No published numbers Free; Plus 8 USD (Grok only); Premium 30; Super 100; Ultra 200. Third-party models extra at API price Free (2,000 completions a month); Pro 10 USD; Pro+ 39; Max 100
Safe first session codex --sandbox read-only default mode Allowlist with an empty list Manual permissions
Never --yolo auto Run Everything Allow all, Autopilot
Suits Existing ChatGPT Plus or higher A Google account, trying before paying Wanting an IDE with an agent built in, while watching cost Already on VS Code, low budget

Codex CLI: install and log in with ChatGPT

Codex CLI is OpenAI’s coding agent for the terminal. Its docs now live at learn.chatgpt.com (the old developers.openai.com/codex link redirects there).

# Windows PowerShell (new window). ByPass applies to this run only.
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"
# Force the binary from GitHub Releases instead (the installer already falls back to it):
$env:CODEX_INSTALLER_USE_RELEASES_OPENAI_COM='false'; irm https://chatgpt.com/codex/install.ps1 | iex
# macOS, pick one
curl -fsSL https://chatgpt.com/codex/install.sh | sh
brew install --cask codex

The installer and the binary both come from releases.openai.com; if your network blocks that domain entirely, both lines fail, so change network. To update later, rerun the install command (Homebrew: brew upgrade --cask codex).

codex login
codex login status
codex doctor

codex login opens the ChatGPT login page in the browser. codex login status must say you are logged in with ChatGPT. codex doctor prints a diagnostic of install, config, login, Git and terminal (the command reference lists no --version flag, so doctor is the “it runs” check). Codex is recommended on Plus, Pro, Business, Edu or Enterprise; Free and Go only get limited Codex.

Task Command
Log in with ChatGPT (plan allowance) codex login
No browser on this machine (beta) codex login --device-auth
Which login is active codex login status
Log out, delete stored credentials codex logout
Log in with an API key (API pricing) Not used here. Never paste a key into a chat

Cost trap: logging in with an API key bills at standard API rates instead of using your ChatGPT plan allowance.

Keep the login to yourself. ~/.codex/auth.json holds an access token: treat it like a password, never commit it or paste it into a ticket or chat. OpenAI’s terms forbid sharing credentials or letting others use your account, so any tool asking you to copy auth.json or paste a token gets nothing. For automated pipelines such as CI, the docs recommend an API key; running codex exec from your own scripts on your own machine with a ChatGPT login counts against your plan, and you watch the allowance yourself.

OpenAI also runs an official Sign in with ChatGPT programme for partner apps (announced 29 September 2026, still limited to some partners). You click Sign in with ChatGPT in a listed app, log in on OpenAI’s page, review the permissions and choose whether the app may use your plan allowance. No API key changes hands; the app gets name, email and profile picture, not chat history or memory. Usage comes out of your existing allowance (you can set a weekly cap per app under Settings → Usage → App limits), extra credits are used only if you switch them on (off by default; leave it), and you disconnect under Settings → Security and login → Login connections. Use only apps on the official partner list; anything else that needs OpenAI models gets an API key with a spending cap.

Codex: keyring, sandbox, read-only first session

By default Codex can store your login in a plain-text file (%USERPROFILE%\.codex\auth.json on Windows). Anyone who can read that file, including another agent on the machine, can use your session. Force the OS keyring (Windows Credential Manager, macOS Keychain) instead:

cli_auth_credentials_store = "keyring"

[features]
prefer_mxc = true

That’s %USERPROFILE%\.codex\config.toml on Windows; on macOS ~/.codex/config.toml only needs the first line. If the keyring is unavailable, login fails instead of silently writing the file. The setting must sit at the top, before any [section] line, or it belongs to that section and does nothing. TOML doesn’t allow the same section twice, so add lines to an existing [features] or [windows] block rather than creating a second one.

A sandbox limits what the agent’s commands can touch: which folders, and whether they reach the network. Codex has three on Windows. Run winver to see your build:

  • mxc (recommended): Windows 11 24H2 build 26100.9278+ or 25H2 build 26200.9278+. No admin install step.
  • elevated (preferred fallback): replace the [features] block with [windows] / sandbox = "elevated" and approve the admin prompt when Codex sets it up.
  • unelevated: last resort, temporary only.

Codex recommends Windows 11; fully updated Windows 10 (1809+) is best effort. For Linux tools use WSL2; WSL1 is unsupported since Codex 0.115.

mkdir -Force "$env:USERPROFILE\.codex"
notepad "$env:USERPROFILE\.codex\config.toml"
codex logout
codex login
Test-Path "$env:USERPROFILE\.codex\auth.json"

The last line must print False (on macOS, ls ~/.codex/auth.json says No such file or directory): no plain-text login left. On macOS, allow the Keychain prompt only when the program name is codex.

First session, read-only:

cd C:\trading-agent-lab
codex --sandbox read-only --ask-for-approval on-request

read-only keeps the agent’s commands read-only; on-request makes Codex stop and ask when it needs more. In the session, /status shows the active config, /permissions sets what runs without asking, /model picks the model and reasoning level, /review reviews changes. Never use --dangerously-bypass-approvals-and-sandbox (alias --yolo); the docs reserve it for environments already isolated from outside.

Antigravity CLI (agy): the personal Google account route

On 18 June 2026 Antigravity CLI (agy) replaced Gemini CLI for personal use. Free personal use and the Google AI Pro and Ultra plans moved to agy; Gemini CLI now serves Gemini Code Assist Standard and Enterprise licences and paid API keys or Vertex. Guides that tell you to install Gemini CLI to use it free are out of date.

The official page gives exactly three install commands. Ignore any other agy install command you find (winget, brew and so on).

irm https://antigravity.google/cli/install.ps1 | iex
# Windows CMD (prompt without PS)
curl -fsSL https://antigravity.google/cli/install.cmd -o install.cmd && install.cmd && del install.cmd
# macOS, Linux
curl -fsSL https://antigravity.google/cli/install.sh | bash

The binary lands in ~/.local/bin/agy (macOS, Linux) or C:\Users\<you>\AppData\Local\agy\bin (Windows). In a new terminal:

agy --version
cd C:\trading-agent-lab
agy

The first run asks for a colour theme, a display style (Alt-Screen or Inline) and whether you trust the folder: say yes only for trading-agent-lab. agy looks for a login in the OS keyring and, if there is none, opens the browser for your personal Google account. That works without AI Pro or Ultra and without an API key. If the Antigravity desktop app is logged in on the same machine, the CLI shares that session. /logout deletes the stored session.

The allowance numbers are not published, so don’t treat it as unlimited. /usage shows usage and limits, /credits shows purchased AI credits. In /settings, Use AI Credits lets the CLI spend paid credits once the plan allowance runs out. The default isn’t documented: open it and switch it off if you don’t want charges.

Mode What agy does First session
default Stops to show the diff before creating or editing files; asks before running commands Use it
plan Adds a planning instruction to the prompt. Not documented as blocking edits Usable, still read every approval
accept-edits Accepts all file changes in the folder; still asks before commands Not yet
auto Accepts edits, runs commands in a sandbox, asks only for high-risk ones Never

Shift + Tab cycles modes; /config shows the current Agent Mode. agy reads AGENTS.md in the folder. Gemini API keys only work with "modelProvider": "gemini" in ~/.gemini/antigravity-cli/settings.json plus a GEMINI_API_KEY variable; a beginner needs neither.

IDE: Cursor, or VS Code with GitHub Copilot

Cursor. Download the installer from cursor.com (Windows 10+ .exe, macOS 12+ .dmg), log in and open trading-agent-lab. Then, straight away:

  1. Turn on Privacy Mode (Ctrl/Cmd + Shift + J → General) so your code is not used for training.
  2. Settings → Agents → Approvals & Execution → Allowlist with an empty list. An empty allowlist behaves like the old “Ask Every Time”, which new users can no longer select. Avoid the default Auto-review (a classifier that can be wrong) and Run Everything (every command, no sandbox, no questions).
  3. Set a spending cap. Third-party models such as Claude or GPT are billed at listed API prices on top of the plan. Plans bought through The X Subscription set the cap at grok.com/dashboard/billing → Additional usage credits → Monthly additional usage limit; legacy plans use the Spending tab in the Cursor dashboard. The cap can stop usage slightly late, so set it below what you can afford. Buy the plan directly, not from a reseller.

Cursor’s CLI is called agent:

irm 'https://cursor.com/install?win32=true' | iex
curl https://cursor.com/install -fsS | bash      # macOS, Linux, WSL
agent --version
agent login          # NO_OPEN_BROWSER=1 prints the link instead
agent status

It updates itself (agent update forces it). Never pass --api-key on the command line: the key stays in your shell history.

VS Code + Copilot. On Windows install the User setup (no admin rights, installs to %LOCALAPPDATA%\Programs\Microsoft VS Code) and keep Add to PATH ticked. On macOS drag it to Applications, then Cmd + Shift + P → Shell Command: Install ‘code’ … in PATH. Check with code --version in a new terminal. Hover the Copilot icon in the status bar → Use AI Features → sign in with GitHub. Without a plan you’re on Copilot Free.

Copilot has billed in AI credits since 1 June 2026 (1 credit = 0.01 USD). Inline completions are free; chat, agent and Copilot CLI cost credits by tokens and model price. Base credits come with the plan and are spent first; “flex” credits are an extra GitHub can change. When credits run out, wait for the reset (00:00 UTC on the 1st), upgrade, or set a USD budget for overage, which is billed after use.

Copilot plan Per month AI credits per month
Free 0 Some (no number published) + 2,000 completions
Student 0 Some
Pro 10 USD 1,500, including 500 flex
Pro+ 39 USD 7,000, including 3,100 flex
Max 100 USD 20,000, including 10,000 flex
Business, Enterprise 19 / 39 USD per seat 1,900 / 3,900 per seat

Then lock it down. Open the Chat view (Ctrl + Alt + I; macOS Ctrl + Cmd + I) and keep the permission picker on Manual permissions, which asks before anything not auto-approved. Assisted permissions uses a model to score risk and can score wrong; Allow all and Autopilot skip confirmation for file edits and commands alike. VS Code’s terminal sandbox is off by default and still experimental on Windows. Copilot Free sends telemetry by default; turn it off in settings:

{ "telemetry.telemetryLevel": "off" }

Read the diff before every commit.

Four readiness gates and an EMA task with a known answer

Installed doesn’t mean usable. Every tool goes through the same four gates.

Gate Codex CLI Antigravity CLI Cursor VS Code + Copilot
1. Runs, version known codex doctor agy --version App opens; agent --version code --version; Copilot icon present
2. Right login codex login status says ChatGPT Personal Google account; /usage shows limits Right account; agent status Right GitHub account; status shows the plan and % used
3. Login stored safely, low permissions Keyring, no auth.json; read-only first session Session in keyring; default mode; Use AI Credits checked Privacy Mode on; empty Allowlist; spending cap Manual permissions; telemetry off
4. EMA task Last 3 candles match Last 3 candles match Last 3 candles match Last 3 candles match

Gate 4 exists because any agent can be wrong while sounding certain. An EMA calculation has a known answer, which makes it a good test for a new tool. Run the new tool’s EMA20/EMA50 script on the same H1 CSV as your reference script and compare the last three candles: they must match to rounding.

If they differ, don’t switch tools yet. Put the two scripts side by side and check four things: how the EMA is initialised (ewm(adjust=False) versus an SMA seed), which column is used (close or something else), the time order (the CSV must be ascending), and whether any rows were filtered out. A different initialisation makes the early candles differ a lot and then converge, which is why you compare the last candles. These numbers are calculations on history to test a tool, not trading signals.

Log the result in reports/tool-comparison.md and commit:

| Tool | Version | Login type | Login stored in | EMA matches | Errors and fixes |
|---|---|---|---|---|---|
| [TOOL] | [VERSION] | [ChatGPT / Google / GitHub] | [keyring / file] | [yes / no] | [what broke, how fixed] |

From here on, only one main tool edits code. Any other tool reads or reviews, with a Git checkpoint before every task.

Common errors

Fix the cause. Never switch off the sandbox or turn on auto-approval just to get a command through. When asking an agent to fix an install problem, paste only the error text: never auth.json, .env or anything with a key, and blur user names and emails in screenshots.

The two most expensive mistakes print no red text: logging in with an API key (API pricing), and enabling extra credits without a cap. Recheck gates 2 and 3 after every tool update.

Symptom Usual cause Fix
The token '&&' is not a valid statement separator CMD command in PowerShell Use the PowerShell line (irm … | iex)
'irm' is not recognized PowerShell command in CMD Open PowerShell
codex, agy or agent not recognised Old window, old PATH New terminal. For agy on Windows, check the binary exists in AppData\Local\agy\bin. On macOS add ~/.local/bin to PATH (below)
Codex installer fails to download releases.openai.com blocked Change network and rerun
Codex sandbox error on Windows Build too old for MXC, or elevated setup not approved [windows] sandbox = "elevated", rerun and approve the admin prompt
Codex won’t run in WSL1 Unsupported since 0.115 Native Windows or WSL2
Codex login fails after setting keyring The machine’s keyring is unusable Switch to "auto" and note it: without a keyring it falls back to the plain file
Gemini CLI refuses a personal plan Personal plans moved to agy Install agy
agy spent paid credits after the allowance ran out Use AI Credits was on /settings → off; check /credits
code not recognised Windows: Add to PATH unticked. macOS: shell command not installed Rerun the installer with Add to PATH / run Shell Command: Install ‘code’ in PATH
EMA differs from the reference Different initialisation, column or row order Compare the code line by line; compare the last 3 candles
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

Try it: a read-only first prompt for the new tool

You are running in [TOOL, e.g. Codex CLI] in the folder [PATH, e.g.
C:\trading-agent-lab]. This session is READ-ONLY: don't create or edit files,
don't install packages, don't run network commands, don't open .env, auth.json
or any file holding keys or passwords.
1) List the files and folders, one line of description each.
2) Read data/[CSV, e.g. xauusd_h1.csv]: row count, columns, first and last
   time, whether rows are sorted ascending by time. If the time zone can't be
   determined, write "unknown".
3) Read the existing EMA script(s) in src/: how the EMA is initialised and which column is used.
4) Plan src/ema_[TOOL].py: EMA20 and EMA50 of close, same initialisation as the
   existing script, printing the last [3] candles with time, close, ema20, ema50.
5) List assumptions, risks and the commands I will run myself to check.
Don't guess numbers you haven't read; say so where you're unsure. Don't propose
connecting a trading account or using an API key. Stop after the plan for my review.

Key takeaways

  • The costly mistakes are silent: an API-key login, or extra credits with no cap. Recheck after every update.
  • Lowest permissions first: Codex read-only, agy in default, Cursor with an empty Allowlist, Copilot on Manual permissions. Never --yolo.
  • If the EMA differs from the reference, check initialisation, the close column and the time order before blaming the tool; compare the last 3 candles.
  • One main tool edits code; any second tool only reads or reviews.

Comments