n1-scan

n1-scan is a command for Claude Code from sigistry/marketplace. It costs 18 tokens per session (648 once invoked), scanned A, original, MIT.

A static code scanner that looks for N+1 query patterns in ORM and data-access code. N+1 queries happen when code makes one database query for a list and then an extra query for each item.

In plain words
What is it for?
Use it to inspect Django, SQLAlchemy, Rails, Sequelize, Prisma, TypeORM, Hibernate, GORM, or Entity Framework code and suggest eager-loading fixes.
Why use it?
It helps find slow database access without requiring a database connection or query logs.

Command for Claude Code

Written for Claude Code: argument-hint in frontmatter. Also seen: model in frontmatter.

Part of the sql-safety-net plugin — 3 skills, 5 commands, 2 agents shipped together

Good fit Use it to inspect Django, SQLAlchemy, Rails, Sequelize, Prisma, TypeORM, Hibernate, GORM, or Entity Framework code and suggest eager-loading fixes.

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/sigistry/marketplace/n1-scan
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/sigistry/marketplace

Made for: Claude Code.

Or install sql-safety-net, the plugin that ships this one along with the rest of its 3 skills, 5 commands, 2 agents.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for n1-scan

README.md
[![agentmods](https://agentmods.dev/badge/commands/sigistry/marketplace/n1-scan/github.svg)](https://agentmods.dev/commands/sigistry/marketplace/n1-scan)
Your own site
<a href="https://agentmods.dev/commands/sigistry/marketplace/n1-scan"><img src="https://agentmods.dev/badge/commands/sigistry/marketplace/n1-scan/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for n1-scan

Your own site · 80×15
<a href="https://agentmods.dev/commands/sigistry/marketplace/n1-scan"><img src="https://agentmods.dev/badge/commands/sigistry/marketplace/n1-scan.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 18 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 648 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00018 $0.00648
Opus 5 $0.00009 $0.00324
Sonnet 5 $0.00004 $0.00130
Haiku 4.5 $0.00002 $0.00065

Measured 6d ago against content hash 04bc71d1b9bd, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, from the pricing page.

Security

Grade A, and why

n1-scan scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/sql-safety-net/commands/n1-scan.md · 39 lines

How it starts

The opening of the file, as written. The whole thing — 39 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Scan the ORM / data-access code at $ARGUMENTS (default: the current diff or the app's models/services directories) for N+1 query patterns, and report each with an idiomatic fix. This is a static scan of source code, no database connection or query log required. It dispatches the n1-hunter agent, which reads the schema-antipatterns skill's ORM N+1 catalog.

Process

Step 1: Detect the ORM

Identify the data-access layer from manifests and imports:

ORM Signal
Django ORM models.py, objects.filter, .all(), settings.py
SQLAlchemy sqlalchemy, session.query, relationship(
Rails ActiveRecord app/models/, has_many, .where
Sequelize sequelize, Model.findAll, hasMany
Prisma prisma/schema.prisma, prisma.*.findMany
TypeORM @Entity, getRepository, @OneToMany
Hibernate/JPA @Entity, @OneToMany(fetch=LAZY), EntityManager
GORM (Go) gorm.io, db.Find, Preload
Entity Framework DbContext, DbSet<, .Include(

Step 2: Dispatch the n1-hunter agent

Launch the n1-hunter agent with the target path. It looks for the classic shape: a query that returns a collection, followed by a loop (or a serializer/to_json/template) that accesses a lazy-loaded relation per element, triggering one query per row. It also flags missing select_related/prefetch_related/joinedload/includes/with/Include()/Preload on queries whose results are iterated with relation access.

Step 3: Report

Relay the agent's findings as:

  • ## N+1 Findings: a table: file:line | ORM | Pattern | Fix. Each row names the loop and the relation being lazily loaded, and gives the exact eager-load call for that ORM.
  • ## Severity Note: which findings are in hot paths (request handlers, list endpoints, serializers) vs cold paths (one-off scripts).

Important Notes

  • Report only patterns backed by real code, cite the exact file:line of the query and the loop.
  • A static scan yields suspected N+1s; note where confirmation needs the runtime query count (the fix is still correct).
  • Never fabricate line numbers or relations; if the relation's laziness cannot be confirmed from the code, say so.
  • Prefer the idiomatic batch/eager fix for the detected ORM over a hand-rolled IN (...) unless the ORM lacks one.

Read the full file on GitHub · 39 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 39 lines · 18 tokens per session scan A 04bc71d1b9bd

Subscribe to this mod's changes

n1-scan is a command published in the GitHub repository sigistry/marketplace (3 stars, last pushed 5d ago), licensed MIT. It adds 18 tokens to every session and 648 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.