Episode 5 · AI Trading · Building a Complete Trading System

Installing Claude Code step by step: CLI and desktop

Install Claude Code, log in on your plan instead of paying API rates, block .env reads, and run a first session: Plan, review, Manual, test, commit.

Claude Code is Anthropic’s coding agent: a program that reads files, edits them and runs commands in the folder you open, within the permissions you give it. It helps write and explain code. It does not know tomorrow’s price and it can be wrong, so every result in this post is something you rerun yourself.

This post assumes the machine is ready: Git installed, a trading-agent-lab folder with a .gitignore that blocks .env, and a Python 3.14 venv with pandas and matplotlib.

Before installing: account, machine, route

You need four things:

  1. A Claude plan with Claude Code: Pro, Max, Ultra, Team or Enterprise, or a Claude Console account billed by API. Free has no Claude Code.
  2. A supported country.
  3. A 64-bit machine (x64 or ARM64): Windows 10 1809+ or macOS 13+, 4 GB RAM, internet.
  4. The project folder above.

There are two routes. The CLI runs in a terminal and has the most options. The Code tab in the Claude desktop app works with the mouse and bundles Claude Code, so it needs no terminal and no Node.js. Both read the same settings files, so you can start in the app and move to the CLI later.

Route Who it suits Notes
Native CLI on Windows, from PowerShell Windows users who will connect to an MT5 demo from Python No command sandbox; compensate with Plan, Manual and deny rules. Git for Windows is optional: with it the agent can also use Git Bash
CLI inside WSL 2 People who need Linux tools or a command sandbox Install and run claude inside the Linux shell. Not suited to MT5: the MetaTrader5 package is Windows-only
CLI on macOS Mac users doing the CSV, charting and test work The MT5 part runs in a Windows VM or VPS
Code tab in the desktop app People who have never opened a terminal Installers for macOS (Intel and Apple Silicon) and Windows (x64, separate ARM64)

Safety rule for everything that follows: this post connects no trading account. Later connections use an MT5 demo account only, API keys never have withdrawal rights, keys and passwords never go into a chat, and you approve every order.

Install the CLI

Open PowerShell (Win + X, not the Admin entry) and check the prompt starts with PS. On macOS open Terminal and never prefix the command with sudo.

# Windows PowerShell
irm https://claude.ai/install.ps1 | iex
# Windows CMD
curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd
# macOS
curl -fsSL https://claude.ai/install.sh | bash

There is no progress bar. Wait for Claude Code successfully installed!. Then close the window, open a new one, and check:

claude --version
claude doctor

A good install prints a version followed by (Claude Code), for example 2.1.211 (Claude Code). claude doctor is read-only: it reports the install state, settings errors and warnings with fixes. If claude is not recognised, the install folder is not on PATH. The installer does not change PATH; it prints the fix under Setup notes at the end of its output.

The native install updates itself in the background (claude update forces it). WinGet and Homebrew installs do not update by default:

winget install Anthropic.ClaudeCode      # then: winget upgrade Anthropic.ClaudeCode
brew install --cask claude-code          # then: brew upgrade claude-code (stable channel, ~1 week behind)

Keep only one install on the machine. Several install methods side by side lead to mixed versions.

Log in on your plan, and avoid the API billing traps

cd C:\trading-agent-lab      # macOS: cd ~/trading-agent-lab
claude

Start in the project folder, not your home folder, where Claude Code doesn’t remember the trust choice and asks every time. On first run it asks you to log in and whether you trust this folder. Trust it only if it really is your trading-agent-lab. For the login method, use the arrow keys to choose your Claude account with a subscription. Don’t choose Anthropic Console, which bills by API. A browser opens; log in. If it doesn’t, press c to copy the link. If the page shows a code, paste it at Paste code here if prompted. The terminal then says Login successful.

Trap 1: an API key in the environment. If the machine has an ANTHROPIC_API_KEY variable, Claude Code asks once whether to use it and remembers the answer. Yes means the session skips your plan and bills per token. Beginners answer no. Check without printing the key:

