🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@inferlane/agent-hooks

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@inferlane/agent-hooks

Drop-in lifecycle hooks for Claude Agent SDK and Anthropic Managed Agents — auto-log cost, tokens, and runtime to InferLane without explicit tool calls.

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

@inferlane/agent-hooks

Drop-in lifecycle hooks that auto-log tokens, cost, active runtime, and web-search charges from Claude Agent SDK sessions (and Anthropic Managed Agents, Goose, SwarmClaw, or any runtime that exposes PreToolUse / PostToolUse / SessionStart / SessionEnd events) to InferLane.

Zero tool calls from the agent. No log_request spam in the model's output. The hooks run transparently alongside your agent loop and post events to InferLane's fleet API in the background.

Install

npm install @inferlane/agent-hooks

Quick start — Claude Agent SDK

import { query } from '@anthropic-ai/claude-agent-sdk';
import { claudeAgentHooks } from '@inferlane/agent-hooks';

const hooks = claudeAgentHooks({
  apiKey: process.env.INFERLANE_API_KEY!,
  runtime: 'CLAUDE_AGENT_SDK',
  agentName: 'my-coding-assistant',
  fleetId: 'fleet_abc123', // optional — attach to a named fleet for rollups + budget alerts
});

for await (const msg of query({
  prompt: 'Refactor the auth module',
  options: { hooks },
})) {
  // handle agent messages
}

That's it. Every tool call, web search, and session completion is logged to InferLane. The dashboard shows token cost + runtime cost ($0.08/hr for Managed Agents) + web-search cost ($10/1000 for Managed Agents) in real time.

What gets tracked

HookRecorded data
SessionStartOpens a fleet session (POST /api/fleet/sessions)
PreToolUseStarts the active-runtime timer; posts TOOL_USE event
PostToolUseStops the timer; posts TOOL_RESULT event with token usage and active-runtime delta. Detects web_search / WebSearch calls and bumps the web-search counter.
SessionEndMarks the session COMPLETED

Runtime cost is only charged for ANTHROPIC_MANAGED sessions (Anthropic bills $0.08 per active session-hour on Managed Agents; local Agent SDK runtime is free). Web-search cost is only charged when the runtime is ANTHROPIC_MANAGED.

Advanced: granular control

If you'd rather manage hook registration yourself:

import { createInferLaneHooks } from '@inferlane/agent-hooks';

const il = createInferLaneHooks({
  apiKey: process.env.INFERLANE_API_KEY!,
  runtime: 'CLAUDE_AGENT_SDK',
  debug: true,             // log hook activity to console
  swallowErrors: true,     // default — don't break the agent if telemetry fails
});

const options = {
  hooks: {
    SessionStart: [il.sessionStart],
    PreToolUse:   [il.preToolUse],
    PostToolUse:  [il.postToolUse],
    SessionEnd:   [il.sessionEnd],
  },
};

// On graceful shutdown:
process.on('SIGTERM', async () => {
  await il.flush(); // closes the active session cleanly
});

Runtime field values

ValueUse for
ANTHROPIC_MANAGEDAnthropic's cloud-hosted managed agent runtime
CLAUDE_AGENT_SDKSelf-hosted Claude Agent SDK
CLAUDE_CODEClaude Code CLI / VS Code extension
GOOSEBlock's Goose agent
SWARMCLAWSwarmClaw orchestrator
CUSTOMAnything else — self-reported

Environment variables

VariablePurpose
INFERLANE_API_KEYBearer token for InferLane fleet API. Can also be passed via apiKey option.
INFERLANE_BASE_URLOverride base URL (default https://inferlane.dev). Useful for self-hosted InferLane.

Privacy

Hook options include debug: true which logs tool names and session IDs to console.log. Do not enable debug in production — tool names and payloads may contain user data.

The hooks never ship the contents of user prompts or tool inputs to InferLane by default. Only token counts, tool names, active-runtime durations, and web-search counts are recorded. To include tool payloads for debugging purposes, see the advanced configuration.

License

MIT

Keywords

inferlane

FAQs

Package last updated on 11 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts