nomi

Setup guides · Python

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.

Versions
claude-agent-sdk >=0.2.140,<0.2.188 with mcp >=2.0,<2.4; Python SDK (nomi-sdk) 1.0.0
Route
Claude Code's own telemetry export for model calls, prompts and replies (its log events, with its traces adding detail), plus an adapter for tool calls

Your coding agent can do the attaching. Ask it:

Use the attach-nomi skill and add nomi to this agent.

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 Python SDK into your agent's environment from the release's wheel (the same file comes with the program; it isn't on the Python package index) and tell it where nomi is:

pip install "nomi-sdk @ https://github.com/joshbodunrin/nomi/releases/download/v1.0.0/nomi_sdk-1.0.0-py3-none-any.whl"
export MYAGENT_NOMI_ENABLED=1
export MYAGENT_NOMI_ENDPOINT=http://127.0.0.1:4320
export MYAGENT_NOMI_TOKEN_FILE="$HOME/.nomi/write-token"

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. All of it lands in one run, joined by IDs only.

Claude Code labels its tracing beta, and it can lose the start of a turn: when its config folder holds settings an earlier run left, it starts the turn before its tracing is on, so the turn’s first model call has no trace span. Its log events aren’t affected, so the call is still recorded, with less detail (below).

from nomi.compatibility import claude_agent_sdk_support
print(claude_agent_sdk_support())

The range is claude-agent-sdk 0.2.140 up to (not including) 0.2.188, with mcp 2.0 up to 2.4. Tested combinations run from 0.2.140 (Claude Code 2.1.235) to 0.2.187 (Claude Code 2.1.330). Pre-releases, release candidates and development builds aren’t accepted, even inside the range: none is tested.

Outside the range, instrument returns your options unchanged and logs one 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. strict=True raises instead. It also names the Claude Code version the SDK includes. A cli_path pointing at another Claude Code build isn’t covered. The TypeScript Agent SDK has its own guide.

Attach

  1. Create the observer once, where your process starts:

    from nomi import Observer
    from nomi.integrations.claude_agent_sdk import instrument
    
    observer = Observer.from_env("support-desk", project="support-desk", agent="support-desk", prefix="SUPPORT_DESK_NOMI")
    
  2. Where your app builds its options, pass them through instrument and use the copy it returns:

    options = instrument(observer, ClaudeAgentOptions(...))
    

    The copy has nomi’s hooks after your own, wraps the tool calls of your in-process SDK MCP servers, and 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 sets CLAUDE_CODE_OTEL_SHUTDOWN_TIMEOUT_MS=500, so Claude Code waits at most half a second for its exporters at the end of each query(), and passes on CLAUDE_CODE_MAX_OUTPUT_TOKENS, when you set it, as the output cap. Any value you set yourself is kept.

  3. Wrap each unit of work around the query() call, so the program’s events and spans join that run:

    with observer.observe("support_turn", workflow="support", group=conversation.id, step="reply"):
        async for message in query(prompt=text, options=options):
            ...
    

    With ClaudeSDKClient, the program reads the trace only at connect(). Connect inside the scope, or model calls and the scope’s declarations land in separate runs.

  4. Switch on Claude Code’s tracing, in ClaudeAgentOptions.env or the process environment. 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)"
    

    The header needs a literal space after Bearer: Claude Code doesn’t decode %20, and every export is then rejected. Leave the metrics and console exporters off. Don’t set the logs exporter or the prompt and reply settings yourself: instrument sets them when Claude Code exports to nomi, and keeps any value you set. With the metadata profile it leaves the prompt and reply settings off; with your logs going to another endpoint it switches none of them on. Claude Code reads these from the environment only, not from a repository’s .claude/settings.json.

Recorded automatically

  • Model calls, one per Claude Code api_request event (api_error for one that failed, api_refusal for a refusal): the model Claude Code reports, input and output tokens, cache reads and writes, duration, the provider request ID, errors with their HTTP status, 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 retry attempts. Each call is counted once. The output cap, when the app sets CLAUDE_CODE_MAX_OUTPUT_TOKENS.
  • A call known only from its event, because its span was never created, has no stop reason, no model asked for (the event’s one model field is the model used) and no output cap unless the app set one; they show as not recorded. Its start time is the event’s time minus its duration, labelled derived.
  • 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. A reply Claude Code cut at its limit (about 60 KB) is shown as cut, with its original length.
  • Tool calls, from the adapter: name, arguments, result, duration, error text, the tool-use ID (exact), a subagent’s ID and type, and file, function and line for in-process SDK MCP tools.
  • Structure: the scope, one interaction per query() (or a turn step built from the prompt event when that span was never created), and model and tool calls under it. A Claude Code span that arrives with no parent is placed by the IDs it carries, never by time or order.

Declared by your code

Decisions (results and issues), effects and logical actions, expected exceptions and waits. No hook or span provides them. An observer.tool(...) inside an SDK MCP tool nests under that tool’s step.

What it can’t see

  • Each model call’s own input, the system prompt and thinking: Claude Code exports only the turn’s prompt.
  • A per-call message ID: the request ID stands in.
  • 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: there is no call to match them to.
  • The output cap when the app leaves CLAUDE_CODE_MAX_OUTPUT_TOKENS unset.
  • Every model call and its tokens when telemetry is off, or its logs aren’t sent to this nomi: shown as unknown, not zero.
  • 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.
  • A tool call Claude Code rejected before any tool ran: there is no step for it.
  • A retried tool call as a retry: a repeat is a new tool-use ID with the same arguments.
  • The code location of built-in tools, the Agent tool and external MCP tools.

Limits and edge cases

  • Claude Code lowers a CLAUDE_CODE_MAX_OUTPUT_TOKENS above the model’s own limit, so the recorded cap can be above the real one.
  • With nomi up, Claude Code waits at most 500 ms for its own exporters at the end of each query() (CLAUDE_CODE_OTEL_SHUTDOWN_TIMEOUT_MS, which instrument sets when you haven’t; Claude Code’s default is 2 s). In the receiver’s sync_each_request mode, or on a disk too slow for even the write, when other processes sync to disk heavily it can drop its last export, so the last reply, or, with Claude Code’s span export off, the model calls, may not reach nomi. The model call then keeps what its span recorded (status, stop reason, tokens, request ID) and says output_not_recorded: "no_reply_event"; a run whose model calls were lost has no model steps and says model_calls: "unknown", with the reason in model_calls_unknown and in unknowns (no model call from Claude Code reached this home), and tokens: "unknown" (“token usage was not reported”). When only some of a run’s model calls are lost, nothing stored shows it: the run shows the calls that arrived. With the default durability (batched) no export was lost under the same disk load (0 of 18 runs, against 15 of 18 with sync_each_request). You can set CLAUDE_CODE_OTEL_SHUTDOWN_TIMEOUT_MS higher yourself, and your value is kept, at the cost of up to that long at the end of each query() when nomi hangs.

In every guide: nothing below a tool’s boundary, such as HTTP retries in your own client, is seen unless your code declares its attempts. Retries inside a provider’s client library show as one longer model call; the step gives the client’s attempts where the route reports them, and otherwise says they aren’t reported. A model nomi has no price for, such as a local one, has its cost shown as unpriced, never as $0. A run that was still open when nomi stopped says its end was not received: its outcome is unknown, not interrupted.

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?”