Setup guides · TypeScript
Claude Agent SDK
Model calls, prompts and replies come from the Claude Code program's own telemetry; tool calls come from an adapter in your process. Both land in one run. In-process tools get a code location only when you pass them through observeTool.
Your coding agent can do the attaching. Ask it:
It finds the places to hook in and asks you the few things only you know. The steps below are what it does.
Start nomi
nomi is one program, nomi.
Download it from the releases page, then:
nomi init
nomi configure -mode sdk -source my-agent -receiver-listen 127.0.0.1:4320
nomi start # leave this running
nomi browser -home "$HOME/.nomi" # opens the run view Everything it records lives in ~/.nomi; -home on any command chooses another folder. nomi doctor says whether it's healthy.
Install the TypeScript SDK (runnomi-sdk 1.0.0) into your agent from the release's packed file. It isn't on npm, so keep the whole address. Then tell it where nomi is:
cd /path/to/your/agent
npm install https://github.com/joshbodunrin/nomi/releases/download/v1.0.0/runnomi-sdk-1.0.0.tgz
export MYAGENT_NOMI_ENABLED=1
export MYAGENT_NOMI_ENDPOINT=http://127.0.0.1:4320
export MYAGENT_NOMI_TOKEN_FILE="$HOME/.nomi/write-token" npm records that address in package.json and the lockfile, so another machine or CI installs the same file. This was checked with npm 10.9.2 from a packed file on disk, from ES module and CommonJS applications; pnpm, yarn and bun weren't.
The SDK has no runtime dependencies and works from ES modules and CommonJS. The settings are read by Observer.fromEnv with prefix: "MYAGENT_NOMI"; the SDK reads the token file itself, so the token is never on a command line. Events are held in memory and sent in the background: what can't be delivered is counted and reported as lost. To keep events on disk through an outage or a restart, set MYAGENT_NOMI_SPOOL_DIR and MYAGENT_NOMI_SOURCE.
These are the same-machine settings. Your agent can also run in a container or on another machine of yours and send to the same nomi: where nomi runs has what changes, and the attach skill can set it up.
nomi never changes how your agent runs: if it’s off, down or hanging, your agent carries on with the same output.
How it fits
The SDK starts the Claude Code program as a separate process. Model calls happen there. Each model call and the turn’s prompt are read from that program’s own log events; its traces, when they arrive, are joined to the same call by request ID and add detail. The adapter records tool calls in your process, and passes the open scope into the program. All of it lands in one run, joined by IDs only.
import { claudeAgentSdkSupport } from "runnomi-sdk/integrations/claude-agent-sdk";
console.log(claudeAgentSdkSupport());
The range is @anthropic-ai/claude-agent-sdk 0.3.327 up to (not including) 0.3.332. Tested on 2026-11-23: 0.3.327 (Claude Code 2.1.327), 0.3.330 (Claude Code 2.1.330, every test) and 0.3.331 (Claude Code 2.1.331). 0.3.328 and 0.3.329 are inside the range and weren’t run. Pre-releases aren’t accepted. The check also names the Claude Code version the SDK includes; a pathToClaudeCodeExecutable pointing at another Claude Code build isn’t covered.
The nomi SDK needs Node 22 or later; this route ran on Node 22.13.0 only. Every test ran the real SDK and its Claude Code program against a local stand-in for the model. Claude Code’s tracing behaves differently against the real Anthropic API than against a local endpoint, and that wasn’t run through this SDK.
Outside the range, instrument returns your options unchanged and logs one nomi: Claude Agent SDK adapter off line naming the installed versions: model calls still arrive from Claude Code’s own export, tool calls from the adapter don’t, and your agent runs as usual. instrument(observer, options, { strict: true }) throws instead.
Attach
-
Create the observer once, where your process starts:
import { createSdkMcpServer, query, tool } from "@anthropic-ai/claude-agent-sdk"; import { Observer } from "runnomi-sdk"; import { instrument, observeTool } from "runnomi-sdk/integrations/claude-agent-sdk"; const observer = Observer.fromEnv("my-agent", { project: "my-repo", agent: "my-agent", prefix: "MYAGENT_NOMI" }); -
Where each in-process tool is defined, pass the definition through
observeTool:const lookupOrder = observeTool( observer, tool("lookup_order", "Look up an order.", { order_id: z.string() }, async (args) => { /* unchanged */ }), ); const desk = createSdkMcpServer({ name: "desk", tools: [lookupOrder] });It returns a copy whose handler calls yours once, with the same arguments, and returns its promise unchanged. The tool’s step then carries a code location, and an
observer.tool(...)made inside the tool nests under it. The SDK has no interface to reach a server’s handlers afterwards, which is why this is done where the tool is defined. A tool not passed through is still recorded, from the hooks, with no code location. -
Where your app builds its options, pass them through
instrumentand use the copy it returns:const options = instrument(observer, { model, systemPrompt, mcpServers: { desk }, hooks: appHooks, env: agentEnv });The copy has nomi’s
PreToolUse,PostToolUse,PostToolUseFailureandPostToolBatchhooks after your own for each event; each records and returns{}. It adds the project, agent and root commit to Claude Code’s resource attributes. When Claude Code exports to this nomi, it also switches on Claude Code’s log export (OTEL_LOGS_EXPORTER=otlp, which model calls are read from) and, with content capture on, its prompt and reply export (OTEL_LOG_USER_PROMPTS,OTEL_LOG_ASSISTANT_RESPONSES). It setsCLAUDE_CODE_OTEL_SHUTDOWN_TIMEOUT_MS=500, so Claude Code waits at most half a second for its exporters at the end of eachquery()(its default is 2 seconds), and passes onCLAUDE_CODE_MAX_OUTPUT_TOKENS, when you set it, as the output cap. Any value you set yourself is kept. -
Wrap each unit of work around the
query()call, so the program’s events and spans join that run:await observer.observe("support_turn", { workflow: "support", group: conversation.id, step: "reply" }, async () => { for await (const message of query({ prompt, options })) { /* ... */ } });Pass the returned options object to
query(), or spread it ({ ...options, resume }) inside the scope: itsenvis computed when it is read, so the scope open at that moment is the one passed in. A copy made outside the scope carries no trace, and the program’s spans are then a run of their own. With streaming input (onequery()serving several turns), the program keeps the trace it started with, so later turns’ model calls land in the first turn’s run; that is how the Python client behaves, and it wasn’t tested with this SDK. -
Switch on Claude Code’s tracing in the environment the program starts with. Fill the token in where the process is launched, and never write it into the repository:
CLAUDE_CODE_ENABLE_TELEMETRY=1 CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1 OTEL_TRACES_EXPORTER=otlp OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4320 OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer $(cat ~/.nomi/write-token)"In this SDK,
options.envreplaces the program’s environment; it isn’t merged over the inherited one, as it is in Python. So when your app setsenv, these go in that object, and it is the only place they are read from (an app that spreadsprocess.envinto it already passes them through). When it sets none, they are read from the process environment. The header needs a literal space afterBearer: Claude Code doesn’t decode%20, and every export is then rejected. Leave the metrics andconsoleexporters off. Don’t set the logs exporter, the prompt and reply settings or the shutdown timeout yourself:instrumentsets them when Claude Code exports to nomi. With themetadataprofile it leaves the prompt and reply settings off; with your logs going to another endpoint it switches none of them on. -
Before the process ends,
await observer.close().
Recorded automatically
- Model calls, one per Claude Code
api_requestevent (api_errorfor one that failed,api_refusalfor a refusal): the model Claude Code reports, input and output tokens, cache reads and writes, duration, the provider request ID, errors with Claude Code’s error class and the HTTP status where there was one, and Claude Code’s own cost estimate, kept apart from nomi’s. When the call’s trace span arrives, it adds the requested model, the stop reason and the program’s own count of attempts. Each call is counted once. The output cap, when the app setsCLAUDE_CODE_MAX_OUTPUT_TOKENS. - Prompts and replies, with content capture on: the prompt of each turn, and the reply text of each model call that answered in text, matched to its call by the provider request ID.
- Tool calls, from the adapter: name, the MCP server, arguments, result, duration, error text, the tool-use ID (exact), and a subagent’s ID and type. For in-process tools passed through
observeTool: the file and line whereobserveToolwas called, and the handler’s name when it has one. - A tool call Claude Code refused before any tool ran (not allowed in
dontAskmode, denied bycanUseToolor by aPreToolUsehook): a failed tool step marked as rejected by the framework, with what Claude Code told the model. - Structure: the scope, one interaction per
query(), model calls under it, and your tool steps with the program’s own tool spans folded in by tool-use ID.
Declared by your code
Decisions (results and issues), effects and logical actions, expected exceptions and waits. No hook or span provides them. Don’t put observer.anthropic, observer.modelCall or observer.tool around the agent’s own model or tool calls; an observer.tool(...) around an HTTP attempt inside a tool is right.
What it can’t see
- The code location of built-in tools, the
Agenttool, external MCP tools, and in-process tools not passed throughobserveTool. - Each model call’s own input, the system prompt, thinking, and the returned model: Claude Code exports only the turn’s prompt.
- A per-call message ID: the request ID stands in, shown as
provider_request_id. - A reply for a call that only asked for tools: its tool calls are the tool steps.
- Replies when the provider or a gateway returns no request ID: the call keeps its tokens and stop reason, with no reply text.
- The first attempt of a request Claude Code retried itself, when the retry succeeded: one model call is recorded.
- The model call in flight when a
query()was aborted: the run is cancelled and its tokens read unknown. - A call to a tool that doesn’t exist or is in
disallowedTools: Claude Code fires no hook, so there is no step. - The output cap when the app leaves
CLAUDE_CODE_MAX_OUTPUT_TOKENSunset. - Every model call and its tokens when telemetry is off, or its logs aren’t sent to this nomi: shown as unknown, not zero. Tool calls are still recorded.
- Model calls Claude Code hadn’t sent when the process ended: it exports in batches, and the run then says model calls may be missing.
Limits and edge cases
- For a tool passed through
observeTool, the code location is where the tool is defined, not the handler’s first line. - A tool that throws doesn’t fail the run: Claude Code gives the error to the model, so the run is a success, with two error steps (the adapter’s and Claude Code’s own span).
- Under the
metadataprofile, Claude Code still puts the provider’s error message on its error event, and nomi stores it; only a home set to omit content drops it.
When nomi is down
Your agent’s output, exit code and requests to the model are the same with nomi up, down, never answering, answering 500 or refusing the token. What isn’t delivered is counted and said once on stderr. With durable delivery on (NOMI_SPOOL_DIR), the SDK keeps its events on disk and sends them when nomi is back.
- Claude Code’s own failing exporters print nothing, and what they lose isn’t counted in that line.
- Claude Code waits at most 500 ms for its own exporters at the end of each
query()(CLAUDE_CODE_OTEL_SHUTDOWN_TIMEOUT_MS, whichinstrumentsets when you haven’t; your own value is kept). - With
nomi configure -durability sync_each_request, heavy disk syncing by other processes can make Claude Code drop its last export (15 of 18 runs, against 0 of 18 with the default). The model call then saysoutput_not_recorded: "no_reply_event", and a run whose model calls were all lost saysmodel_calls: "unknown"andtokens: "unknown". When only some of a run’s model calls are lost, nothing stored shows it. - If one of nomi’s hooks threw, the SDK treats it as any failing hook: the tool call goes ahead.
Connect your coding agent
nomi includes a server with read-only tools for your coding agent, and a debug skill that teaches it to keep what was observed, what your code declared and what is unknown apart. Pick yours:
Claude Code
claude mcp add nomi -s user -- nomi mcp
mkdir -p ~/.claude/skills && cp -R skills/debug-agent-with-nomi ~/.claude/skills/ Codex
codex mcp add nomi -- nomi mcp
mkdir -p ~/.codex/skills && cp -R skills/debug-agent-with-nomi ~/.codex/skills/ Cursor, in ~/.cursor/mcp.json (or .cursor/mcp.json for one project)
{"mcpServers": {"nomi": {"type": "stdio", "command": "nomi", "args": ["mcp"]}}} Cursor's debug skill (the skill needs Cursor 2.4 or later)
mkdir -p ~/.cursor/skills && cp -R skills/debug-agent-with-nomi ~/.cursor/skills/ Cursor also reads skills from ~/.claude/skills/, so if the skills are already installed for Claude Code, nothing needs copying.
Then open a session in your agent's repository and ask, for example:
- “What went wrong in my agent's last few runs?”
- “Why did this run fail?”
- “What changed between these two runs?”