# @arizeai/openinference-instrumentation-claude-agent-sdk

**JavaScript · Instrumentation**

OpenInference instrumentation for Claude Agent SDK

- **Version**: 0.3.9
- **Instruments**: `@anthropic-ai/claude-agent-sdk >=0.2.0`

[npm](https://www.npmjs.com/package/@arizeai/openinference-instrumentation-claude-agent-sdk) · [README](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-instrumentation-claude-agent-sdk/README.md) · [Source](https://github.com/Arize-ai/openinference/tree/main/js/packages/openinference-instrumentation-claude-agent-sdk)

## Install

```sh
npm install @arizeai/openinference-instrumentation-claude-agent-sdk
```

## Usage

Register the instrumentation once, at startup, before the library is imported. The [`ClaudeAgentSDKInstrumentation`](https://openinf.dev/js/openinference-instrumentation-claude-agent-sdk.html.md#ClaudeAgentSDKInstrumentation) reference below lists its options.

```ts
import { registerInstrumentations } from "@opentelemetry/instrumentation";
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
import { ClaudeAgentSDKInstrumentation } from "@arizeai/openinference-instrumentation-claude-agent-sdk";

const provider = new NodeTracerProvider({
  // ...a span processor that exports to Phoenix or any OTLP backend.
});
provider.register();

registerInstrumentations({
  instrumentations: [new ClaudeAgentSDKInstrumentation()],
});
```

If the library is imported first (as ES modules often are), patch it directly with [`manuallyInstrument()`](https://openinf.dev/js/openinference-instrumentation-claude-agent-sdk.html.md#ClaudeAgentSDKInstrumentation.manuallyInstrument).

## `@arizeai/openinference-instrumentation-claude-agent-sdk`

### `isPatched`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-instrumentation-claude-agent-sdk/src/instrumentation.ts#L42)

```typescript
function isPatched(): boolean
```

Check if instrumentation is enabled / disabled.

### `ClaudeAgentSDKInstrumentation`

_class_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-instrumentation-claude-agent-sdk/src/instrumentation.ts#L127)

```typescript
class ClaudeAgentSDKInstrumentation extends InstrumentationBase<ClaudeAgentSDKModule>
```

OpenInference instrumentation for the Claude Agent SDK.

Produces AGENT spans for query()/prompt() invocations and TOOL spans for each tool call via hook injection.

**Examples**

```typescript
import { ClaudeAgentSDKInstrumentation } from "@arizeai/openinference-instrumentation-claude-agent-sdk";

const instrumentation = new ClaudeAgentSDKInstrumentation();
instrumentation.setTracerProvider(provider);
```

**Properties**

| Name | Type |
| - | - |
| [`tracer`](https://openinf.dev/js/openinference-instrumentation-claude-agent-sdk.html.md#ClaudeAgentSDKInstrumentation.tracer) | `Tracer` |

#### `new ClaudeAgentSDKInstrumentation`

_constructor_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-instrumentation-claude-agent-sdk/src/instrumentation.ts#L139)

```typescript
new ClaudeAgentSDKInstrumentation(
  options?: {
    instrumentationConfig?: InstrumentationConfig;
    traceConfig?: TraceConfigOptions;
    tracerProvider?: TracerProvider;
  },
): ClaudeAgentSDKInstrumentation
```

#### `manuallyInstrument`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-instrumentation-claude-agent-sdk/src/instrumentation.ts#L171)

```typescript
manuallyInstrument<TModule extends ClaudeAgentSDKModule>(
  module: TModule,
): TModule
```

Manually instruments the Claude Agent SDK module. Returns a patched copy when the supplied module is a native ESM namespace.

#### `setTracerProvider`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-instrumentation-claude-agent-sdk/src/instrumentation.ts#L190)

```typescript
setTracerProvider(tracerProvider: TracerProvider): void
```

Sets TraceProvider to this plugin
