middleware-create

middleware-create is a command for Claude Code from smicolon/ai-kit. It costs 11 tokens per session (1,373 once invoked), scanned A, original, MIT.

A command for creating custom Hono middleware, code that runs before or after route handlers.

In plain words
What is it for?
Use it to add request logging, JWT authentication, response handling, and typed values shared with handlers.
Why use it?
It gives cross-cutting behavior such as logging or authentication one reusable place instead of duplicating it across routes.

Command for Claude Code

Written for Claude Code: a Claude Code command (commands/*.md).

Needs its repository: it reads a path above its own folder, which exists only inside the repository. The line is import type { Env } from '../types/bindings'.

Good fit Use it to add request logging, JWT authentication, response handling, and typed values shared with handlers.

Compare 6 commands from other repositories ↓
Install

Getting it into your agent

It runs from inside its repository, so the clone comes first — what it calls does not travel with the file alone.

Clone the repo
git clone --depth 1 https://github.com/smicolon/ai-kit
agentmods
npx agentmods add commands/smicolon/ai-kit/middleware-create

Made for: Claude Code.

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 middleware-create

README.md
[![agentmods](https://agentmods.dev/badge/commands/smicolon/ai-kit/middleware-create/github.svg)](https://agentmods.dev/commands/smicolon/ai-kit/middleware-create)
Your own site
<a href="https://agentmods.dev/commands/smicolon/ai-kit/middleware-create"><img src="https://agentmods.dev/badge/commands/smicolon/ai-kit/middleware-create/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 middleware-create

Your own site · 80×15
<a href="https://agentmods.dev/commands/smicolon/ai-kit/middleware-create"><img src="https://agentmods.dev/badge/commands/smicolon/ai-kit/middleware-create.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 11 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,373 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.00011 $0.01373
Opus 5 $0.00005 $0.00687
Sonnet 5 $0.00002 $0.00275
Haiku 4.5 $0.00001 $0.00137

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

Security

Grade A, and why

middleware-create 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.

packs/hono/commands/middleware-create.md · 224 lines

How it starts

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

Create Hono Middleware

Create a new custom middleware following Hono best practices.

Workflow

Step 1: Gather Requirements

Ask the user:

  1. Middleware name (e.g., "auth", "rateLimit", "logger")
  2. Purpose - What should this middleware do?
  3. Configuration options - Any parameters needed?
  4. Variables to set - What data to pass to handlers?
  5. When to apply - Which routes need this?

Middleware Patterns

Basic Middleware

// middleware/{name}.ts
import { createMiddleware } from 'hono/factory'
import type { Env } from '../types/bindings'

export const {name}Middleware = createMiddleware<Env>(async (c, next) => {
  // Pre-handler logic
  console.log(`[${c.req.method}] ${c.req.url}`)

  await next()

  // Post-handler logic (runs after handler)
  console.log(`Response status: ${c.res.status}`)
})

Middleware with Variables

// middleware/auth.ts
import { createMiddleware } from 'hono/factory'
import { HTTPException } from 'hono/http-exception'
import { verify } from 'hono/jwt'
import type { Env } from '../types/bindings'

// First, update types/bindings.ts to include the variable:
// Variables: {
//   user: { id: string; email: string; role: string }
// }

export const authMiddleware = createMiddleware<Env>(async (c, next) => {
  const authHeader = c.req.header('Authorization')

  if (!authHeader?.startsWith('Bearer ')) {
    throw new HTTPException(401, { message: 'Missing authorization token' })
  }

  const token = authHeader.slice(7)

  try {
    const payload = await verify(token, c.env.JWT_SECRET)

    // Set variable for downstream handlers
    c.set('user', {
      id: payload.sub as string,
      email: payload.email as string,
      role: payload.role as string
    })

    await next()
  } catch {
    throw new HTTPException(401, { message: 'Invalid or expired token' })
  }
})

Configurable Middleware Factory

// middleware/rateLimit.ts
import { createMiddleware } from 'hono/factory'
import { HTTPException } from 'hono/http-exception'
import type { Env } from '../types/bindings'

interface RateLimitOptions {
  windowMs: number  // Time window in milliseconds
  max: number       // Max requests per window
  keyGenerator?: (c: Context) => string
}

export const rateLimit = (options: RateLimitOptions) => {
  const { windowMs, max, keyGenerator } = options

  return createMiddleware<Env>(async (c, next) => {
    const key = keyGenerator
      ? keyGenerator(c)
      : c.req.header('CF-Connecting-IP') || 'unknown'

    const cacheKey = `ratelimit:${key}`
    const kv = c.env.KV

    const current = parseInt(await kv.get(cacheKey) || '0')

    if (current >= max) {
      throw new HTTPException(429, {
        message: 'Too many requests, please try again later'
      })
    }

    await kv.put(cacheKey, String(current + 1), {
      expirationTtl: Math.ceil(windowMs / 1000)
    })

    // Add rate limit headers
    c.header('X-RateLimit-Limit', String(max))
    c.header('X-RateLimit-Remaining', String(max - current - 1))

    await next()
  })
}

// Usage:
// app.use('/api/*', rateLimit({ windowMs: 60000, max: 100 }))

Read the full file on GitHub · 224 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 · 224 lines · 11 tokens per session scan A 042dce3fbe11

Subscribe to this mod's changes

middleware-create is a command published in the GitHub repository smicolon/ai-kit (6 stars, last pushed 6d ago), licensed MIT. It adds 11 tokens to every session and 1,373 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.