Skip to main content
plugin

protect-tests — Claude Code plugin: prevent test disabling

protect-tests blocks the "fake green" trap: stops the agent from deleting, renaming, or skipping tests instead of fixing the code. Works with pytest, jest, Go, JUnit, RSpec, and more.

MIT ★ 586 updated 2026-10-26

Install into Claude Code · Plugin marketplace All methods and platforms ↓
/plugin marketplace add karanb192/claude-code-hooks
/plugin install protect-tests@claude-code-hooks
Open on GitHub

What protect-tests does

A hook intercepts every Bash, Edit, MultiEdit, and Write call before execution. When the agent tries to delete a test file or directory (via rm or git rm), rename a test to a disabled name (.bak, .disabled, .skip), add a skip/xfail marker to an existing test, or write a new test file that is already skipped, the hook rejects it with "Fix the code, don't disable the test." Test patterns and skip markers are recognized across pytest, unittest, jest, mocha, vitest, Go, JUnit, TestNG, NUnit, MSTest, RSpec, and Rust.

Configure the safety level via HOOK_SAFETY_LEVEL: critical blocks only deletion, high (default) adds renaming and skip-marker blocks, and strict also prevents writing pre-skipped test files. The hook never interferes with writing new real tests, renaming tests to other test names, or editing test bodies. Blocked attempts are logged to ~/.claude/hooks-logs/YYYY-MM-DD.jsonl without command content.

What it helps with

  • prevent the agent from deleting test files to hide failures
  • stop renaming tests to disabled names like .bak or .skip
  • block adding skip and xfail markers to passing tests
  • reject pre-skipped test files written to bypass failures

Example prompts for the agent

  • Install the plugin and Claude Code will refuse to delete or disable tests
  • Adjust safety with HOOK_SAFETY_LEVEL=strict for strictest enforcement
  • Review logs in ~/.claude/hooks-logs when the agent hits a block

How to install protect-tests

Plugin marketplace

/plugin marketplace add karanb192/claude-code-hooks
/plugin install protect-tests@claude-code-hooks

Step by step, with commands for each platform: Claude Code plugins: marketplaces, installing, and building your own

Questions about protect-tests

How do I install protect-tests in Claude Code?

Run /plugin marketplace add karanb192/claude-code-hooks, then /plugin install protect-tests@claude-code-hooks. Restart Claude Code.

What does protect-tests do?

It prevents the agent from making tests pass by deleting files, renaming tests to disabled names, or adding skip/xfail markers. It forces the agent to fix the code instead.

Which test frameworks does it support?

pytest, unittest, jest, mocha, vitest, Go, JUnit, TestNG, NUnit, MSTest, RSpec, and Rust. The hook detects tests by file patterns and structure.

Source text

protect-tests · MIT
# protect-tests

> Stops "fake green": blocks an agent from making a suite pass by deleting, renaming-away, or skip-disabling tests instead of fixing the code.

A `PreToolUse` hook fires before every `Bash`, `Edit`, `MultiEdit`, and `Write` call and denies the ones that remove or disable tests: `rm` / `git rm` of a test file or test directory, `mv` of a test file to a disabled name (`.bak`, `.disabled`, ...), an edit that introduces a skip/xfail/ignore marker into an existing test, and (at the `strict` level) writing a brand-new test file that is already skipped. Test paths and skip markers are matched across pytest, unittest, jest/mocha/vitest, Go, JUnit/TestNG, NUnit/MSTest, RSpec, and Rust. It does NOT block writing new, real tests, refactor-renaming a test to another test name, or editing test bodies: only removal and disabling.

## Install

```
/plugin marketplace add karanb192/claude-code-hooks   # once per machine
/plugin install protect-tests@claude-code-hooks
```

Restart Claude Code, done. (Or from a shell: `claude plugin install protect-tests@claude-code-hooks`.)

## What it does

