n+1

n+1 is a command for coding agents from fridzema/clockwork-mcp. It costs 9 tokens per session (565 once invoked), scanned A, original, MIT.

A command that looks for N+1 query patterns in recorded web requests. An N+1 problem occurs 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 the latest request, several recent requests, a time range, all stored requests, or a particular URL for N+1 database queries.
Why use it?
This pattern can make an otherwise simple page or API endpoint perform many unnecessary database queries. The command identifies repeated queries and suggests loading related data in advance.

Command

Part of the clockwork plugin — 4 commands, 1 MCP server shipped together

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.

agentmods
npx agentmods add commands/fridzema/clockwork-mcp/n-1
Clone the repo
git clone --depth 1 https://github.com/fridzema/clockwork-mcp

Or install clockwork, the plugin that ships this one along with the rest of its 4 commands, 1 MCP server.

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 n+1

README.md
[![agentmods](https://agentmods.dev/badge/commands/fridzema/clockwork-mcp/n-1.svg)](https://agentmods.dev/commands/fridzema/clockwork-mcp/n-1)
Your own site
<a href="https://agentmods.dev/commands/fridzema/clockwork-mcp/n-1"><img src="https://agentmods.dev/badge/commands/fridzema/clockwork-mcp/n-1.svg" alt="Measured on agentmods" height="20"></a>
Per session 9 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 565 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00009 $0.00565
Opus 5 $0.00005 $0.00282
Sonnet 5 $0.00002 $0.00113
Haiku 4.5 $0.00001 $0.00056

Measured 5d ago against content hash 69d4246b0a39, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

n+1 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 5d 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.

commands/n+1.md · 85 lines

What it actually says

Use the detect_n_plus_one MCP tool to find N+1 query patterns.

Scope Options

By default, analyzes only the latest request. Use these options to analyze multiple requests:

  • count: Number of recent HTTP requests (e.g., count: 10)
  • since: Time duration to look back (e.g., since: "1h", since: "30m", since: "2d")
  • all: Analyze all available requests (max 100)
  • uri: Filter by URI pattern (e.g., uri: "/api/users")
  • requestId: Analyze specific request by ID

Examples:

  • Latest request only: detect_n_plus_one (no scope params)
  • Last 10 requests: detect_n_plus_one with count: 10
  • Last hour: detect_n_plus_one with since: "1h"
  • Specific endpoint: detect_n_plus_one with count: 20, uri: "/api/orders"

Output Format

For single request:

N+1 Query Detection

Found N potential N+1 patterns in request [METHOD] /uri/path

Pattern 1: X occurrences

SELECT * FROM table WHERE id = ?

Fix: Use eager loading with ->with('relation') or ->load('relation')

For multiple requests:

N+1 Query Detection - Last N Requests

Analyzed N requests, found M patterns in K requests

Pattern 1: X total occurrences (avg Y/request)

SELECT * FROM posts WHERE user_id = ?

Affected requests:

  • GET /api/users (15 occurrences)
  • GET /api/dashboard (8 occurrences)
  • GET /api/profile (5 occurrences)

Fix: User::with('posts')

Pattern 2: Y total occurrences

SELECT * FROM comments WHERE post_id = ?

Affected requests:

  • GET /api/posts (22 occurrences)

Fix: Post::with('comments')

How to Fix N+1 Queries

In your controller or query:

// Before (N+1)
$users = User::all();
foreach ($users as $user) {
    echo $user->posts; // Triggers query for each user
}

// After (eager loaded)
$users = User::with('posts')->get();
foreach ($users as $user) {
    echo $user->posts; // No additional queries
}

If no N+1 patterns are found:

N+1 Query Detection

No N+1 patterns detected.

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. 5d ago First seen · 85 lines · 9 tokens per session scan A 69d4246b0a39

Subscribe to this mod's changes

n+1 is a command published in the GitHub repository fridzema/clockwork-mcp (4 stars, last pushed 7mo ago), licensed MIT. It adds 9 tokens to every session and 565 once invoked, about $0.0000 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-08-31.