Testing a Claude Code Plugin: Assert on Tool Calls, Not Just Prose
Check which tools a Claude Code plugin's agent actually called, not just how its answer reads, using the Claude Agent SDK and Promptfoo. Plus the five harness bugs that cost us the most time.

Your agent says it checked the docs before answering. Did it? A fluent answer looks the same whether the agent called the documentation tool or quietly guessed, and a test that only reads the prose will pass either way. We closed that gap for a Claude Code plugin by recording every tool call the agent makes, so a test can fail when the agent skips a step.
This post shows the technique with a small Promptfoo provider, says when Promptfoo’s built-in provider or claude plugin eval may spare you the custom code, and covers the harness bugs that cost us the most time.
Names are simplified. The plugin is a “style-guide” plugin for a component library. It bundles an MCP server called style-guide (tools such as lookup_rule, get_component_docs and get_version), a /style-guide slash command, and a style-reviewer agent. An MCP server is a process that exposes tools to the agent over the Model Context Protocol. A plugin is a folder that bundles skills, agents, hooks (commands Claude Code runs automatically on events, such as after a file write) and MCP servers.
Why unit tests were not enough
The MCP server already had a deterministic Vitest suite covering every tool. What we lacked was proof that the whole plugin behaved as its skills and hooks claimed. Does /style-guide trigger the right skill? Does the validation hook fire when a file is written? Only a real agent can answer that, so we had to drive Claude Code from outside an interactive session.
What we tried first
claude plugin eval. When we tried it, it was gated behind early access we didn’t have. It is documented now (Claude Code 2.1.269 or later). Per the docs, you put cases under evals/ in the plugin, each case runs in a fresh non-interactive session with only your plugin loaded, and you can compare against a no-plugin baseline and gate CI on the score. We haven’t tried it since. If you are starting today, evaluate it first, and check whether its graders can assert on which tools were called, since that is the part this post cares about.
Headless Claude Code. claude -p --plugin-dir <path>, with scripts reading the output. In our setup the main agent failed to invoke an MCP tool six times out of six, and we never found the root cause. We haven’t re-tested on current releases, so treat it as one data point from one setup, not a verdict on the approach.
The Claude Agent SDK. What worked was the SDK’s query() function with a plugins: [{ type: 'local', path }] option. We proved it live before building anything: a bare MCP tool call (five runs, all consistent), then a full pipeline where a skill fired, called two required tools in sequence and produced correct output.
Do you need a custom provider?
Possibly not. Promptfoo ships a built-in anthropic:claude-agent-sdk provider (alias anthropic:claude-code) that runs the Agent SDK for you. Its docs show tool calls exposed in metadata.toolCalls, and Promptfoo’s own skills guide asserts on them with call.name === 'Skill'. Its config covers a working directory, setting sources, a skills filter and extra allowed tools. The docs now ask for @anthropic-ai/claude-agent-sdk 0.3.273 or later; we tested on 0.3.272.
So the technique in this post, asserting on recorded tool calls, doesn’t depend on writing your own provider. That built-in provider wasn’t available when we built this harness, which is why we wrote our own, and we haven’t tried it since. If you are starting today, check it against the things we needed before you copy ours:
- per-case
toolsanddisallowedTools, so a case can remove alternative routes to the answer - loading the plugin from a local path
- running in a disposable fixture workspace
- reading a side effect before and after a call (the hook check below)
If it covers those, use it. The custom provider is about 40 lines and is worth keeping when it doesn’t.
Assert on tool calls as well as prose
The idea is to record every tool_use block the agent emits and hand the list to the test. Each test case then asserts two independent things:
| Check | Mechanism | Catches |
|---|---|---|
| Does the answer read right? | llm-rubric (an LLM grades against a rubric) | Wrong or vague prose |
| Did the agent call the required tools? | javascript assertion on the tool-call array | Plausible answers that skipped the MCP call |
For plugin testing the second check carries most of the weight, with one limit. A tool call in the array proves the agent made the call. It doesn’t prove the agent asked the right question or used the answer. Two cheap ways to tighten it: assert on the call’s input as well as its name, and keep the rubric for whether the answer reflects what the tool returned.

