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

@satoshibits/claude-skill-runtime

v1.0.1

Published

Runtime library for Claude Code auto-loading skills - shared matching algorithms, config loading, and session state management

Readme

@satoshibits/claude-skill-runtime

Runtime library for Claude Code auto-loading skills. Provides shared matching algorithms, config loading, and session state management.

Overview

This package eliminates code duplication between the CLI (@satoshibits/create-auto-loading-claude-skills) and scaffolded hook templates. Bug fixes and improvements can be applied via npm update without regenerating hooks.

Installation

npm install @satoshibits/claude-skill-runtime
# or
pnpm add @satoshibits/claude-skill-runtime

API Reference

Config Loading

import { ConfigLoader, getLogger } from "@satoshibits/claude-skill-runtime";

const projectDir = "/path/to/project";
const loader = new ConfigLoader(projectDir);
const config = loader.loadSkillRules();
const logger = getLogger(projectDir, config);

Rule Matching

import { RuleMatcher } from "@satoshibits/claude-skill-runtime";

const matcher = new RuleMatcher(config, projectRoot);

// Match prompt triggers (optionally include modified files for file-based triggers)
const promptMatches = matcher.matchPrompt("create a new API endpoint", [
  "/src/api/users.ts",
]);

// Match shadow triggers (suggestions without auto-loading)
const shadowMatches = matcher.matchShadowTriggers(
  "still failing after many attempts",
);

// Match pre-tool triggers (before tool execution)
const preToolMatches = matcher.matchPreToolTriggers(
  "Bash",
  'git commit -m "fix"',
);

// Match stop triggers (when Claude completes work)
const stopMatches = matcher.matchStopTriggers("I have fixed the bug");

Session State

import { sessionState } from "@satoshibits/claude-skill-runtime";

const sessionId = "my-session-id";

// Track modified files
sessionState.addModifiedFile(sessionId, "/src/api/users.ts");

// Track activated skills
sessionState.recordSkillActivation(sessionId, "backend-dev-guidelines");

// Get session data
const files = sessionState.getModifiedFiles(sessionId);
const skills = sessionState.getActivatedSkills(sessionId);

Shadow Triggers

import {
  convertMatchesToSuggestions,
  formatShadowSuggestions,
} from "@satoshibits/claude-skill-runtime";

// Convert matches to user-facing suggestions
const suggestions = convertMatchesToSuggestions(shadowMatches);

// Format for output
const formatted = formatShadowSuggestions(suggestions);

Path Utilities

import {
  normalizeFilePath,
  normalizeFilePaths,
  resolveFilePath,
} from "@satoshibits/claude-skill-runtime";

const normalized = normalizeFilePath("/path/to/file.ts", projectRoot);
const resolved = resolveFilePath("src/api/users.ts", projectRoot);

Debug Logging

import {
  createLogger,
  createNoopLogger,
} from "@satoshibits/claude-skill-runtime";

const logger = createLogger("/path/to/project", true, [
  "activation",
  "scoring",
]);

logger.log("activation", "Skill matched", { skillName: "backend-dev" });

Hook Utilities

Shared utilities for hook templates - eliminates code duplication across hooks.

import {
  handleHookError,
  initHookContext,
  readStdin,
} from "@satoshibits/claude-skill-runtime";

import type { HookContext } from "@satoshibits/claude-skill-runtime";

// Read JSON input from stdin
const input = await readStdin();
const data = JSON.parse(input);

// Initialize standard hook context (projectDir, config, logger)
const { projectDir, configLoader, config, logger } = initHookContext({
  workingDirectory: data.working_directory,
});

// Handle errors consistently across hooks
try {
  // ... hook logic
} catch (error) {
  handleHookError(error, logger, { hookName: "PreToolUse", debugOutput: true });
  process.exit(0);
}

Pattern Utilities

Shared utilities for regex pattern handling.

import {
  extractPatternFields,
  extractValidationRulePatterns,
  validatePattern,
} from "@satoshibits/claude-skill-runtime";

// Extract all pattern fields from a skill rule
for (const { fieldPath, patterns } of extractPatternFields(rule)) {
  for (const pattern of patterns) {
    const error = validatePattern(pattern, "i");
    if (error) console.error(`Invalid pattern in ${fieldPath}: ${error}`);
  }
}

// Extract patterns from validation rules
for (const { fieldPath, patterns, flags } of extractValidationRulePatterns(
  rule.validationRules,
)) {
  // ...
}

Config Factory

import { createDefaultConfig } from "@satoshibits/claude-skill-runtime";

// Create a new default config structure
const config = createDefaultConfig();

Pattern Validation

import { validateRegexPatterns } from "@satoshibits/claude-skill-runtime";

const errors = validateRegexPatterns(config);
if (errors.length > 0) {
  console.error("Invalid patterns:", errors);
}

Types

import type {
  DebugLogger,
  // Hook output types
  GuaranteedSkillInfo,
  HandleHookErrorOptions,
  // Hook utilities
  HookContext,
  HookShadowSuggestion,
  InitHookContextOptions,
  LogCategory,
  // Pattern utilities
  PatternField,
  PostToolUseOutput,
  PreToolMatch,
  PreToolUseOutput,
  SessionData,
  ShadowMatch,
  ShadowSuggestion,
  SkillConfig,
  SkillMatch,
  // Core types
  SkillRule,
  StopHookOutput,
  StopMatch,
  UserPromptSubmitOutput,
  ValidationRule,
  ValidationRulePatternField,
} from "@satoshibits/claude-skill-runtime";

Architecture

This library is designed for stateless hook execution. Per Claude Code's hook architecture:

  • Hooks are one-way output pipelines (stdin JSON -> processing -> stdout JSON)
  • Hooks cannot receive user feedback or track preferences across prompts
  • Session state persists to disk for cross-process continuity

The library provides deterministic pattern matching while respecting these constraints.

License

MIT