Bug

Called a method that doesn't exist

调用了不存在的方法

The agent uses a method, option, config key or CLI flag that exists in some other language or library version, but not in yours.

Applies to: Claude Code · Cursor · Codex · Copilot agent

Symptom

`haystack.contains(needle)` in JavaScript, a config key the framework silently ignores, or a CLI flag that errors at runtime.

Why it happens

Agents conflate APIs across languages and versions; the signature looks plausible because some language has it. Config keys are worse, because unknown keys are often ignored without an error. agent-review lists this as AR006; developertoolkit.ai puts its earliest control in the session (type check and tests in the agent's own loop).

Example

From the agent-review taxonomy (AR006).

js
if (haystack.contains(needle)) { ... } // should be .includes

Copy-paste fixes

Pick the files for the agents you use. Snippets are in English so they work in any repo.

Rules

Claude Code: add to CLAUDE.md

CLAUDE.md
## Check the API against the installed version
- Before using an unfamiliar method, option, config key or flag, confirm it in the installed
  version: read the type definitions in node_modules / site-packages, run `<cli> --help`, or open the
  docs for the exact version in the lockfile.
- Run the type checker and tests after every edit, not only at the end.
- When you change config, show evidence the setting took effect (log line, output, behavior).
Rules

Codex, Copilot coding agent and others: add to AGENTS.md

AGENTS.md
## Check the API against the installed version
- Before using an unfamiliar method, option, config key or flag, confirm it in the installed
  version: read the type definitions in node_modules / site-packages, run `<cli> --help`, or open the
  docs for the exact version in the lockfile.
- Run the type checker and tests after every edit, not only at the end.
- When you change config, show evidence the setting took effect (log line, output, behavior).
Cursor rule

Cursor: project rule

.cursor/rules/hallucinated-api-method.mdc
---
description: "AgentFails: Called a method that doesn't exist"
alwaysApply: true
---

## Check the API against the installed version
- Before using an unfamiliar method, option, config key or flag, confirm it in the installed
  version: read the type definitions in node_modules / site-packages, run `<cli> --help`, or open the
  docs for the exact version in the lockfile.
- Run the type checker and tests after every edit, not only at the end.
- When you change config, show evidence the setting took effect (log line, output, behavior).
Hook

Claude Code PostToolUse hook: type-check after every edit

Exit code 2 from a PostToolUse hook shows stderr to Claude so it can fix the error right away. Replace tsc with mypy, cargo check, go vet, etc.

.claude/settings.json
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write|MultiEdit",
        "hooks": [
          { "type": "command", "command": "npx tsc --noEmit -p . 1>&2 || exit 2" }
        ]
      }
    ]
  }
}

Sources and credit

Related patterns

翻车 of the week

One real agent failure and its fix, every week. Free, short, no spam.