npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@contextwindow/sdk

v0.5.2

Published

ContextWindow SDK - Persistent memory for AI agents

Readme

@contextwindow/sdk

Persistent memory for AI agents. Store, recall, and manage user context across conversations.

npm version License: MIT Early Access

Early Access — ContextWindow is in early access. The API is stable but we're actively adding features. Found a bug or have a feature request? Report it here.

Install

npm install @contextwindow/sdk

Quick Start

import { ContextWindow } from '@contextwindow/sdk';

const cw = new ContextWindow({ apiKey: 'cw_...' });
const user = cw.withUser('user_123');

// Store memories
await user.remember([
  { content: 'Prefers dark mode', type: 'preference' },
  { content: 'Works at Acme Corp', type: 'fact' },
]);

// Recall relevant memories
const { memories } = await user.recall('What does the user prefer?');
console.log(memories[0].content); // "Prefers dark mode"
console.log(memories[0].score);   // 0.94

// Get a formatted string ready for your system prompt
const context = await user.recallForPrompt('user context');
// "You know this about the user:\n- Prefers dark mode\n- Works at Acme Corp"

Use with OpenAI

import { ContextWindow, openaiTools, handleToolCall } from '@contextwindow/sdk';
import OpenAI from 'openai';

const cw = new ContextWindow({ apiKey: 'cw_...' });
const user = cw.withUser('user_123');
const openai = new OpenAI();

// Give the AI memory abilities
const res = await openai.chat.completions.create({
  model: 'gpt-4o',
  messages: [{ role: 'user', content: 'Remember that I like sushi' }],
  tools: openaiTools,
});

// Execute tool calls automatically
for (const tc of res.choices[0].message.tool_calls ?? []) {
  await handleToolCall(user, tc.function.name, JSON.parse(tc.function.arguments));
}

Use with Claude

import { ContextWindow, claudeTools, handleToolCall } from '@contextwindow/sdk';
import Anthropic from '@anthropic-ai/sdk';

const cw = new ContextWindow({ apiKey: 'cw_...' });
const user = cw.withUser('user_123');
const anthropic = new Anthropic();

const res = await anthropic.messages.create({
  model: 'claude-sonnet-4-20250514',
  max_tokens: 1024,
  messages: [{ role: 'user', content: 'Remember that I like sushi' }],
  tools: claudeTools,
});

for (const block of res.content) {
  if (block.type === 'tool_use') {
    await handleToolCall(user, block.name, block.input);
  }
}

Ingest Conversations

Send full conversations and let ContextWindow extract facts automatically:

await user.ingest([
  { role: 'user', content: 'I just moved to Tokyo' },
  { role: 'assistant', content: "That's exciting!" },
  { role: 'user', content: "I'm starting at Google next month" },
]);

// Automatically extracts:
// → "User moved to Tokyo" (event)
// → "User starting at Google" (fact)

Smart Routing

Route messages to the optimal model automatically. Simple messages go to a fast, cheap model. Complex messages go to a powerful model. The SDK detects your provider (OpenAI or Anthropic) and picks the right model for each.

// No model needed — smart routing is on by default
const result = await user.runWithTools({
  client: anthropic,
  // autoRoute is on by default — picks the best model per message
  messages: [{ role: 'user', content: 'Hi, I need to refill my prescription' }],
  tools: [...claudeTools, ...myTools],
  onToolCall: (name, args) => handleMyTool(name, args),
});

// Force a specific model when needed:
const result2 = await user.runWithTools({
  client: anthropic,
  model: 'claude-sonnet-4-6',  // model takes priority over autoRoute
  messages: [...],
  tools: [...],
});

For plan limits, classification details, and full configuration: Smart Routing docs →

API Methods

| Method | Description | |--------|-------------| | withUser(userId) | Create a scoped client — no need to pass userId on every call | | remember(facts) | Store facts, preferences, events | | recall(query, options?) | Semantic search over memories | | recallForPrompt(query) | Recall + format as system prompt string | | forget(options) | Delete by ID or filter | | ingest(conversation) | Extract facts from conversations automatically | | list(options?) | Paginated listing with filters | | route(message) | Smart model routing — returns tier + recommended model | | usage() | Current plan usage and limits |

Configuration

const cw = new ContextWindow({
  apiKey: 'cw_...',                              // Required
  baseUrl: 'https://api.mycontextwindow.com',     // Optional (default)
  debug: false,                                   // Optional — log SDK activity
  retry: {                                        // Optional — built-in retry
    maxRetries: 3,                                // Default: 3
    initialDelay: 500,                            // Default: 500ms
    maxDelay: 10000,                              // Default: 10s
  },
});

Documentation

For advanced configuration, all method parameters, response types, and integration guides:

Read the full documentation →

License

MIT