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.
git clone --depth 1 https://github.com/smicolon/ai-kitnpx agentmods add commands/smicolon/ai-kit/middleware-createWrote 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.
[](https://agentmods.dev/commands/smicolon/ai-kit/middleware-create)<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.
<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>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.
| Model | Per session | Once 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 |
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.
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:
- Middleware name (e.g., "auth", "rateLimit", "logger")
- Purpose - What should this middleware do?
- Configuration options - Any parameters needed?
- Variables to set - What data to pass to handlers?
- 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 }))
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.
- 6d ago First seen · 224 lines · 11 tokens per session scan A 042dce3fbe11
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.
Other commands, from other repositories
ctx:design
Design system architecture, APIs, and component interfaces with structured workflow.
flow-nexus-workflow
Event-driven workflow automation with message queues.
architect
System design with Memory-based coordination for scalable architectures.
coder
Autonomous code generation with batch file operations.
checklist
Generate a custom checklist for the current feature based on user requirements.
clarify
Identify underspecified areas in the current feature spec by asking up to 5 highly targeted clarification questions and encoding answers back into the spec.