Run End-to-End Tests from Your Terminal with Kane CLI

Author and Run Tests Right from the Terminal in Natural Language, with an Evidence-Backed Pass or Fail from a Real Browser.

npm install -g @testmuai/kane-cli

AIAutomationCoding

How to Add Automated Testing to Claude Code, Cursor, Copilot, and Codex

Make Claude Code, Cursor, Copilot and Codex test their own work: the file each agent reads, a stop hook that runs your tests, and a real browser check.

Last Updated on:

The agent finishes the feature and writes, confidently, that it has been tested. Nothing opened a browser. Nothing ran.

The gap is not that these tools cannot test. It is that nobody told them, in a place they read, what testing means in this repository.

That place is different for each tool, and one of them is now read by all four. For how the agents themselves compare on pricing, models and headless runs, see Claude Code vs Codex vs Cursor.

TL;DR

To test code written by an AI coding agent such as Cursor, Codex, Claude Code or Copilot, don't let the agent that wrote it be the only judge: put the test rule in the file the agent reads, add a stop hook that runs the tests before it finishes, verify the change in a real browser with Kane CLI from TestMu AI, and require the same checks in CI.

  • Claude Code: reads CLAUDE.md and path-scoped rules in .claude/rules. Reads AGENTS.md: yes, only when no CLAUDE.md exists, otherwise through a line reading @AGENTS.md. Stop hook that blocks: yes, in .claude/settings.json, exit code 2, ending the turn after eight continuations in a row.
  • Cursor: reads .mdc rule files under .cursor/rules. Reads AGENTS.md: yes. Stop hook that sends it back: yes, a stop hook in .cursor/hooks.json returns a followup_message, which Cursor submits as the next user message, up to loop_limit times (5 by default).
  • GitHub Copilot: reads .github/copilot-instructions.md and path-scoped .instructions.md files under .github/instructions. Reads AGENTS.md: yes. Stop hook that blocks: no, its agentStop hook is not documented as able to block, so a required status check on the pull request is the gate.
  • Codex: AGENTS.md is its native instruction file, read from the project root down to the working directory. Stop hook that blocks: yes, exit code 2 with the reason on stderr, after you trust the hook in /hooks; no continuation cap is documented, so the script reads stop_hook_active.
  • Kane CLI: runs a plain-English objective in real Chrome and exits 0 when the change is verified, 1 when the check failed, 2 when the run did not start and 3 when it timed out or was cancelled, so any of the four agents can branch on the result.
  • Required status check: a CI check required on the pull request reruns the tests and the Kane CLI check, so a change merges only when both pass, whichever of the four coding agents wrote it.

Why Do AI Coding Agents Skip Testing?

Because testing was never defined for them. Left undefined, an agent settles on the cheapest thing that resembles verification, which is usually reading its own diff and declaring it correct.

There is also a capability gap underneath the instruction gap. Some agents can open a browser, Cursor's among them, but unless the repository names a browser check, nothing in a default setup turns what the agent sees there into a pass or fail it has to respect.

  • They can run commands - that is the opening, because a shell command is something all four already do without new integrations.
  • They do not check a page by default - without a browser check in the loop, a rendering failure produces no signal at all.
  • They will not invent a convention - if the repository has no stated check, the agent picks whatever it saw most in training.
  • Vague instructions read as optional - test your changes competes with every other line in context and usually loses.
  • They grade their own work - when the same agent writes the code and the tests, a green run shows that the two agree, which is a weaker claim than the feature working for a user; can coding agents test their own code goes through why.

A review does not close the gap either. Claude Code's Code Review reads the diff and the surrounding code without building or running it, so a clean review says nothing about whether the page renders; AI code review vs verification compares what each one catches.

To pick the tool that runs those checks, the best E2E testing tool for Claude Code compares Kane CLI, Playwright Test and Playwright MCP.

How Do You Add Testing to an AI Coding Agent, Step by Step?

