Claude Code
Use this guide to observe Claude Code sessions with NeMo Relay. Claude Code is the supported integration target. The Claude application, Claude web, and Claude desktop sessions are unsupported unless they expose the same local hook and gateway controls as Claude Code.
On Windows, Relay generates Bash-compatible hook commands for Claude Code,
using forward-slash executable and configuration paths. After upgrading Relay,
run nemo-relay integrations refresh to regenerate persistently installed hooks.
Transparent Run
For shared run options and argument forwarding, refer to Command Reference.
Use the wrapper for no-install local observability:
Pass Claude Code arguments after --:
This shortcut is equivalent to nemo-relay run -- claude. The wrapper starts a
gateway on a dynamic 127.0.0.1 port, creates a temporary Claude plugin
directory with NeMo Relay hooks, and passes that plugin with --plugin-dir.
Because Claude Code gives its first --settings source precedence over the
process environment, Relay also creates a private settings overlay that
preserves that source and overrides only ANTHROPIC_BASE_URL for the launched
process. The source settings and installed plugin enablement remain unchanged.
The wrapper also defaults CLAUDE_CODE_GATEWAY_HINT_HEADERS to 1 in the
launched process when no value is inherited. Supported Claude versions then
report each model request’s class. Claude’s settings can override this process
default.
When Relay supplies the Anthropic credential, through [upstream.anthropic_oidc]
or [upstream.anthropic_api_key_helper], and the launched process inherits
neither ANTHROPIC_API_KEY nor ANTHROPIC_AUTH_TOKEN, the wrapper sets
ANTHROPIC_API_KEY to a placeholder, so Claude Code starts without a key of
its own. The gateway replaces the placeholder with the credential that Relay
supplies.
Whenever Relay supplies the Anthropic credential, the wrapper also defaults
CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY to 1 when no value is inherited,
so the Claude Code /model menu lists the models that the upstream’s
/v1/models returns through the gateway. Set the variable to 0 to keep the
built-in model list.
If a Relay plugin is already enabled, its MCP process authenticates and borrows
the dynamic gateway instead of launching the fixed sidecar, then monitors that
exact gateway while MCP stdio remains open. Its persistent hooks exit without
forwarding. Only the wrapper-owned temporary hooks deliver lifecycle payloads,
and those hooks authenticate the wrapper gateway before sending a payload, so
installed and source-marketplace plugin IDs cannot duplicate the captured
stream.
Inspect what would be launched without starting Claude Code:
Persistent Plugin Install
Use persistent plugin installation when Claude Code should load NeMo Relay from
its normal plugin marketplace instead of through nemo-relay claude:
The installer creates a local marketplace, installs
nemo-relay-plugin@nemo-relay-local at user scope, and enables Claude Code
provider routing through the local NeMo Relay sidecar. It uses the existing
nemo-relay binary on PATH; it does not install a plugin-local Relay binary.
The installer also enables gateway hints in Claude’s user settings unless that
setting is already present. See Model Request Classes
for the metadata these hints provide.
The plugin starts nemo-relay mcp, which starts or reuses the shared gateway.
For authentication, heartbeats, recovery, and idle shutdown, refer to
Shared Gateway Lifecycle.
The generated entry sets alwaysLoad: true, so Claude Code 2.1.121 or newer
waits for the MCP connection before session startup. The installed command hook
carries the same install-generation fence, waits for the MCP-owned gateway, and
forwards the canonical payload once. MCP owns the session-long gateway
lifecycle.
Persistent plugin mode loads system and user Relay configuration only.
For project-specific configuration, use
nemo-relay --config .nemo-relay/config.toml run -- claude. Relay selects the
sibling plugins.toml; system configuration still applies. Run
nemo-relay install claude-code --force to replace an existing
generation-fenced installation safely.
After upgrading Relay, refresh every Relay-managed coding-agent integration before starting a new Claude Code session:
Restart Claude Code afterward. See
Refresh Installed Integrations
for updates and
Shared Gateway Lifecycle
for gateway shutdown instructions.
For one installation, nemo-relay install claude-code --force remains the focused repair
command. Manual MCP configurations are not changed.
Check or remove the installed plugin with:
Refer to Manage Persistent Integrations for install directories, rollback behavior, and source marketplace notes.
Shared Config
Create $XDG_CONFIG_HOME/nemo-relay/config.toml or
~/.config/nemo-relay/config.toml for user defaults:
To forward Claude Code requests to a custom provider host, configure Relay’s endpoint and authentication as described in Provider Upstreams.
Then configure observability with nemo-relay plugins edit or the XDG user
plugins.toml:
Replace /absolute/path/to/atif with an absolute, writable path on your
machine. On Windows, use a path such as C:/relay/atif. An absolute path keeps
the export destination consistent when a persistent gateway serves sessions
from different projects.
Run nemo-relay run --agent claude to use the configured command and plugin
config. Files layer from explicit-or-user to system, so system
configuration has the highest file-level priority.
Standalone Gateway
Use the long-running gateway only when you want Claude Code running outside the wrapper (e.g., already configured by an IDE):
Launch Claude Code from another terminal with the gateway environment:
The gateway forwards Anthropic /v1/messages, /v1/messages/count_tokens, and
model routes without rewriting provider JSON. Hook events require either the
persistent NeMo Relay plugin or a transparent nemo-relay claude or
nemo-relay run --agent claude invocation, which injects ephemeral hooks into
the launched process.
Smoke Test
Run a small Claude Code prompt that starts a session and uses one tool. Then check that hook forwarding reaches the gateway:
The response should be valid Claude Code hook JSON. For most lifecycle events it
is an allow/continue response. A full observability smoke fixture should produce
expected openinference OpenTelemetry spans, raw ATOF events, and ATIF
trajectories for at least one user turn, one LLM call, and one tool call.
Verify Export
End the Claude Code session and check for completed turn trajectories in Agent Trajectory Interchange Format (ATIF):
Use the same absolute path you configured above.
The gateway writes a trajectory when its enclosing turn closes, including at
SessionEnd. One session can produce multiple files. If none appear, confirm
that hooks fire, plugins.toml enables ATIF, and the gateway process can write
to the configured directory. An idle internal model call has no enclosing turn
and does not create an ATIF trajectory.
Captured Events
Generated Claude Code hooks include SessionStart, SessionEnd,
UserPromptSubmit, UserPromptExpansion, PreToolUse, PostToolUse,
PostToolUseFailure, SubagentStart, SubagentStop,
Notification, Stop, StopFailure, PreCompact, and PostCompact. Both
compaction hooks emit canonical compaction marks. Relay normalizes the other hooks as scope,
prompt, tool, notification, subagent, or private LLM correlation events
according to the hook payload. UserPromptExpansion records nonempty
slash-command expansions as skill.load.inferred; Claude Code does not
identify whether an expansion came from a skill or a legacy custom command.
The normal Skill pre-tool hook emits an observed skill.load mark.
The wrapper requires Claude Code 2.1.121 or newer. Earlier versions do not
support every required hook event, and nemo-relay doctor reports the version
mismatch.
Tool hooks preserve canonical fields such as tool_use_id, tool_name,
tool_input, error, duration_ms, and is_interrupt. Subagent hooks use
agent_id as the subagent identifier and preserve agent_type in metadata.
Claude Code traces are turn-oriented, but a trace root is not a prompt count. Gateway traffic or compaction hooks can open a turn without a prompt hook. Use request classes to separate internal model operations from conversation work, and final prompt-observation metadata to count completed turns with an observed prompt.
Troubleshoot LLM Lifecycle
For configuration, integration, and exporter checks, start with Troubleshoot the CLI.
Missing hooks usually means Claude Code did not load the local hook config or
the nemo-relay binary is not on PATH.
Missing LLM spans with present hook spans means Anthropic traffic is not routed
through the gateway. Verify ANTHROPIC_BASE_URL in the Claude Code process
environment and confirm that requests hit /v1/messages.
If LLM spans exist but attach to the session instead of a subagent, pass
x-nemo-relay-subagent-id on gateway requests or include shared
conversation_id, generation_id, or request_id values in both hook payloads
and provider requests.
When Relay cannot prove a stronger LLM owner, it keeps the span under the active
turn and adds correlation metadata instead of guessing. Inspect
llm_correlation_status, llm_correlation_source, and
llm_correlation_subagent_id on LLM spans. Common statuses include explicit,
single_hint, request_affinity, agent_fallback, and
ambiguous_fallback. Tool spans expose the same diagnostic pattern with
tool_correlation_status, tool_correlation_source, and
tool_correlation_subagent_id.
Unmatched Subagent Stops
Claude Code’s SubagentStart hook
runs for Agent tool launches, resumed subagents, and teammate messages. Its
SubagentStop input documentation
also describes stops for Claude’s internal agents, including prompt suggestions
and /btw side questions. For these stops, agent_type is the session agent’s
name, or an empty string when the session has no named agent. An unmatched stop
therefore does not, by itself, establish that a start hook was lost.
When an unmatched Claude SubagentStop has the session’s agent type, Relay
records a claude_agent_stop_unclassified mark with the hook payload and
start_observed=false. A matching type suggests internal activity but cannot
rule out a real subagent whose start was missed. Other unmatched stops retain
the subagent_end_without_start mark. Neither mark opens a new turn, including
when the stop arrives after the turn has closed. To find all unmatched Claude
stops in OpenTelemetry logs, include both mark names in nemo_relay.mark.name.
Notifications
Claude Code Notification hooks produce notification marks without opening a
turn. Notifications within an active turn or an explicitly correlated subagent
keep that parent. Between turns, a notification does not create a new turn just
to hold the mark.
ATOF retains these marks, and the full and openinference projections can
export them. The gen_ai projection omits marks. A notification mark does not
establish the purpose of a separate model call.
Separate Model Request Classes
Claude Code 2.1.273 or newer labels model requests with
x-claude-code-request-class
when gateway hints are enabled. Wrapped launches set
CLAUDE_CODE_GATEWAY_HINT_HEADERS to "1" only when the variable is unset. The
persistent installer and
nemo-relay integrations refresh add "1" only when the setting is missing
from Claude’s user settings. Claude’s saved settings can override a shell
export. Generated managed settings also enable hints.
Replace older managed bundles
to include the setting.
Relay records the normalized class in LLM event metadata as
claude_code_request_class:
Calls labeled auxiliary or compaction remain in traces with their reported
usage. They still run the configured middleware and cache policy, but do not
open main turns, replace task output, or provide hints for matching tool calls.
An internal call between turns has no enclosing ATIF trajectory. Use ATOF or
OpenTelemetry to include these calls in usage totals.
The integration minimum remains Claude Code 2.1.121. Versions before 2.1.273
and missing, invalid, or unsupported classes remain unknown and keep the
existing turn handling and parent selection. Classes describe operations, not
whether a person initiated them. Do not treat unknown as confirmed
conversation work.
Count Turns with Observed Prompts
Count completed main turns with final turn_prompt_observed=true, rather than
counting trace roots. This flag includes late prompt hooks; false means no
prompt hook was observed, and a missing field is unknown. Subagent prompts do
not set the parent’s flag. Gateway requests and compaction hooks can open turns
without a prompt hook.
Export Class and Prompt Evidence to GenAI
Enable OpenTelemetry in the existing observability component, then add this
file sink or use the same mappings on a gen_ai endpoint:
These custom aliases expose the class on model spans and the final prompt flag on turn spans. They are not standard GenAI attributes. See attribute mappings for configuration and sanitization behavior.
Hook Limitations
Claude Code hooks are available only when Claude Code loads the persistent NeMo
Relay plugin or the ephemeral plugin generated by nemo-relay claude or
nemo-relay run --agent claude.
The standalone gateway can still observe Anthropic LLM traffic, but it cannot
invent missing tool, prompt, compaction, notification, or subagent hooks.
Claude Code’s --safe-mode, --bare, CLAUDE_CODE_SAFE_MODE, and
CLAUDE_CODE_SIMPLE options can prevent Relay’s injected hooks from running,
even when model traffic still goes through ANTHROPIC_BASE_URL. This can leave
observability incomplete and degrade Relay’s execution state.
When Relay starts a normal Claude Code session through nemo-relay claude or
nemo-relay run --agent claude, it warns if it detects one of these settings.
Informational commands such as --help and --version exit without this
warning.
This is a best-effort check: --bare may still load explicitly supplied
plugins, and Relay cannot detect settings such as disableAllHooks or
environment changes made inside a wrapper script.
Remove hook-disabling settings when you need Relay to observe hooks or enforce policies.
UserPromptSubmit contributes prompt and LLM correlation data. Stop is a
private correlation and turn-boundary hint rather than a standalone
user-visible mark. StopFailure closes the current turn with an error status,
preserving the hook’s error type and optional error_details. The session
stays open, and the next prompt starts a new turn. The other generated hooks
normalize to their corresponding scope, tool, mark, notification, compaction,
or subagent semantics.