add-middleware
Use when writing or debugging ra middleware hooks.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Use when writing or debugging ra middleware hooks.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
System design and architecture decisions. Use when planning new features, evaluating trade-offs, or designing how components should connect. Proposes 2-3 approaches and recommends one.
Smart commit workflow. Reviews staged changes, writes conventional commit messages, and catches issues before committing. Use when ready to commit work.
Quality review of completed work. Use after making changes and before claiming completion. Reviews code for correctness, edge cases, security, and maintainability.
Systematic debugging workflow. Use when diagnosing bugs, test failures, or unexpected behavior. Follows a rigorous reproduce → isolate → hypothesize → fix → verify cycle.
Systematic multi-agent research. Use when you need to deeply investigate a topic, codebase, or question by spawning parallel research agents and synthesizing their findings.
Deep code explanation. Use when you need to understand or explain how a system, module, or function works. Traces data flow, maps dependencies, and explains design decisions.
| name | add-middleware |
| description | Use when writing or debugging ra middleware hooks. |
See src/middleware/CLAUDE.md for loading mechanics and src/agent/types.ts for all context shapes.
| Hook | Context | When | Can Mutate |
|---|---|---|---|
beforeLoopBegin | LoopContext | Once at start | messages |
beforeModelCall | ModelCallContext | Before each LLM call | request.messages, request.tools |
onStreamChunk | StreamChunkContext | Per streaming chunk | — |
afterModelResponse | ModelCallContext | After model finishes | — |
beforeToolExecution | ToolExecutionContext | Before each tool runs | can stop() |
afterToolExecution | ToolResultContext | After each tool returns | — |
afterLoopIteration | LoopContext | After each iteration | — |
afterLoopComplete | LoopContext | After final iteration | — |
onError | ErrorContext | On exceptions | — |
Every context has stop() and signal (AbortSignal). Call stop() to halt the loop.
Export a default async function:
// middleware/my-hook.ts
import type { ModelCallContext } from '../src/agent/types'
export default async (ctx: ModelCallContext) => {
// ctx.request, ctx.loop, ctx.stop(), ctx.signal
}
middleware:
beforeModelCall:
- "./middleware/my-hook.ts" # file path
- "(ctx) => { console.log('hey') }" # inline expression
Token budget (afterModelResponse):
export default async (ctx) => {
if (ctx.loop.usage.inputTokens > 100000) ctx.stop()
}
Tool filtering (beforeModelCall):
export default async (ctx) => {
if (ctx.loop.iteration > 5)
ctx.request.tools = ctx.request.tools?.filter(t => t.name !== 'WebFetch')
}
Guardrail (beforeToolExecution):
export default async (ctx) => {
if (ctx.toolCall.name === 'Bash' && ctx.toolCall.arguments.includes('rm -rf'))
ctx.stop()
}
beforeModelCall can mutate ctx.request — this is how you modify what the model seesbeforeModelCall middleware, injected first automaticallytoolTimeout just like tools