@tanstack/ai-code-mode-snippets has 1,735 recorded weekly downloads on npm, a decrease of 5.3% over the past 30 days, ranking #1931 of 3,247 tracked listings.
About @tanstack/ai-code-mode-snippets
@tanstack/ai-code-mode-snippets
Persistent snippet library for TanStack AI Code Mode - LLM-created reusable code snippets.
Overview
The Snippets System extends Code Mode with persistent, LLM-creatable reusable code snippets. Snippets are TypeScript functions that the LLM can create, catalog, and invoke across sessions—enabling compounding capability over time.
Installation
pnpm add @tanstack/ai-code-mode-snippets
Usage
import {
codeModeWithSnippets,
createAlwaysTrustedStrategy,
} from '@tanstack/ai-code-mode-snippets'
// Node-only file storage lives behind the `/storage` subpath so the root
// export stays safe for Worker/browser bundlers.
import { createFileSnippetStorage } from '@tanstack/ai-code-mode-snippets/storage'
import { createNodeIsolateDriver } from '@tanstack/ai-isolate-node'
// Create snippet storage
const snippetStorage = createFileSnippetStorage({
directory: './.snippets',
trustStrategy: createAlwaysTrustedStrategy(),
})
// Create code mode config
const codeModeConfig = {
driver: createNodeIsolateDriver(),
tools: allTools, // Your external tools
timeout: 60000,
memoryLimit: 128,
}
// Build a dynamic registry and system prompt with snippets
const { toolsRegistry, systemPrompt, selectedSnippets } =
await codeModeWithSnippets({
config: codeModeConfig,
adapter: anthropic('claude-haiku-4-5'), // Cheap model for snippet selection
snippets: {
storage: snippetStorage,
maxSnippetsInContext: 5,
},
messages,
threadId: 'thread-1',
})
// Use in chat
const stream = chat({
adapter: anthropic('claude-sonnet-4-6'), // Main model
toolRegistry: toolsRegistry,
messages,
threadId: 'thread-1',
systemPrompts: [basePrompt, systemPrompt],
})
Testing
This package includes a CLI for testing the snippets system. The tests verify the complete snippets lifecycle:
- First run (Snippet Creation): LLM uses
execute_typescriptto solve a problem and registers a reusable snippet - Second run (Snippet Reuse): LLM calls the saved snippet directly without needing
execute_typescript
Running the Simulated Test
The simulated test uses a mock adapter with predetermined responses for fully deterministic testing. No API key required.
# From the package directory
cd packages/ai-code-mode-snippets
# Run the simulated test
pnpm test:cli:simulated
Running the Live Test
The live test uses a real LLM (OpenAI or Anthropic) to verify the snippets flow with actual LLM responses.
Setup
-
Copy the environment example file:
cp test-cli/env.example test-cli/.env.local -
Edit
test-cli/.env.localand add your API key:OPENAI_API_KEY=sk-... # or ANTHROPIC_API_KEY=sk-ant-...
Run the test
# Run with OpenAI (default)
pnpm test:cli:live
# Run with Anthropic
pnpm test:cli:live --provider anthropic
# Run with a specific model
pnpm test:cli:live --model gpt-4o-mini
# Run with verbose output
pnpm test:cli:live -v
CLI Commands
# Show help
pnpm test:cli --help
# Run simulated test (deterministic, no API key)
pnpm test:cli simulated
# Run live test (requires API key)
pnpm test:cli live [options]
Options:
--provider <provider> LLM provider: openai or anthropic (default: openai)
--model <model> Model to use (default depends on provider)
-v, --verbose Enable verbose output
API Reference
codeModeWithSnippets(options)
Creates Code Mode tools and system prompt with snippets integration.
Options:
config- Code Mode tool configuration (driver, tools, timeout, memoryLimit)adapter- Text adapter for snippet selection (should be a cheap/fast model)snippets.storage- Snippet storage implementationsnippets.maxSnippetsInContext- Maximum snippets to load into context (default: 5)messages- Current conversation messagesthreadId- Thread id of the conversation (required). The snippet selection chat uses it.snippetsAsTools- Whether to include snippets as direct tools (default: true)
Returns:
toolsRegistry- MutableToolRegistrycontainingexecute_typescript, snippet management tools, and selected snippet toolssystemPrompt- System prompt documenting available snippets and external functionsselectedSnippets- Snippets that were selected for this request
Storage
The worker/browser-safe in-memory storage (createMemorySnippetStorage) is
re-exported from the root entry. The Node-only file storage
(createFileSnippetStorage) imports node:fs / node:path, so it is only
available from the /storage subpath — keeping the root export safe to import
from Cloudflare Workers and browser bundlers:
// Worker/browser-safe — root export
import { createMemorySnippetStorage } from '@tanstack/ai-code-mode-snippets'
// Node-only — `/storage` subpath
import { createFileSnippetStorage } from '@tanstack/ai-code-mode-snippets/storage'
createFileSnippetStorage(options)
Git-friendly file-based storage:
.snippets/
├── compare_react_state_libraries/
│ ├── meta.json # Metadata, schemas, stats
│ └── code.ts # TypeScript implementation
└── fetch_github_stats/
├── meta.json
└── code.ts
createMemorySnippetStorage(options)
In-memory storage for testing.
Trust Strategies
Snippets track execution success and promote trust levels over time:…
Description from the npm listing.
- ai
- ai-sdk
- typescript
- tanstack
- code-mode
- snippets
- agents
- llm
- sandbox
- tool-calling
- tanstack-intent
README badge
Show your rank in a README or on your website. The badge updates automatically.
Charts
Images: 30d · 1y · all time · 1600×900 dark
Adoption over time
7/30/90-day growth
Ranking history
Listing placement
Listing placement
Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.
Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.
Recent observations
Full history (170)Similar npm AI SDKs plugins
All 20 @tanstack/ai-code-mode-snippets alternativesData source
Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.
Listing: https://www.npmjs.com/package/@tanstack/ai-code-mode-snippets. First seen Oct 16, 2026; last successful collection Dec 6, 2026. See the methodology.