| Tool | Blocked when | Level | Deny id |
|------|--------------|-------|---------|
| `Bash` | `rm` / `unlink` / `shred` / `trash` / `git rm` targets a test file or test directory | `critical` | `delete-test` |
| `Bash` | `mv` renames a test file to a disabled name (`.bak`, `.old`, `.orig`, `.disabled`, `.skip`, `.ignore`, `.tmp`, `~`) | `high` | `rename-test` |
| `Edit` / `MultiEdit` | the edit adds a skip/xfail/ignore marker to an existing test file | `high` | `skip-test` |
| `Write` | the new test file's content is already skipped/ignored | `strict` | `write-skipped-test` |

Anything at or below the active safety level is denied with a reason Claude sees ("Fix the code, don't disable the test"); everything else passes through. On malformed input the hook fails open (emits `{}`), so it can never wedge a session.

## Safety levels

| Level | Blocks |
|-------|--------|
| `critical` | deleting test files or whole test directories (rm / git rm) |
| `high` (default) | + renaming a test file to a disabled name, + adding a skip/xfail/ignore marker to an existing test |
| `strict` | + writing a whole test file that is already skipped |

## Configuration

One optional environment variable:

| Variable | Default | Purpose |
|----------|---------|---------|
| `HOOK_SAFETY_LEVEL` | `high` | Safety level: `critical`, `high`, or `strict`. Any other value falls back to `high`. Set it via env (shell profile, or inline in a hook command), not by editing the installed script: plugin updates overwrite plugin files. |

## How it registers

`hooks/hooks.json` registers one `PreToolUse` hook with matcher `Bash|Edit|MultiEdit|Write`, running synchronously (a deny decision has to land before the tool executes).

## Data & privacy

Blocked calls and parse errors are logged as JSONL to `~/.claude/hooks-logs/YYYY-MM-DD.jsonl` (deny id, level, tool name, session id, cwd, permission mode; no commands or file contents, though a parse error's message can quote the first few characters of a malformed payload). The script only uses `fs` and `path`, so nothing leaves your machine.

## Uninstall

```
/plugin uninstall protect-tests@claude-code-hooks
```

Part of [claude-code-hooks](https://github.com/karanb192/claude-code-hooks), a marketplace of production-ready Claude Code hooks.

© Karan Bansal · MIT · karanb192/claude-code-hooks

Similar plugins

All plugins for Testing and QA →

From the same set28

The whole set →
config-watch config-watch makes every mid-session change to settings or skills visible in the session, or blocks it outright. Aimed at installers and npm scripts that rewrite config while the agent works. ★ 586repo stars subagent-spawn-cap subagent-spawn-cap counts subagent spawns per session: asks at 20, asks again every 10, refuses at 60. Puts back the cap Claude dropped in 2.1.224. ★ 586repo stars config-guard config-guard — a PreToolUse hook that stops the agent from rewriting the files holding its own guardrails: settings, hook scripts, plugin manifests. Reads pass. ★ 586repo stars case-insensitive-guard case-insensitive-guard is a Claude Code plugin that blocks destructive Bash commands aimed at a path with a different letter case. It checks commands such as rm -rf before they run. ★ 586repo stars git-safety git-safety — a PreToolUse Bash hook for Claude Code that intercepts destructive git and gh CLI actions before execution. ★ 586repo stars protect-secrets protect-secrets — a PreToolUse hook that checks every Read, Edit, Write, Bash and Grep call and blocks .env, SSH keys or cloud credentials — or asks you first. ★ 586repo stars bounty-board bounty-board turns TODO and FIXME comments into bounties that grow in XP value as they age. Scans your repo, prices each debt marker by git-blame age, and feeds the top 3 into your session as side quests. ★ 586repo stars dead-end-registry dead-end-registry stores reverted code changes and alerts you before retrying failed ideas. Keeps track of discarded approaches and detour token costs per repository. ★ 586repo stars

Project sponsors

Companies that keep this analytics open