The provider
Promptfoo’s custom provider API is a class with an id() method and a callApi(prompt, context) method. context.vars holds the test case’s variables, and returning { output, metadata } is enough. This is our provider, trimmed:
import { query } from "@anthropic-ai/claude-agent-sdk";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
const PLUGIN_ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
// Array-valued vars arrive as JSON strings (see "The config trap").
const parseArrayVar = (value) =>
value === undefined ? undefined : JSON.parse(value);
function extractToolCalls(messages) {
return messages
.filter((m) => m.type === "assistant")
.flatMap((m) => m.message.content)
.filter((block) => block.type === "tool_use")
.map(({ name, input }) => ({ name, input }));
}
export default class PluginEvalProvider {
id = () => "plugin-eval-provider";
callApi = async (promptText, context) => {
const vars = context.vars ?? {};
const result = query({
prompt: promptText,
options: {
cwd: PLUGIN_ROOT,
settingSources: [], // ignore user/project settings so runs are reproducible
plugins: [{ type: "local", path: PLUGIN_ROOT }],
tools: parseArrayVar(vars.tools),
disallowedTools: parseArrayVar(vars.disallowedTools),
permissionMode: "bypassPermissions",
allowDangerouslySkipPermissions: true,
},
});
const messages = [];
let output = "";
for await (const message of result) {
messages.push(message);
if (message.type === "result") output = message.result;
}
return { output, metadata: { toolCalls: extractToolCalls(messages) } };
};
}
The option names match the Agent SDK TypeScript reference, and the plugin shape matches the plugins guide. That guide also notes plugin skills are namespaced, invoked as /plugin-name:skill-name.
Cases that assert real Write calls run in a disposable, git-tracked fixture workspace. An early live run of the migration agent failed on a missing dependency because the scratch directory had none, and a minimal fixture fixed that without touching a real repo.
Asserting what a plugin actually does
The questions from the start were: does the command trigger the right skill, does the hook fire, does an unrelated prompt trigger nothing? Each one is a short assertion over the same recorded data. The examples below are illustrative. Log your own toolCalls once before relying on exact names or input shapes, because a slash command may not surface as a Skill call the way a model-chosen skill does.
Right tool, right question. Check the name and the input together:
- description: "rule lookup asks about the right rule"
vars:
prompt: "/style-guide what is the spacing rule for buttons?"
tools: '["Skill", "ToolSearch", "mcp__plugin_style-guide_style-guide__lookup_rule"]'
assert:
- type: javascript
value: "context.providerResponse.metadata.toolCalls.some(c => c.name.endsWith('lookup_rule') && JSON.stringify(c.input).includes('spacing'))"
- type: llm-rubric
value: "States the button spacing rule and does not invent values the tool did not return."
Skill activation. A skill the model chooses shows up as a Skill call. Assert on it, and on the skill name inside the input:
- description: "skill activates for a matching request"
vars:
prompt: "Review this button for style-guide violations: <Button size='huge'>Go</Button>"
tools: '["Skill", "ToolSearch", "mcp__plugin_style-guide_style-guide__lookup_rule"]'
assert:
- type: javascript
value: "context.providerResponse.metadata.toolCalls.some(c => c.name === 'Skill' && JSON.stringify(c.input).includes('style'))"
Hook firing. A hook isn’t a tool call, so there is nothing in toolCalls to assert on. If the hook has any observable side effect (a log line, a marker file), snapshot it before and after the call and return the result as metadata. This is the same trick as the usage-log case under “Gotchas”:
import { existsSync, statSync } from "node:fs";
// Hypothetical: the hook appends a line to this file whenever it fires.
const HOOK_LOG = join(PLUGIN_ROOT, ".eval-scratch", "hook.log");
const sizeOf = (p) => (existsSync(p) ? statSync(p).size : 0);
// Inside callApi, around the query() loop:
const logBefore = sizeOf(HOOK_LOG);
// ... run query() and collect messages as above ...
return {
output,
metadata: {
toolCalls: extractToolCalls(messages),
hookLogGrew: sizeOf(HOOK_LOG) > logBefore,
},
};
- description: "validation hook fires on a component write"
vars:
prompt: "Create src/Button.tsx with a basic button component."
assert:
- type: javascript
value: "context.providerResponse.metadata.toolCalls.some(c => c.name === 'Write') && context.providerResponse.metadata.hookLogGrew === true"
The negative case. An unrelated prompt must trigger nothing from the plugin:
- description: "unrelated prompt triggers nothing"
vars:
prompt: "What is the capital of France?"
tools: '["Skill", "ToolSearch", "mcp__plugin_style-guide_style-guide__lookup_rule"]'
assert:
- type: javascript
value: "!context.providerResponse.metadata.toolCalls.some(c => c.name === 'Skill' || c.name.startsWith('mcp__plugin_style-guide'))"
The config trap that cost the most time
Promptfoo expands array-valued vars into one test case per element. Write tools: ['Skill', 'ToolSearch'] and your provider never sees a two-item array. It runs the case twice, once with "Skill" and once with "ToolSearch". That is the right behaviour for sweeping prompts across inputs and the wrong one for a single list-shaped value.
The symptom fooled us because it looked like tool-isolation bugs in the plugin, with cases acting as if only one tool existed. It also produced a second, unrelated-looking symptom: disallowedTools crashed with oe.join is not a function, which read like a bug in the minified SDK. Same root cause. The array had been demoted to a string, and something called .join() on it.
Here is a minimal complete config with the broken form and the fix side by side:
description: plugin behavioral eval suite
evaluateOptions:
maxConcurrency: 1
providers:
- id: file://./provider.mjs
prompts:
- "{{prompt}}"
defaultTest:
options:
provider:
id: anthropic:messages:claude-sonnet-5
config:
max_tokens: 4096
tests:
# Broken: Promptfoo runs this as two tests, vars.tools = "Skill", then "ToolSearch"
- description: "rule lookup (bare array)"
vars:
prompt: "/style-guide what is the spacing rule for buttons?"
tools: ["Skill", "ToolSearch"]
# Fixed: a JSON string arrives intact; the provider parses it
- description: "rule lookup"
vars:
prompt: "/style-guide what is the spacing rule for buttons?"
tools: '["Skill", "ToolSearch", "mcp__plugin_style-guide_style-guide__lookup_rule"]'
assert:
- type: javascript
value: "context.providerResponse.metadata.toolCalls.some(c => c.name.endsWith('lookup_rule'))"
Promptfoo’s disableVarExpansion option may help, but its docs only show it for assertion values and we haven’t tried it for provider vars, so we stuck with JSON strings.
The defaultTest block pins the grader model. Without it, Promptfoo picks a grading provider based on which API key is set in your shell. It also raises max_tokens, which matters below.
Scoping what the agent can reach
To prove the plugin’s tool is what produced an answer, a test has to remove the other routes to it. That means restricting the agent’s tools per case, and three of our bugs came from getting that wrong:
| Symptom | Cause | Fix |
|---|---|---|
toggleMcpServer(name, false) didn’t stop the agent reaching MCP tools (two live runs) | Likely because the plugin was already trusted at the user-settings level, independent of the per-session toggle | Use disallowedTools for a real boundary; it blocks MCP tools via a mcp__server__* wildcard |
A case with tools: ["Agent"] left the delegated subagent with no Read, Write or Bash | A top-level tools list caps built-in tools for the whole delegation tree, whatever the subagent’s frontmatter says. MCP tools weren’t affected | List the built-ins the subagent needs next to "Agent" |
A case scoped with allowedTools still used Bash and Read freely | allowedTools only skips permission prompts. It doesn’t restrict availability, as the SDK reference says | Restrict with tools; use allowedTools only to pre-approve |
The grader bug
An LLM rubric returned “no verdict” on a large generated-component case. The grader had hit the 1024-token default max_tokens mid-reasoning. Pin the grader model and set max_tokens: 4096, as the config above does.
Five bugs, none in the plugin
Counting the array-expansion bug once, that is five distinct causes: array expansion, the MCP toggle, the tools cap on subagents, allowedTools semantics and the grader token limit. All five were found while building the harness, not while using the plugin.
The harness did catch one real plugin gap. The style-reviewer agent sometimes skipped get_version, because its instruction said “read the target, then call get_version” in one sentence and an inline-snippet review had nothing to read. Splitting it into separate, unconditional steps fixed it on a rerun.
What we haven’t measured
Agents vary from run to run, so we assert on structural facts (which tools were called) and keep rubrics narrow. That is a design choice meant to reduce flakiness, not a measured result. We don’t have per-case pass rates across repeated runs, so we can’t tell you how often a case flips or whether tool-call assertions are steadier than rubric ones. The only instability we can point to is API overload noise when we fired several real calls at once, which is one reason the suite runs serially.
If you adopt this, measure it before you trust a red or green result. Run each case several times (for example with promptfoo eval --repeat 5; check promptfoo eval --help on your version) and look at the pass rate per case. Separate three kinds of failure: a tool call that really was skipped, a rubric that flipped on borderline wording, and API overload noise.
What a green run does not tell you
Our 18 cases cover skill activation, agent invocation, hook firing, a negative check (an unrelated prompt must trigger nothing) and two image-input code-generation skills. Content checks on the generated code still missed three defects that only showed up when the component was rendered: an invented Sass @use import, a component forced into a role its API doesn’t support, and a missing form-control binding. The eval sandbox can’t render anything, so that check stays manual. I read a green run as “the mechanism fired”, nothing more.
Gotchas and trade-offs
- Time and money. A full run makes real API calls serially and takes roughly 15 to 20 minutes. Use a case-description regex filter (
--filter-pattern) while iterating. - Permissions.
permissionMode: 'bypassPermissions'lets the agent run commands without asking, and the SDK makes you confirm it withallowDangerouslySkipPermissions: true. Run this in a sandbox or CI container, never against a repo you care about. - Serial runs.
maxConcurrency: 1keeps one case from polluting another. Our usage-log case asserts that its own call grew a log the MCP server appends to, so it re-snapshots the log size right before its call. Parallel runs would break that, and firing several real calls at once also produced API-overload noise. - Non-determinism. Agents vary run to run, and we haven’t measured how much (see “What we haven’t measured”). Assert on structural facts and keep rubrics narrow.
Alternatives and when not to use this
| Option | Good for | Limit |
|---|---|---|
claude plugin eval | Native tooling: an evals/ suite inside the plugin, isolated runs, a no-plugin baseline and CI gating, per its docs | Was gated when we tried; documented now (Claude Code 2.1.269+). We haven’t tried it. Check whether its graders can assert on tool calls |
Promptfoo’s built-in anthropic:claude-agent-sdk provider | Skipping custom code. Per its docs it exposes tool calls in metadata.toolCalls | Didn’t exist when we built this; we haven’t tried it since. Docs ask for Agent SDK 0.3.273 or later. Check per-case tool restriction, fixtures and side-effect snapshots |
| Custom provider (this post) | Full control over query() options, per-case tool scoping and side-effect snapshots | About 40 lines to maintain |
claude -p --plugin-dir | Cheapest possible smoke test | Failed 6/6 on MCP calls in our setup; root cause unknown, not re-tested |
| Unit tests on the MCP server | Fast, free, deterministic | Can’t tell you whether an agent chooses to call the tools |
If your plugin is only an MCP server with no skills, hooks or agents, plain unit tests are enough. This approach earns its cost when behaviour depends on the agent’s decisions.
For the server side, see How We Built an MCP Server for Our UI Library. For keeping the prompts the agent reads maintainable, see Shipping LLM Prompts as a Build Artifact, Not a Doc.
Takeaways
- Assert on the agent’s tool calls as well as its prose; fluent answers hide skipped steps.
- Assert on a call’s input, not just its name, because a call’s presence doesn’t prove it was the right one.
- Record tool calls through a custom Promptfoo provider around
query(), or check first whether the built-in Agent SDK provider orclaude plugin evalalready does what you need. - Hooks aren’t tool calls. Assert on their side effects.
- Never put bare arrays under Promptfoo
vars; encode them as JSON strings. - Restrict a run with
toolsordisallowedTools, notallowedTools. Pin the grader model and itsmax_tokens, and run serially. - Treat a green run as “the mechanism fired” and keep a manual check for generated code.
Tested with: @anthropic-ai/claude-agent-sdk 0.3.272, promptfoo 0.121.20, Node 22 or newer. Promptfoo’s built-in Agent SDK provider docs now ask for 0.3.273 or later.