Set the checks up in this order, whichever agent writes the code. Steps 2 to 4 differ by tool and are set up below; steps 1, 5 and 6 are the same for all four.

  • Write the acceptance criteria first - state the expected behaviour, the edge cases and the error states before the agent starts, then have it write failing tests from them and leave those tests alone while it implements. This is test-driven development with the agent as the implementer, and writing the acceptance criteria before the code keeps the tests tied to the requirement rather than to whatever the agent built. Spec-driven development tools such as Spec Kit and OpenSpec build this step in, writing the spec before the agent plans or codes. Spec-driven testing then checks the finished app against each criterion in that spec.
  • Put the rule where the agent reads it - CLAUDE.md or AGENTS.md for Claude Code, a .mdc rule or AGENTS.md for Cursor, .github/copilot-instructions.md or AGENTS.md for Copilot, and AGENTS.md for Codex. The table below has the paths.
  • Enforce the rule with a hook - a hook that runs when the agent tries to finish can run the tests and send it back while they fail, which turns an instruction the agent may skip into a check that runs every time.
  • Check the change in a real browser - unit tests cannot see a button that renders off-screen on a phone or a form that posts to the wrong route, so give the agent a command that opens the page, checks the outcome and returns an exit code. How to verify AI-written UI changes across viewports walks through that check.
  • Make CI the final gate - run the same tests and the browser check as required status checks on the pull request, and run mutation testing on the changed files: when a deliberately broken copy of the code still passes, the tests around it assert too little. Continuous verification for AI code covers the pipeline design, and how to gate a pull request with Kane CLI covers the browser step. Our guide to deterministic tests covers the repeat-run checks for tests an agent wrote.
  • Review against a checklist - a person, or a second agent that did not write the change, checks that no assertion was removed or loosened, that every imported package exists, and that the agent's closing claims match the CI run. A code review checklist covers the rest.

For front-end work, our Modern Web Guidance guide runs these steps on a confirmation dialog, from written criteria to a merge gate and a real iPhone check.

Where Do Claude Code, Cursor, Copilot, and Codex Read Instructions?

Each tool has its own preferred file, and each has a second path that behaves differently. Getting the path wrong is the most common reason an instruction appears to be ignored.

ToolNative instruction fileScoping mechanismAlso reads AGENTS.md
Claude CodeCLAUDE.md or .claude/CLAUDE.md at the project root, plus ~/.claude/CLAUDE.md for every projectMarkdown files in .claude/rules with a paths list in the frontmatter, which load only when Claude works with matching filesYes, when no CLAUDE.md exists (version 2.1.277 or later); otherwise import it with a line reading @AGENTS.md
Cursor.mdc rule files under .cursor/rulesFrontmatter: alwaysApply, globs, or description for intelligent selectionYes, in the project root and subdirectories
GitHub Copilot.github/copilot-instructions.md.github/instructions/NAME.instructions.md with an applyTo globYes, nearest file in the directory tree takes precedence
CodexAGENTS.mdProject root file, or a global one under the Codex config directoryYes, this is its native file

One caveat on the Copilot row is worth reading twice. GitHub's documentation states that path-specific custom instructions on GitHub.com are currently supported only for the Copilot cloud agent and Copilot code review, so a glob-scoped file will not necessarily reach every surface you use.

Claude Code has a similar catch. It reads AGENTS.md only when no CLAUDE.md exists in the working directory or above it, and only from version 2.1.277, so a repository that already has a CLAUDE.md needs a line reading @AGENTS.md in it.

Full field references live in the Claude Code memory documentation, the Cursor rules documentation and GitHub's guide to repository custom instructions.

AGENTS.md: The One Instruction File All Four Tools Read

AGENTS.md is the convergence point. Write the testing contract there once and Cursor, Copilot, Codex and Claude Code all pick it up, which turns four integrations into one file in the repository root.

For Claude Code in a repository that also has a CLAUDE.md, import the file at the top of CLAUDE.md and keep Claude-specific lines below it:

@AGENTS.md

## Claude Code
Follow the verification contract in AGENTS.md before you report a task as done.

What goes in it matters more than where it goes. Name the trigger, the exact command, and what each outcome means.

## Verification contract

After changing anything under src/ that affects a rendered page, run:

    kane-cli run --agent --headless "Go to <page URL>, then <the user-visible result to check>"

Rules for reading the result:

