AI Guard

Scans JavaScript and TypeScript for bugs common in AI-written code and returns the findings to the agent. It also checks a change for weakened tests and verifies npm packages before they are installed.

Documentation

v1.4.7Package checks, Cursor and Codex hooks

Guardrails for AI-written JavaScript and TypeScript

AI Guard is an ESLint plugin, CLI and set of agent hooks that catch the risky patterns AI coding tools often produce, such as swallowed errors, leaked secrets and packages that don't exist, before they reach a commit.

$ npm install --save-dev eslint-plugin-ai-guard

Measured on 12 November 2026. Method and limits

What it does

Checks at every point an agent's code passes through.

Every check is deterministic: the same code gives the same result, with no model in the loop. AI Guard does not try to tell whether code was written by a person or a model; it reports patterns wherever they came from.

  • Lint rules

    27 rules for secrets, swallowed errors, floating promises, invented imports and placeholder code, in ESLint or a zero-config CLI. npx ai-guard run Rule catalog
  • Checks on the agent's change

    One verdict for a change, plus checks for skipped tests, new eslint-disable comments and hidden text in agent config. Problems that were already there never block. npx ai-guard verify Verify and integrity
  • Package checks

    Blocks packages that don’t exist on npm, removed malware and suspicious look-alikes before they are installed. Warns on releases from the last 24 hours. npx ai-guard verify-deps --all What is blocked
  • Agent hooks

    Feedback after each edit and a check before the agent finishes, in Claude Code, Codex and Cursor, set up with one command. npx ai-guard init-hooks Hooks by agent
  • Pre-commit gate

    Runs on every commit, whoever wrote the code, through husky, lefthook, simple-git-hooks or pre-commit. Only problems the commit introduces block it. npx ai-guard init-git-hook Pre-commit setup
  • CI and Code Scanning

    The GitHub Action annotates pull requests and writes a job summary and a SARIF file for GitHub Code Scanning. uses: ai-guard-dev/eslint-plugin-ai-guard@v1 Workflow

Package checks

A package is checked before it is installed.

Assistants suggest packages that don't exist, and attackers register those names. AI Guard looks each package up on npm and blocks only on facts: the name or version doesn't exist, npm replaced it with a security placeholder, or a look-alike or install script appears on a new or rarely downloaded package.

  • Network use is opt-in and only queries the public npm registry.
  • Packages from private registries are skipped, so internal names are never sent out. Blocked versus warned
$ npx ai-guard verify-deps crossenv   AI GUARD   Dependencies  ·  1 package  ·  1 blocked  ·  0 warnings   command lineerror  crossenv  npm removed the package published as "crossenv" (usually for malware) and replaced it with an empty placeholder. Did you mean "cross-env"? security-holding

Output copied from the CLI on 13 November 2026, with colour removed and long lines wrapped. The command exits with code 1, a blocking finding. crossenv was part of the August 2017 typosquatting campaign that imitated cross-env; npm replaced it with an empty security placeholder.

Agent hooks

Claude Code, Codex and Cursor from one command.

npx ai-guard init-hooks detects the agents a project uses from .claude/, .cursor/ and .codex/. What each agent gets depends on what its hook system allows.

Set up hooks

Claude CodeCodexCursor
Lint and weakened checks fed back after each editYesYes (apply_patch)At the finish gate instead
Finish gate: problems the session introduced, raised onceYesYesYes (follow-up message)
Session-start snapshot, so earlier work is not blamed on the agentYesYesYes
Guard on git commit --no-verify and HUSKY=0Asks youDenied; the agent is told to ask youAsks you
Package check before installs (opt-in)Deny or askDenyDeny or ask

Tested: Run against real installs in Claude Code and the Codex CLI. Cursor support follows Cursor’s documented hook format and has not been tested in the editor.

Frequently asked questions

What is eslint-plugin-ai-guard?

It is the npm package for AI Guard: an open-source ESLint plugin, CLI and set of agent hooks that catches risky patterns AI coding tools often produce in JavaScript and TypeScript and checks npm packages before they are installed. It is MIT licensed and runs locally.

Does AI Guard detect AI-written code?

No. It reports risky patterns that AI tools often produce, such as swallowed errors, leaked secrets, placeholder code and packages that don’t exist, wherever the code came from.

Does it replace ESLint or my existing config?

No. It is an ESLint plugin: you add its rules to your existing config. The ai-guard CLI can also run the same rules without your config. See AI Guard and ESLint.

Which AI coding agents does it work with?

npx ai-guard init-hooks sets up hooks for Claude Code, Codex and Cursor. Claude Code and the Codex CLI were tested against real installs; Cursor support follows Cursor’s documented hook format and has not been tested in the editor. Any MCP client can use the MCP server.

Does it send my code anywhere?

No. Lint and the checks on a change run locally with no network access and no telemetry. Only the package checks use the network, to query the public npm registry, and only when you run them.

Install

Try it on your project.

The CLI uses its own configuration, so you can see findings before you change your ESLint setup or CI.

  • Node.js 20 or later
  • ESLint 8 or later, flat config or legacy config
  • Optional: @typescript-eslint/parser for TypeScript
  • Current version: 1.4.7 Getting started guide
$ npm install --save-dev eslint-plugin-ai-guard

Then run

# Zero-config scan of the whole project$ npx ai-guard run # Hooks for Claude Code, Cursor and Codex$ npx ai-guard init-hooks # Check every dependency on npm$ npx ai-guard verify-deps --all

Open source

MIT licensed, developed in public.

The rules, CLI, GitHub Action, MCP server, and Claude Code plugin are all in one repository. Every rule has tests and a documentation page you can check a finding against.

npm downloads, all time

12,922

Last 30 days

3,727

Last verified count; live figures load from the npm downloads API. Downloads include CI installs and are not a count of users.

AI Guard and Sarvam AI Startup Program

Ecosystem

AI Guard × Sarvam AI Startup Program

AI Guard was selected for the Sarvam AI Startup Program, supporting continued work on deterministic guardrails for AI-assisted software engineering.

Collaborate

Build AI Guard with us.

AI Guard is open source, and we're open to working with developers, security researchers, and teams building with AI coding tools.

Interested in contributing a rule, testing AI Guard on your codebase, exploring integrations, or discussing a partnership? We'd love to hear from you.

Have any queries? Email us directly at [email protected]

Collaboration AreasOpen Source & Community

Rule Contributions

Author or refine AST detection rules for your stack.

Codebase Testing

Run differential benchmarks on real-world AI-assisted code.

Agent Integrations

Help bridge AST rules with Cursor, Claude Code, and Copilot.

Security Research

Share insights on recurring AI vulnerability patterns.

Have any queries? Email [email protected]