Test-Path Env:ANTHROPIC_API_KEY          # Windows: True / False
Remove-Item Env:ANTHROPIC_API_KEY        # remove it for this window
echo ${#ANTHROPIC_API_KEY}               # macOS: 0 means not set
unset ANTHROPIC_API_KEY                  # then remove the export line from ~/.zshrc

To remove it for good on Windows, search “environment” in Start, edit the user variables and delete ANTHROPIC_API_KEY, plus any line in your PowerShell $PROFILE that sets it.

Trap 2: extra usage credits. When you hit the plan limit, Claude Code may offer paid extra credits. To stay within the plan, decline and wait for the limit to reset. /usage shows what you have used.

Then type /status. The Login method line must show your Claude account, not an API key; if both exist, /status marks the one not in use.

Account Claude Code? Billing For a beginner
Free No 0 USD Chat only
Pro Yes 20 USD a month (17 billed yearly); limits per 5-hour window and per week Usually enough to learn
Max, Ultra Yes Max 100 USD, 5× Pro; Ultra 200 USD, 10× Pro per week, no 5-hour window for verified accounts Upgrade only when you really hit limits
Console (API key) Yes Per token, from pre-paid credits Not needed yet; set a spending cap first if you create a key

Your login lives in the macOS Keychain, or on Windows in %USERPROFILE%\.claude\.credentials.json. Never send that file to anyone or paste it anywhere. /logout then claude switches accounts.

Never hand your plan login to a third-party tool. Subscription OAuth login is for ordinary use in Claude Code and Anthropic’s own apps. Third parties may not embed Claude.ai login, route requests through Free, Pro, Max or Ultra credentials, or collect or proxy login credentials and session tokens, and Anthropic can act without notice. The consumer terms also forbid sharing login details and accessing the service with bots or scripts except through an API key or explicit permission. So: a tool asking for your plan token or to read .credentials.json gets nothing; a macOS Keychain prompt from an unknown program gets Deny; another tool that needs Claude gets its own API key from Claude Console with a spending cap. claude -p (one request, print, exit) is different: that is Claude Code itself running on your machine, and on a plan login it counts against the plan’s limits, which are meant for normal individual use.

Don’t hand anything to the agent yet. /exit.

Lock it down before the first session

An instruction in a prompt or in CLAUDE.md (the project rules file Claude Code reads at the start of a session) is only context. The model usually follows it; nothing guarantees it. A real lock is configuration that Claude Code itself enforces, and deny rules hold in every permission mode, including Auto.

Create .claude/settings.json in the project:

{
  "permissions": {
    "defaultMode": "plan",
    "deny": [
      "Read(./.env)",
      "Read(./.env.*)"
    ]
  },
  "env": {
    "PYTHONUTF8": "1"
  }
}

It does three things. It blocks Claude Code’s file-reading tools from .env and every .env.* (that includes .env.example, which is fine: it only holds names). It starts every terminal session in this folder in Plan mode. And it sets PYTHONUTF8=1 for every command the agent runs here, so scripts don’t die with UnicodeEncodeError when the agent reads their output. Project env takes effect once you trust the folder.

On Windows, notepad .claude\settings.json (after mkdir .claude); on macOS, nano .claude/settings.json (Ctrl + O, Enter, Ctrl + X). JSON is strict: no // comments, no trailing comma. A syntax error shows as Settings Error on the next start; claude doctor gives the details. Commit the file so the rules have history.

Test the lock with a fake line, never a real key:

Set-Content -Path .env -Encoding ascii -Value "NOTE=test-file-no-real-key"
git check-ignore -v .env

Run claude again. The status line under the input must say ⏸ plan mode on, and /status must list the project settings under Setting sources. Ask the agent what .env contains: the correct result is that it’s blocked.

Know the gaps. The rule blocks Claude Code’s file tools and familiar Bash commands like cat .env, but not a folder-wide grep -r or a Python script that opens the file itself, and the docs don’t say whether it stops PowerShell’s Get-Content .env. That’s why the lab .env holds no real keys, and why you read every command and script before letting it run.

Never use bypass mode (bypassPermissions, --dangerously-skip-permissions). It’s meant for containers or isolated VMs, and it does nothing against prompt injection: text hidden in data that tries to steer the agent.

If Git for Windows lives somewhere unusual, Claude Code may not find Git Bash (it looks in C:\Program Files\Git and next to git on PATH); it then runs commands through PowerShell. To point it there, run where.exe git; for D:\Tools\Git\cmd\git.exe, add "CLAUDE_CODE_GIT_BASH_PATH": "D:\\Tools\\Git\\bin\\bash.exe" to env (double every backslash in JSON).

Not comfortable with a terminal: the Code tab

The desktop app bundles Claude Code, logs in with your Claude account, and does not read ANTHROPIC_API_KEY, so trap 1 doesn’t apply. It reads the same settings files, so the .env rule still holds.

  1. Download the installer from the desktop quickstart page and run it; open Claude and log in.
  2. Click Code in the sidebar.
  3. Under the input, open the environment picker and choose the top Local entry; then Open folder… and pick trading-agent-lab.
  4. Choose a model, then a permission mode: Plan for exploring, Manual for writing code. Check the mode before the first message: a new session can inherit a default or your last choice for this folder.
  5. Never choose Bypass permissions (on personal plans it only appears if you enable it in Settings).

When the agent edits files, a +12 -1 counter appears; click it to read the diff file by file and comment on lines. Ctrl + ` opens the app’s terminal for your own checks. If Code shows an upgrade prompt, the account has no paid plan; if it asks you to log in online, log in and restart the app.

The first session: Plan, review, Manual, test, commit

Mode CLI status line Runs without asking When a beginner uses it
Plan ⏸ plan mode on Reads files, runs exploring commands, writes a plan; no source edits before you approve First session, any exploration
Manual (default) ⏸ manual mode on Read-only; edits and commands ask first, except a few read-only ones like ls, git status Writing code while you read each change
Accept edits ⏵⏵ accept edits on File edits and some file commands (mkdir, mv, cp, even rm) in the working folder Once you’re used to it and still reading diffs
Auto ⏵⏵ auto mode on Most things; a background classifier blocks what it deems risky. Not a safety guarantee Not yet
Bypass permissions ⏵⏵ bypass permissions on Almost everything Never; containers and isolated VMs only
  1. Open a new terminal in the project and run claude. Thanks to the settings file the status line says ⏸ plan mode on. If you see something else, such as ⏵⏵ auto mode on (new terminal sessions start in Auto from 2.1.283 when nothing else is configured), you are in the wrong folder or the settings file is broken: check /status.
  2. To change mode, press Shift+Tab and watch the status line (Manual, Accept edits, Plan). On Windows, if Shift+Tab does nothing, use Alt+M, or restart with claude --permission-mode plan.
  3. Paste the prompt below. In Plan the agent reads files, may run exploring commands, and writes a plan. It edits no source until you approve.
  4. Read the plan like a spec: the right files, the right formula, no unknown packages, no network calls. Ctrl+G opens it in an editor; or choose No, keep planning and give feedback.
  5. When it’s right, choose Yes, manually approve edits: the session moves to Manual and asks before each file change or command. Read, then Yes; for anything odd, No with a reason. Don’t pick “Yes, and use auto mode” yet, and don’t press Shift+Tab while a permission prompt is open: there it allows the action for the whole session. Esc interrupts the agent.
  6. When it says it’s done, check it yourself in a separate terminal. “All tests pass” is not evidence; your own run is.
.venv\Scripts\python -m pip install pytest
.venv\Scripts\python -m pytest -q
.venv\Scripts\python src\ema.py
git status
git add -A
git diff --staged
git commit -m "Add src/ema.py computing EMA20 and EMA50 with tests"

The hand-computed test: with span 3, alpha = 2 ÷ (3 + 1) = 0.5. The EMA starts at the first close, 10, then 0.5 × 11 + 0.5 × 10 = 10.5, then 11.25 and 12.125. Then compare the last three EMA50 values against an independent calculation of the same formula (ewm(span=50, adjust=False) in a one-line pandas command): they must match to rounding. These are calculations on historical data, not trading signals.

Finally, /init drafts a starter CLAUDE.md; in Manual it asks before writing. Read it, delete anything wrong or superfluous, commit, and leave with /exit or Ctrl + D twice.

When the install fails

Most failures are a command pasted into the wrong terminal, the install folder missing from PATH, or the network blocking the download. Fix, open a new window, rerun claude --version. When you ask someone (or an AI chat) for help, paste only the error line, with your user name, private paths and anything that looks like a key removed.

You see Cause Fix
The token '&&' is not a valid statement separator CMD command in PowerShell Use irm https://claude.ai/install.ps1 | iex
'irm' is not recognized PowerShell command in CMD Open PowerShell, or use the CMD command
A parameter cannot be found that matches parameter name 'fsSL' macOS command in PowerShell Use the Windows command
'claude' is not recognized / command not found: claude %USERPROFILE%\.local\bin (macOS ~/.local/bin) not on PATH, or an old window New window; otherwise add it to PATH (below)
syntax error near unexpected token '<', System.Xml.XmlDocument, or HTML The install URL returned a web page: network block or temporary issue Retry later, or use WinGet / Homebrew
curl: (22) The requested URL returned error: 403 Proxy, firewall or unsupported region Check supported countries; on a corporate network set HTTP_PROXY and HTTPS_PROXY
Could not create SSL/TLS secure channel Windows PowerShell 5.1 without TLS 1.2 Enable TLS 1.2 (below) and rerun in the same window
Claude Code does not support 32-bit Windows You opened Windows PowerShell (x86) Open the entry without (x86)
claude opens the desktop app An old Claude Desktop owns the command Update Claude Desktop
# Add the install folder to PATH (Windows)
$currentPath = [Environment]::GetEnvironmentVariable('PATH', 'User')
[Environment]::SetEnvironmentVariable('PATH', "$currentPath;$env:USERPROFILE\.local\bin", 'User')
# Enable TLS 1.2 (Windows PowerShell 5.1)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
irm https://claude.ai/install.ps1 | iex
# Add the install folder to PATH (macOS, zsh)
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

To start over, uninstall the way you installed. Remove-Item and rm -rf delete for good, so type the paths carefully. Uninstalling doesn’t remove ~/.claude; delete it only if you accept losing settings and session history.

Remove-Item -Path "$env:USERPROFILE\.local\bin\claude.exe" -Force
Remove-Item -Path "$env:USERPROFILE\.local\share\claude" -Recurse -Force
rm -f ~/.local/bin/claude && rm -rf ~/.local/share/claude      # macOS native
winget uninstall Anthropic.ClaudeCode
brew uninstall --cask claude-code
npm uninstall -g @anthropic-ai/claude-code

Try it: the first Plan-mode prompt

You are in the folder [trading-agent-lab]. This is a planning session: read and
propose only. Don't create or edit files, don't install packages, don't run
commands that use the network, don't read .env or any file holding keys or passwords.
Context: I'm a new trader learning to code. The project uses only historical
data in data/, connects to no trading account and sends no orders.

1) List the files and folders, one line of description each.
2) Read [data/xauusd_h1.csv]: row count, column names, first and last candle
   time. If the time zone can't be determined from the file, write "unknown"; don't guess.
3) Propose a plan for src/ema.py: EMA [20] and [50] of the close column using
   pandas ewm(span=N, adjust=False); print the last 3 rows with time, close,
   ema20, ema50; save a chart of close and both EMAs to [reports/xauusd_h1_ema.png].
4) Propose tests/test_ema.py: closes (10, 11, 12, 13) with span=3 must give
   (10.0, 10.5, 11.25, 12.125); plus a case where the file has no close column
   and the error is clear.
5) Write the commands I will run myself to check (install pytest, run tests,
   run the script) for [Windows PowerShell or macOS], using the Python in .venv.

List assumptions, risks and anything you're unsure about. No views on future
prices. Stop after the plan so I can review it.

Every later session follows the same routine: right terminal, cd into the project, git status clean, claude, check the mode, plan, review, Manual, your own test run, git diff --staged, commit.

Key takeaways

  • If the machine has ANTHROPIC_API_KEY, decline it. /status must show a Claude account on a plan, not an API key.
  • deny: Read(./.env) in .claude/settings.json holds in every mode, but it doesn’t stop grep -r or a script that opens the file itself.
  • New sessions can start in Auto. Set defaultMode to plan, approve the plan, then choose Yes, manually approve edits to move to Manual.

Comments