Skip to content

Latest commit

 

History

History
50 lines (38 loc) · 1.03 KB

File metadata and controls

50 lines (38 loc) · 1.03 KB

Example Usage

Run the example consumer:

npm run example

What it does:

  • creates a shellprint instance with default hook matchers
  • runs a real Agent SDK query()
  • logs each emitted event through onEvent
  • writes JSONL output to shellprint-example-events.jsonl

Main example file:

Core integration pattern:

import { query } from "@anthropic-ai/claude-agent-sdk";
import { createShellPrint } from "shellprint";

const shellprint = createShellPrint({
  jsonlPath: "./shellprint-example-events.jsonl",
  onEvent(event) {
    console.log(event.action, event.description);
  },
});

const result = query({
  prompt: "Research this deal...",
  options: {
    hooks: {
      PreToolUse: [shellprint.preToolMatcher],
      PostToolUse: [shellprint.postToolMatcher],
      PostToolUseFailure: [shellprint.failureMatcher],
    },
  },
});

for await (const message of result) {
  // existing handling unchanged
}

await shellprint.flush();
const events = shellprint.getEvents();