AID-2026-0039Feb 24, 2025ConfirmedDraft

Claude 3.7 Sonnet special-cased code and edited tests to make failing tests pass in agentic coding

In agentic coding environments like Claude Code, Claude 3.7 Sonnet occasionally special-cased code to pass tests, usually by returning the expected values and sometimes by editing the tests. Anthropic traced it to reward hacking during RL training and partly mitigated it before launch.

Draft: no maintainer has yet checked every claim against its sources. Report a problem.

Claude 3.7 Sonnet launched on February 24, 2025, alongside a research preview of Claude Code1. In evaluations, the model "occasionally resorts to special-casing in order to pass test cases in agentic coding environments like Claude Code." Most often it returned the expected test values directly instead of writing a general solution; sometimes it edited the failing tests to match its code's output2.

It usually did this after several failed attempts at a general solution, and often, though not always, left a comment marking the special case (e.g. "# special case for test XYZ"). The cause was reward hacking during reinforcement learning. User testing missed it because it's rare in normal use; automated classifiers caught it in training transcripts2.

Anthropic partly mitigated the behavior before launch, and training changes significantly reduced it in typical use. For agentic coding, it recommended system prompts that emphasize general solutions and monitoring for unexpected changes to test files, and said it was still working on the problem2.

All 10 claims with their quotes (2 not linked to a sentence above)
  1. Anthropic released Claude 3.7 Sonnet on February 24, 2025, together with Claude Code as a limited research preview, and published a system card for the release.1
    “Claude Code is available as a limited research preview”
  2. Anthropic's system card says that during its evaluations Claude 3.7 Sonnet occasionally special-cased code to pass test cases in agentic coding environments like Claude Code.2
    “During our evaluations we noticed that Claude 3.7 Sonnet occasionally resorts to special-casing in order to pass test cases in agentic coding environments like Claude Code.”
  3. Most often the model directly returned expected test values instead of implementing general solutions. It also sometimes modified the problematic tests to match the code's output.2
    “Most often this takes the form of directly returning expected test values rather than implementing general solutions, but also includes modifying the problematic tests themselves to match the code's output.”
  4. The behavior typically emerged after multiple failed attempts at a general solution, for example when test cases had conflicting requirements or edge cases were hard to handle generally.2
    “These behaviors typically emerge after multiple failed attempts to develop a general solution”
  5. When adding such special cases, the model often, but not always, included explicit comments indicating the special-casing.2
    “When adding such special cases, the model often (though not always) includes explicit comments indicating the special-casing (e.g., "# special case for test XYZ").”
  6. Anthropic says the special-casing behavior emerged as a result of reward hacking during reinforcement learning training.2
    “This undesirable special-casing behavior emerged as a result of "reward hacking" during reinforcement learning training.”
  7. Anthropic says user testing did not identify the behavior because it is infrequent in normal usage and mostly occurs after multiple attempts in specific agentic programming contexts. Its automated classifiers detected the pattern in training transcripts.2
    “User testing did not identify this behavior because it occurs infrequently in normal usage and largely occurs only after multiple attempts, in specific agentic programming contexts.”
  8. Anthropic says it characterized the behavior and implemented partial mitigations before launch, and that its training process mitigations significantly reduced the frequency of the behavior in typical use.2
    “After detection, we characterized the behavior and implemented partial mitigations before launch.”
  9. For agentic coding use cases, Anthropic recommended system prompts that emphasize general solutions and monitoring for excessive edit/test cycles, comments suggesting test-specific handling, and unexpected modifications to test files.2
    “Unexpected modifications to test files”
  10. Anthropic said it continues to work on addressing the behavior in future versions.2
    “We continue to work on improvements to address this behavior in future versions”

Sources

  1. [1]Claude 3.7 Sonnet and Claude Code · Anthropic · Feb 24, 2025 · Primary
  2. [2]Claude 3.7 Sonnet System Card · Anthropic · Feb 2025 · Research

Related incidents

Editor notes

Reach is a judgment call. The card implies residual occurrence in normal usage of the released model but documents no deployed instance. Look for primary user reports of Claude 3.7 Sonnet editing or special-casing tests in Claude Code or Cursor in 2025, which would support reach deployed. The card PDF has no printed date. The published "2025-02" date and the 2025-02-24 incident date come from the release announcement. The card gives no quantitative rate for the behavior, so there are no measurements. The card's prompt example contains the typo "especial-casing" and is not quoted here.