Set up StopWarden with Claude Code or any AI agent
You can have an AI agent (Claude Code, Codex, Cursor, or any agent that can run PowerShell on your PC) configure StopWarden for you, once, from your strategy's source code or backtest. The agent writes the settings. You read the Learn report and decide whether Protect turns on. StopWarden enforces that split: it refuses to save Protect without an accepted Learn report, and config-set cannot write the acceptance for you.
This works on the free tier. Watch and the Safety Scan need no licence.
What the agent does, and what it never does
| The agent does | The agent never does |
|---|---|
| Reads your strategy code and tells you how it places stops | Runs autopilot learn --accept (that is your OK) |
| Runs the Safety Scan on your own NinjaTrader logs (read-only) | Sets "mode": "protect" |
Writes the settings with autopilot config-set --merge | Enables, disables, flattens or stops anything |
Runs autopilot doctor --json and shows you each failing row | Asks for or stores your passwords, bot tokens or licence key |
Runs autopilot learn (read-only) and shows you the report | Touches the NinjaTrader window |
If your agent can run shell commands, it can run learn --accept too. The rule is yours to hold: tell it not to, and read the report yourself before you accept.
Before you start
- Install StopWarden and compile the AddOn once (see the Quick start, Steps 1-4).
- Open a normal PowerShell window in a folder your agent can work in. Check that
autopilot versionprints a version. - Add your strategy to Sim101 in NinjaTrader and save the workspace (Quick start, Step 2). Leave it disabled.
Copy-paste prompt
Paste this into your agent. Replace the two lines in brackets.
You are setting up StopWarden, an add-on for NinjaTrader 8, for my strategy. Work on this PC, in PowerShell.
My strategy source: [path to my strategy .cs file or backtest code]
My account to start on: Sim101
Rules you must follow:
- Read `autopilot config-schema --json` first. It lists every setting, its range, who may change it, and the commands you may run.
- Keep "mode" as "watch". Never set "protect".
- Never run `autopilot learn --accept`, `enable`, `disable`, `flatten`, `stop`, `resume`, `store-secret`, `link-telegram` or `license`.
- Do not ask for or write any password, token or licence key.
- Change settings only with `autopilot config-set --merge --file <patch.json>`. Put only the keys you change in the file.
Steps:
1. Read my strategy source. Tell me: which instrument it trades, its trading hours, how it places its stop (SetStopLoss, an
exit stop order, or an ATM template), and whether it holds more than one instrument at a time.
2. Run `autopilot nt8-info` and pick my connection name, strategy row and account from its output. Show me your picks.
3. Run `autopilot scan --text --days 30` and show me what it found.
4. Write a patch with nt8.connections, targets (one strategy on one account), and a schedule that covers the strategy's trading hours.
If the strategy places stops with orders that are not Stop Market or Stop Limit, tell me before you add
watchdog.extra_stop_name_prefixes.
5. Run `autopilot config-set --merge --file <patch.json>`. If it prints RESULT=INVALID, fix every ERROR line and run it again.
6. Run `autopilot doctor --json`. Show me every row that is not a pass and say what I must do, in plain English.
7. Run `autopilot status` and tell me the mode and whether a Learn report is accepted.
8. Stop. Tell me to keep my strategy trading on Sim101 in Watch, and to run `autopilot learn` again after it has about 20 trades.
The safe command list
Every command below can be run by an agent. Each prints plain text or JSON to the terminal.
| Command | What it does |
|---|---|
autopilot config-schema --json | Every setting with type, default, range or choices, and who may change it. Also the command list and the rules above |
autopilot config-get | Your current settings as JSON |
autopilot config-set --merge --file patch.json | Checks every key and saves the settings. Writes nothing if any key is wrong, and lists every problem at once |
autopilot doctor --json | The pre-flight checks as a JSON list |
autopilot status | Phase, strategy, positions, mode, and protect_learn_accepted as JSON |
autopilot nt8-info | Your connection names, strategy rows and accounts, as JSON |
autopilot scan --json --days 30 | The Safety Scan over your own logs (read-only; see SCAN) |
autopilot learn --json | The Learn report (read-only). It does not turn anything on without --accept |
autopilot activity --tail 200 | The recent activity log |
autopilot verify-row | Asks NinjaTrader whether exactly one row matches your strategy and account |
autopilot check-update, autopilot version | Version and update check |
Ask-first commands (they act outside the settings file): autopilot test-alert sends a real message to your Telegram or Discord, and install-tasks, uninstall-tasks, shutdown and start change what runs on your PC.
What an agent can read from your code
| In your strategy | What it tells the agent |
|---|---|
Trading hours, session filters, TradingHours | schedule.launch_at, enable_at, disable_at (all on this PC's clock) |
SetStopLoss, ExitLongStopMarket, ExitShortStop | Plain stop orders. These are the orders StopWarden recognises as a stop |
AtmStrategyCreate or an ATM template | An ATM strategy. Protect is Watch-only for these (FAQ) |
| A stop order with a custom type or name | Tell the agent to list it; you decide whether it goes in watchdog.extra_stop_name_prefixes |
| Two instruments open at once on one account | Protect stays off (SAFETY) |
Backtest results do not set any StopWarden number. The wait before StopWarden acts is fixed, and the agent cannot change it.
Turning on Protect (your step)
Protect is for you to switch on. Follow the FAQ: run autopilot learn yourself, read what it says about your strategy's stops, and accept it only if you are happy. Some strategies stay Watch-only, and the report says why. Then activate a paid licence and choose Use Protect.
If something goes wrong
config-set printed RESULT=INVALID: every ERROR= line is one problem. Fix them all and run it again; nothing was saved. doctor shows a failing row: see Troubleshooting. To stop everything now, see the FAQ.