AI agents, Claude and ChatGPT

Claude trading bot: build one with Claude Code, safely

Yes, you can build a trading bot with Claude, using Claude Code. It reads your files, runs commands and talks to a broker through MCP, which makes it a real tool for a backtest or a bot. It also means your keys, your approvals and your broker’s own limits all matter. Here is how the pieces fit, as of November 2026.

[

November 16, 2026

]
•
[

19

 

min to read

]

The short answer

Yes, with setup. A Claude trading bot is Claude Code writing and running your strategy code, then connecting to a broker’s MCP server: Alpaca, Coinbase, Robinhood and Interactive Brokers each run one. Use a trade-only key, a separate account and deny rules for risky commands, since unattended runs skip some approval prompts. It never connects to Ethy.

Can you build a trading bot with Claude, and what is Claude Code?

Yes, with a caveat about what “Claude” means here. The chat window does not run a bot; Claude Code does, because it can write the code, run it and call a broker’s tools. That is what people mean by a Claude trading bot, and the rest of this page covers how it works and what to lock down.

Claude Code is Anthropic’s “agentic coding tool that reads your codebase, edits files, runs commands, and integrates with your development tools”, available in a terminal, inside VS Code and JetBrains, in a desktop app and on the web. You install it with one command (curl -fsSL https://claude.ai/install.sh | bash on macOS, Linux and WSL) and start it with claude inside a project folder; it needs a Claude subscription or an Anthropic Console account.

The difference from a normal chat is what it can touch. In chat, Claude works with what you paste, what it finds on the web and any connector you add, and answers in text. Claude Code opens your project’s files, runs shell commands such as a backtest script or a data download, writes commits, and, through MCP, calls outside tools such as a broker’s API. A CLAUDE.md file in your project root gives it standing instructions it reads at the start of every session, and it builds its own “auto memory” of what it learns as it works.

This page is about that second kind of work: writing and running code that touches a market, including a broker. Whether Claude itself, in an ordinary chat, can place a trade for you, through a browser agent or Anthropic’s own products, is a different question with a different answer; see can Claude trade for you? for that. Building an AI trading agent’s architecture from first principles, the parts that hold regardless of which coding tool writes them, is in how to build an AI trading agent for onchain markets. This page sits between the two: Claude Code specifically, as the thing doing the building.

How do you build a Claude trading bot or backtest with Claude Code?

The useful pattern is to let Claude Code write and run the deterministic parts, your rule, your data loading, your position sizing, and check its own work by running the code, rather than asking it to reason its way to an answer in words. Four habits make that safer:

  1. Ask for the plan before the code

    Switch Claude Code to plan mode with /plan and have it lay out the data source, the rule in plain language, and the metrics it will report before it writes a line. Catching a misunderstood rule here is cheaper than catching it after a run.

  2. Point it at real data, not its memory

    Have it download or read a CSV of candles rather than asking it to recall prices; a model’s training data is not a price feed, and a backtest built on remembered numbers is worthless. For the traps that catch a quick backtest, such as look-ahead bias (using information a trader could not have had at the time) and ignoring costs, see our guide to backtesting a trading strategy.

  3. Run it non-interactively for repeatable results

    For a script you’ll run again and again, use Claude Code’s non-interactive mode: claude -p "backtest the rule in strategy.md against data/eth-1h.csv and report win rate, max drawdown and Sharpe" --allowedTools "Read,Bash". Anthropic’s own documentation recommends adding --bare for this kind of scripted call, so the run skips auto-loading hooks, Skills, MCP servers and memory from whatever happens to be on the machine, and gives the same result everywhere it runs. Bare mode doesn’t use your subscription login, so set an ANTHROPIC_API_KEY from the Claude Console first.

  4. Read the cost, not just the result

    With --output-format json, the response includes total_cost_usd and a per-model breakdown, so a backtest you run in a loop doesn’t surprise you later. Anthropic’s docs call these client-side estimates that can differ from your actual bill.

claude -p "backtest the 9/21 EMA cross on data/eth-1h.csv, enter and exit at the next bar open, charge 0.05% per trade, and report trades, win rate, max drawdown and Sharpe" \
  --bare --allowedTools "Read,Bash" --output-format json | jq ".result, .total_cost_usd"

None of this makes the backtest itself more honest. A rule a model wrote can still look ahead, overfit, or skip trading costs, exactly as a human-written one can; the checks belong in the code you ask Claude Code to run, not in trusting its summary. Once a rule backtests the way you expect, turning it into a live bot is a second step: wiring the same script to a broker, on a schedule, with hard limits in front of every order. The next two sections cover the broker side and the limits.

What are Claude Skills, and is there one for trading?

Not from Anthropic. Its pre-built Agent Skills cover PowerPoint, Excel, Word and PDF files, and the skills bundled with Claude Code itself, such as /code-review, /debug and /loop, are developer tools. Its open-source Claude for Financial Services plugins add finance skills, such as comps, DCF models and earnings notes, but Anthropic says those agents don’t execute transactions. “Claude skills trading” is really a question about building your own.

A Skill is a folder with a SKILL.md file: a short YAML header (a name and a description Claude matches your request against) and markdown instructions, plus any scripts or reference files it needs. In Claude Code specifically, you place one in ~/.claude/skills/ to use it in every project, or in .claude/skills/ to keep it with one repository and share it with your team. Claude reads the description at the start of a session, almost free in tokens, and only loads the full instructions when a request matches it.

A backtest-runbook Skill is a reasonable first one to write: a SKILL.md that tells Claude Code which CSV columns your data uses, which cost assumptions to charge by default, and which metrics to report every time, so you stop repeating the same instructions in every session.

---
name: backtest-runbook
description: Backtests a trading rule against our standard OHLCV CSV format. Use when the
  user asks to backtest, test, or evaluate a trading rule against historical data.
---

## Data format
Columns: date, open, high, low, close, volume. One file per market, in data/.

## Defaults unless the user says otherwise
- Enter and exit at the next bar's open, never the signal bar's close.
- Charge 0.05% per trade for costs.
- Report: number of trades, win rate, max drawdown, Sharpe ratio, and the result against
  buy-and-hold over the same dates.

## Script
Run `scripts/backtest.py <rule> <csv>` and report its JSON output in a short table.

Treat a Skill from anyone else the way you’d treat installed software, because it is exactly that. Anthropic’s own guidance is direct: “Use Skills only from trusted sources: those you created yourself or obtained from Anthropic,” since “a malicious Skill can direct Claude to call tools or run code in ways that don’t match the Skill’s stated purpose.” A Skill that fetches data from an outside URL is riskier again, since whatever it fetches becomes something Claude reads and can act on. Audit the SKILL.md and every bundled script before you add a Skill you downloaded, exactly as you would before running a script from a stranger.

How do you connect Claude Code to a broker with MCP?

MCP, the Model Context Protocol, is the open standard Anthropic built for this: a broker runs a server that offers tools such as “get positions” or “place order”, and claude mcp add wires it into Claude Code. All four brokers this guide covers run a server Claude Code can add; three print the exact command, and Interactive Brokers gives the address.

Connecting Claude Code to four brokers, from each broker’s own documentation, November 16, 2026
BrokerAdd it in Claude CodeWhat the connection reaches
Alpacaclaude mcp add alpaca --scope user --transport stdio uvx alpaca-mcp-server --env ALPACA_API_KEY=... --env ALPACA_SECRET_KEY=...Stocks, options and crypto orders through Alpaca’s own API; its docs say the server “defaults to paper trading” and needs ALPACA_PAPER_TRADE=false with live keys to risk real money
Coinbaseclaude mcp add coinbase --transport http https://agents.coinbase.com/mcp, then /mcp to authenticateWhichever portfolios you scope the connection to at sign-in; for its command-line route, Coinbase’s docs separate a Trade permission on the API key from a Transfer permission, which “allows moves between your portfolios only” and no withdrawals to an outside address
Robinhoodclaude mcp add robinhood-trading --transport http https://agent.robinhood.com/mcp/trading, then /mcp and authenticateA separate “Robinhood Agentic” account you fund yourself; Robinhood’s own page for outside agents says the connection reads all your account numbers, balances and order history, but “can only place trades in your Robinhood Agentic account”
Interactive BrokersNo ready-made command; IBKR names Claude Code among the apps that can connect and gives the address to add as an MCP server, https://api.ibkr.com/v1/api/mcp-public, then you authorize access on IBKR’s own login screenResearch, monitoring and drafted orders you submit yourself by default; its Autonomous Trading, which trades without asking each time, opens up only inside a separate, funded AI Partition, after at least 10 trades in two weeks in a Review and Approve mode

IBKR is the strictest about autonomy: its AI integration page warns that if you link an AI any other way, “including browser-based and similar agents, you are providing those AI agents with full control of your account, without any controls or limits”, and Autonomous Trading, introduced October 21, 2026, only runs inside that dedicated partition. You are responsible for what goes out under your name either way; both Robinhood and IBKR say so in as many words, and Alpaca’s README adds a line worth keeping in view while you work: “This server can place real trades and access your portfolio. Treat your API keys as sensitive credentials.”

Two Claude Code details change what “connecting a broker” actually means in practice. First, scope: --scope user keeps a server available in every project on your machine; --scope project writes it to a .mcp.json file you could commit to a repository, which is a mistake if that file or its environment holds a live key. Second, approval: Claude Code’s own docs say it “prompts for approval in interactive sessions before using project-scoped servers from .mcp.json files”, but a non-interactive run started with claude -p, or a cloud session outside a project, “loads project-scoped servers without asking.” A broker server you’d never approve by hand can still connect automatically the moment you (or someone else’s cloned repository) runs a script that way. Pass --strict-mcp-config when you want a run to use only the servers you pass with --mcp-config, nothing a project file adds on its own.

All four brokers name Claude Code as a client, alongside Claude’s chat apps; our guide to whether Claude can trade for you covers the chat-app side of Robinhood’s connector, including its approval defaults, and agentic trading covers the wider landscape of brokers opening up to AI agents, Claude included.

How do you handle API keys and approvals in Claude Code?

You have two separate places to put a limit: on the tool Claude is about to use, through Claude Code’s own permission system, and on the broker key underneath it. Use both.

Lock down the tool, in settings.json

A project or personal settings file can allow, ask about, or flatly deny a tool, down to one MCP tool by name (mcp__<server>__<tool>). This example, with the tool names Alpaca’s server uses, lets Claude Code read your account, positions and recent orders without asking, while refusing the tools that place, replace or close orders and direct reads of your key file, whatever a prompt or a compromised Skill asks for:

{
  "permissions": {
    "allow": ["mcp__alpaca__get_account_info", "mcp__alpaca__get_all_positions", "mcp__alpaca__get_orders"],
    "deny": [
      "mcp__alpaca__place_stock_order", "mcp__alpaca__place_crypto_order", "mcp__alpaca__place_option_order",
      "mcp__alpaca__replace_order_by_id", "mcp__alpaca__close_position", "mcp__alpaca__close_all_positions",
      "Read(./.env)", "Read(./.env.*)"
    ]
  }
}

Claude Code also ships permission modes you can set for a whole session with --permission-mode: Manual mode asks before anything beyond a read-only command; Accept Edits auto-approves file edits and basic filesystem commands but still asks before a shell command that isn’t on your allow list; and Auto mode, where current versions start interactive terminal sessions, hands routine approvals to a built-in classifier instead of you. None of the three substitutes for the deny rule above: a classifier reviewing “is this a reasonable thing to do” is not the same as a rule that refuses a specific tool outright.

Lock down the key, at the broker

Every broker here lets you narrow what a key or a connection can do before Claude Code ever sees it: Alpaca’s server reads an ALPACA_TOOLSETS variable that can restrict it to read-only market data tools; Coinbase scopes a connection to the portfolios you pick at sign-in, and separates Trade from Transfer permissions on the API key its command-line tool uses, keeping the Transfer permission from reaching an external address; Robinhood’s agentic account and IBKR’s AI Partition limit an agent to the money you put in them, whatever it asks for. Use the narrowest one your task needs, the same least-privilege approach OWASP recommends generally for an AI system with tool access: “limit the permissions that LLM extensions are granted to other systems to the minimum necessary”, and “require a human to approve high-impact actions before they are taken.”

Keep the keys themselves out of the conversation and out of your repository. Pass them as environment variables in the MCP server’s own config, the way the Alpaca command above does, never typed into a prompt; a settings file deny rule for Read(./.env) stops Claude Code’s file tools and commands such as cat from reading it, though Anthropic notes it doesn’t cover a script that opens the file itself. Claude Code itself stores your own Anthropic credentials in the macOS Keychain, or a permissions-restricted file on Linux and Windows, which is the standard to hold a broker key to as well.

What goes wrong when traders use Claude Code to build a bot?

Most of what can go wrong when a coding agent touches money comes down to a few failures:

Common failure points when Claude Code is wired to a broker, and what limits each one
What goes wrongWhy it happensWhat limits it
A scheduled run connects a server you never approvedA non-interactive or cloud run skips the interactive approval prompt for project-scoped serversUse --strict-mcp-config, or review every .mcp.json before you run a cloned repository non-interactively
Paper mode was off and nobody noticedAlpaca’s server is paper-trading by default, but a copied command or a stale environment variable can set ALPACA_PAPER_TRADE=falseCheck the flag before every run that matters, and log it with the result
A broker key does more than the task needsIt’s faster to reuse one key for everything than to scope a new one for every scriptMatch the key, or the toolset, to the job: read-only for research, trade-only for a bot, never a key that can withdraw
A Skill or an MCP server does something its description doesn’t mentionAnthropic doesn’t security-audit third-party MCP servers, even ones listed in its own directory, and a malicious Skill can call tools in ways that don’t match its stated purposeRead the code before you add anything from outside Anthropic; keep untrusted servers and Skills away from sessions that can also place an order
The rule looked great backtested, then lost money liveThe same look-ahead bias and overfitting that can slip into any backtest; a coding agent writes the mistake faster, it doesn’t avoid itKeep the checks in code: a held-out test window, realistic costs, and a paper-trading run before real money
Nobody was there to click “allow”An unattended job built with --permission-prompts none denies anything that would have needed a person, it doesn’t grant itDesign the job to need no approval at all for what it does: narrow tool access, hard limits in the script, not a wider permission mode

The deeper pattern behind most of this table is that an agent with tool access can do real damage from a request that was never meant to reach your account. That’s what OWASP calls excessive agency: a system granted “the ability to call functions or interface with other systems” ends up performing “damaging actions”, whatever caused them, because it had more functionality, more permission or more autonomy than the task required. The fix in its list is the same fix as above, restated for any agent, not just Claude Code: give it only the extensions it needs, give those extensions only the access they need, and keep a person, or a hard rule in code, in front of anything with real consequences.

How to vet a repository or a package you didn’t write yourself, including the fake “trading bot” repos that circulate with inflated stars, is covered in depth in how to build an AI trading agent for onchain markets; the same caution applies whether Claude Code, another coding tool, or a human wrote the result.

How do you keep a Claude Code trading setup secure?

  1. Start on paper, in a separate account

    Alpaca defaults to paper trading; Coinbase, Robinhood and IBKR all point you toward a separate portfolio, agentic account or AI Partition funded only with what you could lose. Use that account until the whole flow, from data to order, has run without a surprise for weeks.

  2. Scope the key before you scope the prompt

    A read-only or trade-only key limits the damage of a bug or a bad instruction more reliably than asking Claude Code nicely in the system prompt. Set it at the broker, not in words.

  3. Write deny rules for the specific tools and files that matter

    An order tool, a withdrawal tool, your .env file: name them in settings.json rather than relying on a permission mode to catch everything.

  4. Treat every MCP server and Skill like software you install

    Read what it does before you add it, prefer the broker’s own published server over a community clone, and keep ones you don’t fully trust out of any session that can also reach your account.

  5. Review what ran, not just what it returned

    With --output-format stream-json, a run’s opening system/init event lists its MCP servers and their status, and any --mcp-config entry it skipped; Claude Code’s security docs note plainly that it does not security-audit third-party MCP servers, listed or not, so that review is yours to do.

  6. Keep this separate from Ethy

    Claude Code is a general tool you wire to a broker yourself, piece by piece. Ethy is a different product, with its own app: you can’t point Claude Code, or any other assistant, at Ethy through MCP or an API.

Where does Ethy fit next to a Claude Code bot you build yourself?

Claude Code is the general-purpose option: full control, your own broker, your own risk code, and the engineering time that takes. An AI trading agent built for trading from the start trades the engineering for a narrower, ready-made tool. Ethy is one, the AI trading agent you ask before you trade, and it covers most of what the sections above exist to build:

  • A chart read with no script to write. The daily, 4-hour, 1-hour and 15-minute charts together, with the trend on each, support and resistance, RSI and MACD divergences, Fibonacci levels, VWAP, volume nodes, patterns and an overall bias.
  • A backtester already wired to the market. Describe a rule in plain words and Ethy backtests the exact version that would deploy, on up to 365 days of history, with every entry and exit marked, no CSV to find or clean.
  • Limits that live in the product, not in a settings file you maintain. Stop loss and take profit sit on Hyperliquid itself and fire even when Ethy is closed; automations can add a maximum daily loss and a maximum drawdown, and they pause after 10 losing trades in a row by default.
  • Your trading plan, read first. Your own rules for risk, markets, process and goals, checked at the start of every chat, with a flag when an idea goes against them.

It places the order too: from the chat, Ethy trades Hyperliquid perpetual futures, which cover crypto plus the stocks, indices, commodities and currencies listed on trade.xyz, and it runs spot swaps. New users see a confirmation card before an order goes out; automations trade on their own once activated, live or in paper mode with no money at stake. Your balance lives in a wallet that belongs to you, and you can export its key at any time. There’s no MCP server to add and no API key to manage, because there’s nothing to connect: you use Ethy in its own app, not from inside Claude Code. Ethy is software for research and analysis, and it doesn’t give investment advice.

Summary

  • Claude Code can write and run a backtest against real data, and connect to a broker through MCP: Alpaca, Coinbase and Robinhood each publish the claude mcp add command for their server, and Interactive Brokers publishes the address of its own.
  • There’s no official Claude trading Skill; writing your own is a SKILL.md file in ~/.claude/skills/ or .claude/skills/, and a Skill from an untrusted source should be audited like any other software you install.
  • Set limits in two places: Claude Code’s own permissions (allow, ask and deny rules, down to one MCP tool by name) and the broker’s own key scope (read-only, trade-only, a separate funded account).
  • A non-interactive or cloud run skips the approval prompt that project-scoped MCP servers normally get in an interactive session, so review a repository’s .mcp.json before you run it unattended.
  • Most of what goes wrong traces back to excessive agency: a tool, a key or an approval that reached further than the task needed. Scope each one narrowly and keep a hard rule in code in front of anything that spends money.
  • None of this connects to Ethy. Claude Code is a general tool you wire up yourself; Ethy is a separate, ready-made product with its own app.

Questions people ask

Can Claude Code place real trades by itself?

Only once you connect a broker’s MCP server and give it a funded account to trade in, such as Alpaca’s, Coinbase’s or Robinhood’s agentic account. Out of the box it has no brokerage account and no key. Either way, Claude Code never connects to Ethy; they are separate products.

Is there an official Claude Code skill for trading?

No. Anthropic’s pre-built Agent Skills cover document formats such as PowerPoint and Excel, not trading, and its Claude for Financial Services plugins cover research and valuation work, not placing trades. You can write your own as a SKILL.md file describing your data format and default assumptions, but audit any Skill you didn’t write yourself before you add it, the same way you would a script.

Does Claude Code work with Interactive Brokers?

Yes. IBKR’s AI Integration page names Claude Code among the apps that can connect: you add its MCP address, https://api.ibkr.com/v1/api/mcp-public, and authorize access through IBKR’s own login. Drafted orders go through your review by default, and its Autonomous Trading opens up only inside a separate, funded AI Partition after a track record in its Review and Approve mode.

Can a Claude Code trading bot run while my laptop is off?

With a cloud scheduled task, yes, the same way Claude Code can schedule any recurring job. A scheduled run that reaches a broker still needs the same key scoping and deny rules as one you run by hand, because nobody is there to answer an approval prompt while it runs.

Is it safe to let Claude Code trade unattended?

Safer with narrow permissions than without them, never fully safe. An unattended run started with --permission-prompts none denies anything that would have needed a person to approve, it doesn’t grant it, so design the job so the risky actions it might attempt are the ones you’ve already blocked at the tool or the key.

What’s the difference between Claude Code and chatting with Claude about trading?

Claude Code reads your files, runs commands and can call a broker’s tools directly; a chat works with what you paste, what it finds on the web and any connector you add, and has no route to your accounts on its own. What chat Claude can and can’t do around a trade, including Anthropic’s own rules on financial advice, is covered in can Claude trade for you?

Sources

  1. Claude Code docs: Overviewcode.claude.com
  2. Claude Code docs: Connect Claude Code to tools via MCPcode.claude.com
  3. Claude Code docs: Settings files and precedencecode.claude.com
  4. Claude Code docs: Use Skills in Claude Codecode.claude.com
  5. Claude Code docs: Run Claude Code programmatically (headless mode)code.claude.com
  6. Claude Code docs: Securitycode.claude.com
  7. Claude Code docs: Permission modescode.claude.com
  8. Anthropic docs: Agent Skills overviewplatform.claude.com
  9. Anthropic: Claude for Financial Services, agents and skills (GitHub)github.com
  10. Alpaca docs: Trading API MCP serverdocs.alpaca.markets
  11. Alpaca: alpaca-mcp-server README (GitHub)github.com
  12. Coinbase Developer Docs: Coinbase MCPdocs.cdp.coinbase.com
  13. Robinhood: Onboarding an external agent (Trading MCP)robinhood.com
  14. Interactive Brokers: AI Integration and IBKR Autonomous Tradinginteractivebrokers.com
  15. Interactive Brokers: Interactive Brokers Introduces Autonomous Trading (October 21, 2026)interactivebrokers.com
  16. OWASP Top 10 for LLM Applications 2025: LLM06:2025 Excessive Agencygenai.owasp.org

Trading involves risk, including the loss of your money. Ethy AI is a research and trading tool and does not give investment advice or recommendations. Backtests are simulations on historical data and do not predict future results.

Ethy blog

Read more

The $ETHY ecosystem

Stop watching charts.
Start living.

Deploy your AI trading agent in one click.