- Exit 0 means verified. Only then may you report the task complete.
- Exit 1 means the check failed. Fix the feature. Do not weaken the objective.
- Exit 2 means the run did not start: sign-in, Chrome, configuration or no
  start URL. Say so. This is not a code failure.
- Exit 3 means the run timed out or was cancelled. Re-run once, then escalate.

Never report success on a non-zero exit code.

The last line does the most work. Without it, agents routinely summarise a failed run as a minor issue and carry on.

Note also that this contract names no selectors and no framework. That is deliberate, because it has to survive all four tools and whichever one you adopt next.

To start an AGENTS.md from a template, the free AGENTS.md generator builds one for Cursor, Claude Code and Copilot.

Which Hook Keeps Each Coding Agent Working Until Tests Pass?

Claude Code, Cursor and Codex each run a hook when the agent tries to finish, and each lets that hook send the agent back to work. GitHub Copilot runs a hook at the same moment, but its documentation describes only the hook before a tool call as able to deny anything. Those stop hooks sit at the step of the agentic coding loop where the agent decides its work is done.

ToolHook fileEvent when the agent finishesHow the hook sends it backLoop guard
Claude Code.claude/settings.json in the project, or ~/.claude/settings.json for every projectStopExit code 2 with the reason on stderr, or a JSON decision of block with a reasonEnds the turn after eight continuations in a row
Cursor.cursor/hooks.json in the project, or ~/.cursor/hooks.jsonstopReturns a followup_message, which Cursor sends as the next user messageloop_limit, 5 by default
Codexhooks.json next to the Codex config, or a hooks table in config.tomlStopExit code 2 with the reason on stderr, or a JSON decision of blockNo documented cap; the script reads stop_hook_active to see a turn that was already continued
GitHub Copilot.github/hooks/*.jsonagentStopNot documented as able to blockNot applicable; use a required status check on the pull request

Hooks can also stop an action before it runs, such as a shell command or a file write; pre-action checks for AI coding agents covers that side. Each tool's section below has a working configuration.

Wiring Claude Code: A CLAUDE.md Rule and a Stop Hook

Give Claude Code the testing rule in CLAUDE.md, then enforce it with a Stop hook that runs the tests and sends Claude back to work while they fail. On teams with an agentic quality engineer, that person writes and maintains this rule and reviews the tests agents write under it. Teams running Spec Kit with Claude Code can also put a rule like this in its constitution, the standing rules every later Spec Kit command reads.

For a quick visual walkthrough of this concept, watch the video below from TestMu AI.

Youtube thumbnail

Subscribe to the TestMu AI YouTube channel for more tutorials on testing and automation.

## Testing rules
- Before implementing, write failing tests from the acceptance criteria and show them to me.
- Never delete, skip or loosen an assertion to make a test pass. If a test looks wrong, stop and ask.
- Run npm test after any change under src/. After a change to a rendered page,
  follow the verification contract in AGENTS.md.
- Do not report a task as complete while any test or verification run is failing.

Hooks live in .claude/settings.json, which the team shares through the repository, in .claude/settings.local.json for personal settings, or in ~/.claude/settings.json for every project. This one runs a script when Claude tries to finish:

{
  "hooks": {
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/run-tests.sh",
            "timeout": 600
          }
        ]
      }
    ]
  }
}

The script exits with code 2 when the tests fail, which keeps Claude working, and whatever it writes to stderr is the reason Claude reads:

#!/usr/bin/env bash
# .claude/hooks/run-tests.sh
# Exit 2 keeps Claude working; stderr is the reason it reads.
cd "${CLAUDE_PROJECT_DIR:-.}" || exit 0
log=$(mktemp)
if npm test --silent > "$log" 2>&1; then
  exit 0
fi
echo "Tests are failing. Fix the code, not the tests, then finish again." >&2
tail -n 40 "$log" >&2
exit 2

Make it executable with chmod +x .claude/hooks/run-tests.sh, then type /hooks in Claude Code to see the hook listed with the settings file it came from. Claude Code ends the turn anyway after eight continuations in a row, and the hook's input includes stop_hook_active, which is true when Claude is already continuing because of a stop hook, so a stricter script can allow one retry and then let a person look.

If the hook runs Kane CLI instead of npm test, translate the exit codes before the script exits. Kane CLI's 1 (the check failed) has to become the hook's 2, and its 2 (the run did not start) should not block, because nothing about the code was tested. Claude Code hooks has that translation script and the full event list, and test apps built with Claude Code shows browser checks for the apps Claude Code builds.

Wiring Cursor: A Rule File and a Stop Hook

AGENTS.md alone is enough for Cursor. Add a rule file only when you want the instruction to fire on specific paths rather than on every session.

---
description: Browser verification required for UI changes
globs: ["src/pages/**", "src/components/**"]
alwaysApply: false
---

Any change matching these globs must be verified in a real browser
before the task is reported complete. Follow the verification contract
in AGENTS.md. A non-zero exit code is a failure, not a warning.

Save that as a .mdc file under .cursor/rules. With alwaysApply set to false and globs set, the rule attaches only when a matching file is in play, which keeps it out of the way during unrelated work. A plain .md file in .cursor/rules is ignored, and Cursor asks for rules under 500 lines.

We covered the rest of the rule system, including how the four application types differ, in Cursor rules.

This section covers the editor. For the same agent running headless in a terminal or CI job instead, see our guide to Cursor CLI.

A rule asks Cursor to run the tests; a hook runs them. Cursor reads hooks from .cursor/hooks.json in the project, or ~/.cursor/hooks.json for every project, and project hooks run from the project root. A hook that exits with code 2 blocks the action, any other non-zero code lets it go ahead, and a stop hook that returns a non-empty followup_message has Cursor send that text as the next user message, up to loop_limit times (5 by default). The Cursor hooks documentation lists every event.

{
  "version": 1,
  "hooks": {
    "stop": [
      {
        "command": ".cursor/hooks/tests-or-followup.sh",
        "timeout": 600,
        "loop_limit": 3
      }
    ]
  }
}

The script acts only when the agent finished normally, and it needs jq:

#!/usr/bin/env bash
# .cursor/hooks/tests-or-followup.sh
# If the tests fail, send the failure back as the next message.
status=$(jq -r '.status')
if [ "$status" != "completed" ]; then echo '{}'; exit 0; fi
log=$(mktemp)
if npm test --silent > "$log" 2>&1; then echo '{}'; exit 0; fi
jq -n --arg out "$(tail -n 30 "$log")" \
  '{followup_message: ("Tests are failing. Fix the code, not the tests.\n" + $out)}'

With Auto-run on, Cursor executes the tests automatically, and a Bugbot rule can flag pull requests that change code without adding tests, as Cursor's test-generation guide shows. To check the apps Cursor builds in a browser, see test apps built with Cursor.

Test infrastructure that does not break, from TestMu AI

Wiring GitHub Copilot: Instructions and a Required Check

Copilot has the widest spread between surfaces, so decide which surface you are targeting before choosing a file.

  • Repository-wide - put the contract in .github/copilot-instructions.md, the broadest option and the one to start with.
  • Path-scoped - add .github/instructions/browser-checks.instructions.md with an applyTo glob such as src/pages/**, remembering GitHub's stated surface limits.
  • Shared with the others - rely on AGENTS.md, where GitHub documents that the nearest file in the tree wins.
  • Nested overrides - a subdirectory AGENTS.md lets a monorepo package state a stricter contract than the root.

GitHub also documents CLAUDE.md and GEMINI.md in the repository root as alternatives Copilot will honour. If your repository already has one of those for another agent, Copilot can read it rather than needing a duplicate. How Copilot and Claude Code compare beyond instruction files is covered in GitHub Copilot vs Claude Code.

Copilot runs hooks too, from JSON files in .github/hooks, in the Copilot app, the Copilot CLI and the cloud agent, with VS Code support in public preview. GitHub's documentation describes only the preToolUse hook as able to deny an action, and agentStop runs when the agent has finished responding, so for Copilot the dependable gate is a required status check on the pull request. Browser checks for the apps Copilot builds are on test apps built with GitHub Copilot.

Wiring Codex: AGENTS.md, the Kane CLI Skill and Hooks

Codex is the simplest of the four, because AGENTS.md is its native format rather than a compatibility layer.

It reads AGENTS.md from the project root down to the working directory, and a global file in the Codex home directory (~/.codex unless CODEX_HOME is set) applies across every repository on the machine. TestMu AI publishes the Kane CLI instructions in two forms: a skill installer and an AGENTS.md section you can append.

# Once per machine: install Kane CLI and sign in
npm install -g @testmuai/kane-cli
kane-cli login

# Option 1: install the Kane CLI skill
# (the same installer covers Claude Code and Gemini CLI)
npx @testmuai/kane-cli-skill

# Option 2: append the Kane CLI instructions to AGENTS.md
# (run it once from the repository root, since >> appends)
curl -fsSL https://www.testmuai.com/kane-cli-agent/AGENTS.md >> AGENTS.md

Codex stops adding instruction files once their combined size reaches 32 KiB, and the Kane CLI section was about 18 KB in October 2026, so check the total on a repository whose AGENTS.md is already long; the skill installer keeps those instructions out of AGENTS.md. Codex also runs hooks, from a hooks.json file next to its config or a hooks table in config.toml, and it skips a new or changed hook until you review and trust it in /hooks. A Stop hook that exits with code 2 sends Codex back to work, and the reason it writes to stderr becomes the next prompt. The guide to Codex skills covers where Codex looks for SKILL.md files and how to check that one triggers.

Because Cursor reads AGENTS.md too, the appended section in option 2 covers Cursor without a second step. Codex-specific usage limits and how to stretch them are covered separately in Codex usage.

Setup for other agents, Gemini CLI among them, is in the Kane CLI with AI coding agents documentation, and test apps built with Codex covers browser checks for Codex builds.

Which Command Should a Coding Agent Run to Verify Its Work?

The instruction is only as good as the command it names. That command has to work headless, return a status the agent can branch on, and not require a test file that does not exist yet.

Kane CLI from TestMu AI fits those three constraints. It takes the objective in plain English, drives real Chrome, and exits with a POSIX status. For the full setup, see AI code testing for coding agents.

  • No test file required - the objective is the test, which suits an agent verifying something it built two minutes ago.
  • Machine-readable stream - agent mode emits newline-delimited JSON and closes with a run_end event carrying the full result.
  • Runs where agents run - headless mode needs no display server, so it works the same in a terminal, in CI, and in a cloud agent. Kane CLI drives Chrome on your machine, and with --remote runs the same suite in Chrome on a HyperExecute runner. For cloud coding agents that open their own pull requests, Devin Bots vs Kane CLI walks through a merge gate for bot PRs.
  • Apps as well as pages - for native apps it runs on emulators and simulators, and since Kane CLI 0.9.0 on real Android and iOS devices in the TestMu AI cloud, which needs KaneAI Max for one device, or KaneAI credits plus Real Device Plus Automation Cloud.
  • Evidence for the reviewer - every run that starts seals an evidence pack with per-step screenshots, network and console logs and failure records, prints its path on stderr, and opens locally with kane-cli evidence serve.
  • Install is one command - npm install -g @testmuai/kane-cli, with Node.js 18 or higher and Chrome on the PATH.

Here is a real run of the shape an agent would issue, on Kane CLI 0.8.4, checking that a form refuses to submit when it should. The run_end line is wrapped and shortened to its main fields.

$ kane-cli run --agent --headless \
    "open the Input Form Submit page, submit the form with all fields empty,
     and assert the browser blocks submission with a validation message
     on the Name field" \
    --url https://www.testmuai.com/selenium-playground/ | tail -1

{"type":"run_end","status":"passed",
 "summary":"Tried to submit the form without entering any information. The browser
            stopped the submission and showed a validation message on the Name field,
            so the form was not submitted.",
 "final_state":{"name_field_validation_message":"true"},
 "reason":"Objective completed","duration":47,"bifurcated":false,"total_runs":1,...}

$ echo $?
0

That objective asserts a negative, which is the case agent-written unit tests miss most reliably. Nothing in the source says the browser refused to submit.

Command flags and configuration are documented in the Kane CLI introduction documentation, and setup for each coding agent, the exit codes and the how-to guides are on Kane CLI for coding agents. If your agent drives a browser through OpenCode, OpenCode Browse vs Kane CLI compares that exploratory browsing with saved release tests.

If your agent already uses MCP, the TestMu AI MCP server gives Cursor, Claude Code, GitHub Copilot, OpenAI Codex and other MCP clients tools for HyperExecute, Automation, SmartUI, Accessibility and Test Manager. Use it when the agent should start cloud runs or read their results, and use Kane CLI when it needs one command with an exit code. For the Codex side of that setup, see Codex MCP. The Cursor side is covered in Cursor MCP.

Kane CLI does not replace static analysis, dependency audits or secret scanning, and logic that never reaches a page is better covered by unit tests and mutation testing.

Note

Note: Kane CLI is free to install, and its runs, local or cloud, use plan credits; new accounts get 10,000 free credits, valid for 30 days. Claim the credits on the Kane CLI page

How to Check the Agent Is Reading the Instruction File

Do not assume a file is being read because it exists. Give the instruction a cheap observable side effect, run one small task, and check whether the side effect happened.

  • Add a line telling the agent to append a timestamp to a local file before starting any task, then run something trivial and look at the file.
  • If the file is empty, fix the path before rewording anything, because wording cannot rescue a file that is never loaded.
  • Once it loads, replace the timestamp line with the real verification contract and repeat the same one-task test.
  • Then watch compliance over a long session, because that is where instruction-following degrades and where you learn whether you need enforcement instead.

Claude Code shows part of this without a test task: run /context and check the Memory files list, then type /hooks to see each hook and the settings file it came from. In Codex, /hooks is also where you review and trust a new hook, which Codex skips until you do.

Step four is where most teams land on the honest answer. An instruction file gets you most of the way, and a lifecycle event gets you the rest.

If your agent supports that kind of enforcement, the hooks table and the wiring sections above bind a command to the moment the agent tries to finish, so the check fires whether or not the model remembers it. For a wider view of which assistants help with testing at all, see our roundup of AI code assistants for testing.

Testing from the terminal? Kane CLI by TestMu AI lets SDETs and developers plan, write, run and debug tests from the command line.

To run your first test, start free, or
for a full walkthrough of the product.

Author

...

Bhawana

Blogs: 78

  • Twitter
  • Linkedin

Bhawana is a Community Evangelist at TestMu AI with over 3 years of experience creating technically accurate, strategy-driven content in software testing. She has authored 50+ blogs on test automation, cross-browser testing, mobile testing, and real device testing. She also serves as Product Marketing Manager for Kane CLI, the command-line tool that runs browser automation from the terminal using natural-language flows in a real Chrome browser. Bhawana is certified in KaneAI, Selenium, Appium, Playwright, and Cypress, reflecting her hands-on knowledge of modern automation practices. On LinkedIn, she is followed by 6000+ QA engineers, testers, AI automation testers, and tech leaders.

Reviewer

...

Shahzeb Hoda

Reviewer

  • Linkedin

Shahzeb Hoda is the Associate Director of Marketing and a Community Contributor at TestMu AI, leading strategic initiatives in developer marketing, content, and community growth. With 10+ years of experience in quality engineering, software testing, automation testing, and e-learning, he has authored and reviewed 70+ technical articles on software testing and automation. Shahzeb holds an M.Tech in Computer Science from BIT, Mesra, and is certified in Selenium, Cypress, Playwright, Appium, and KaneAI. He brings deep expertise in CI/CD pipeline automation, cross-browser testing, AI-driven testing practices, and framework documentation. On LinkedIn, he is followed by 3,700+ engineers, developers, DevOps professionals, tech leaders, and enthusiasts.

Add to Google preferred sources

Summarise with AI

Copied to Clipboard!
...

3000+ Browsers. One Platform.

See exactly how your site performs everywhere.

Try it free
...

Write Tests in Plain English with KaneAI

Create, debug, and evolve tests using natural language.

Try for free

AI Coding Tool Testing FAQs

Did you find this page helpful?

TestMu AI forEnterprise

Get access to solutions built on Enterprise
grade security, privacy, & compliance

  • Advanced access controls
  • Advanced data retention rules
  • Advanced Local Testing
  • Premium Support options
  • Early access to beta features
  • Private Slack Channel
  • Unlimited Manual Accessibility DevTools Tests