claude-code-langcache 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OpenClaw Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,124 @@
1
+ # claude-code-langcache
2
+
3
+ Semantic caching skill for [Claude Code](https://claude.ai/code) using [Redis LangCache](https://redis.io/langcache/).
4
+
5
+ Reduce LLM costs and latency by caching responses for semantically similar queries, with built-in privacy and security guardrails.
6
+
7
+ > **For OpenClaw users:** See [openclaw-langcache](https://www.npmjs.com/package/openclaw-langcache)
8
+
9
+ ## Features
10
+
11
+ - **Semantic similarity matching** - Cache hits for similar (not just identical) queries
12
+ - **Hard block enforcement** - Automatically blocks caching of sensitive data:
13
+ - Temporal info (today, tomorrow, deadlines, appointments)
14
+ - Credentials (API keys, passwords, tokens, OTP)
15
+ - Identifiers (emails, phone numbers, account IDs)
16
+ - Personal context (relationships, private conversations)
17
+ - **Category-aware thresholds** - Different similarity thresholds for factual Q&A vs style transforms
18
+ - **CLI and Python integration** - Use from shell scripts or embed in Python agents
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ npm install -g claude-code-langcache
24
+ ```
25
+
26
+ The skill will be automatically installed to `~/.claude/skills/langcache/`
27
+
28
+ ## Configuration
29
+
30
+ Set your Redis LangCache credentials:
31
+
32
+ ```bash
33
+ export LANGCACHE_HOST=your-instance.redis.cloud
34
+ export LANGCACHE_CACHE_ID=your-cache-id
35
+ export LANGCACHE_API_KEY=your-api-key
36
+ ```
37
+
38
+ Get these from [Redis Cloud Console](https://app.redislabs.com/) after creating a LangCache instance.
39
+
40
+ ## Usage
41
+
42
+ ### Automatic (via Claude Code)
43
+
44
+ The skill triggers automatically when you mention:
45
+ - "cache LLM responses"
46
+ - "semantic caching"
47
+ - "reduce API costs"
48
+ - "configure LangCache"
49
+
50
+ Or invoke manually with `/langcache`
51
+
52
+ ### CLI
53
+
54
+ ```bash
55
+ # Search for cached response
56
+ ~/.claude/skills/langcache/scripts/langcache.sh search "What is Redis?"
57
+
58
+ # With similarity threshold
59
+ ~/.claude/skills/langcache/scripts/langcache.sh search "What is Redis?" --threshold 0.9
60
+
61
+ # Store a response
62
+ ~/.claude/skills/langcache/scripts/langcache.sh store "What is Redis?" "Redis is an in-memory data store..."
63
+
64
+ # Check if content would be blocked
65
+ ~/.claude/skills/langcache/scripts/langcache.sh check "What's on my calendar today?"
66
+ # Output: BLOCKED: temporal_info
67
+ ```
68
+
69
+ ## Caching Policy
70
+
71
+ ### Cacheable (white-list)
72
+
73
+ | Category | Examples | Threshold |
74
+ |----------|----------|-----------|
75
+ | Factual Q&A | "What is X?", "How does Y work?" | 0.90 |
76
+ | Definitions / docs | API docs, command help | 0.90 |
77
+ | Command explanations | "What does `git rebase` do?" | 0.92 |
78
+ | Reply templates | "polite no", "follow-up", "intro" | 0.88 |
79
+ | Style transforms | "make this warmer/shorter" | 0.85 |
80
+
81
+ ### Never Cached (hard blocks)
82
+
83
+ | Category | Examples |
84
+ |----------|----------|
85
+ | Temporal | today, tomorrow, deadline, ETA, "in 20 minutes" |
86
+ | Credentials | API keys, passwords, tokens, OTP/2FA |
87
+ | Identifiers | emails, phone numbers, account IDs, UUIDs |
88
+ | Personal | "my wife said", private conversations, relationships |
89
+
90
+ ## File Structure
91
+
92
+ ```
93
+ ~/.claude/skills/langcache/
94
+ ├── SKILL.md # Skill definition and instructions
95
+ ├── scripts/
96
+ │ └── langcache.sh # CLI wrapper with policy enforcement
97
+ ├── references/
98
+ │ ├── api-reference.md # Complete REST API documentation
99
+ │ └── best-practices.md # Optimization techniques
100
+ └── examples/
101
+ ├── basic-caching.sh # Simple cache workflow
102
+ └── agent-integration.py # Python integration pattern
103
+ ```
104
+
105
+ ## Requirements
106
+
107
+ - Claude Code
108
+ - Redis Cloud account with LangCache enabled
109
+ - Node.js 18+ (for npm installation)
110
+ - `jq` and `curl` (for CLI usage)
111
+
112
+ ## Related Packages
113
+
114
+ - [openclaw-langcache](https://www.npmjs.com/package/openclaw-langcache) - For OpenClaw users
115
+
116
+ ## License
117
+
118
+ MIT License - see [LICENSE](LICENSE) for details.
119
+
120
+ ## Resources
121
+
122
+ - [Redis LangCache Documentation](https://redis.io/docs/latest/develop/ai/langcache/)
123
+ - [Claude Code Documentation](https://docs.anthropic.com/claude-code)
124
+ - [Semantic Caching Guide](https://redis.io/blog/what-is-semantic-caching/)
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "claude-code-langcache",
3
+ "version": "1.0.0",
4
+ "description": "Semantic caching skill for Claude Code using Redis LangCache",
5
+ "keywords": [
6
+ "claude-code",
7
+ "claude",
8
+ "skill",
9
+ "langcache",
10
+ "redis",
11
+ "semantic-caching",
12
+ "llm",
13
+ "ai",
14
+ "cache"
15
+ ],
16
+ "homepage": "https://github.com/manvinder01/claude-code-langcache#readme",
17
+ "bugs": {
18
+ "url": "https://github.com/manvinder01/claude-code-langcache/issues"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/manvinder01/claude-code-langcache.git"
23
+ },
24
+ "license": "MIT",
25
+ "author": {
26
+ "name": "Manvinder Singh"
27
+ },
28
+ "files": [
29
+ "skills/",
30
+ "scripts/",
31
+ "README.md",
32
+ "LICENSE"
33
+ ],
34
+ "scripts": {
35
+ "postinstall": "node scripts/postinstall.js"
36
+ },
37
+ "engines": {
38
+ "node": ">=18.0.0"
39
+ },
40
+ "claude-code": {
41
+ "type": "skill",
42
+ "skills": ["langcache"],
43
+ "installPath": "skills/"
44
+ }
45
+ }
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Postinstall script for claude-code-langcache
4
+ * Installs the skill to Claude Code workspace
5
+ */
6
+
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+ const os = require('os');
10
+
11
+ const SKILL_NAME = 'langcache';
12
+
13
+ function getClaudePath() {
14
+ const home = os.homedir();
15
+ return path.join(
16
+ process.env.CLAUDE_HOME || path.join(home, '.claude'),
17
+ 'skills'
18
+ );
19
+ }
20
+
21
+ function copyDir(src, dest) {
22
+ fs.mkdirSync(dest, { recursive: true });
23
+ const entries = fs.readdirSync(src, { withFileTypes: true });
24
+
25
+ for (const entry of entries) {
26
+ const srcPath = path.join(src, entry.name);
27
+ const destPath = path.join(dest, entry.name);
28
+
29
+ if (entry.isDirectory()) {
30
+ copyDir(srcPath, destPath);
31
+ } else {
32
+ fs.copyFileSync(srcPath, destPath);
33
+ if (entry.name.endsWith('.sh') || entry.name.endsWith('.py')) {
34
+ fs.chmodSync(destPath, 0o755);
35
+ }
36
+ }
37
+ }
38
+ }
39
+
40
+ function main() {
41
+ console.log('\n📦 Installing langcache skill for Claude Code...\n');
42
+
43
+ try {
44
+ const skillsPath = getClaudePath();
45
+ const destPath = path.join(skillsPath, SKILL_NAME);
46
+ const packageRoot = path.dirname(__dirname);
47
+ const srcPath = path.join(packageRoot, 'skills', SKILL_NAME);
48
+
49
+ if (!fs.existsSync(srcPath)) {
50
+ console.log('Source skill not found, skipping');
51
+ return;
52
+ }
53
+
54
+ fs.mkdirSync(skillsPath, { recursive: true });
55
+
56
+ if (fs.existsSync(destPath)) {
57
+ console.log(`⚠ Skill already exists at ${destPath}`);
58
+ console.log(' To update: rm -rf ~/.claude/skills/langcache && npm install -g claude-code-langcache');
59
+ return;
60
+ }
61
+
62
+ copyDir(srcPath, destPath);
63
+
64
+ console.log(`✓ Installed to ${destPath}\n`);
65
+ console.log('Next steps:');
66
+ console.log('1. Set your Redis LangCache credentials:');
67
+ console.log(' export LANGCACHE_HOST=your-instance.redis.cloud');
68
+ console.log(' export LANGCACHE_CACHE_ID=your-cache-id');
69
+ console.log(' export LANGCACHE_API_KEY=your-api-key');
70
+ console.log('');
71
+ console.log('2. The skill auto-activates when you mention "semantic caching"');
72
+ console.log(' or invoke manually with /langcache\n');
73
+
74
+ } catch (err) {
75
+ console.warn(`⚠ Warning: ${err.message}`);
76
+ console.warn('Manually copy from node_modules/claude-code-langcache/skills/');
77
+ }
78
+ }
79
+
80
+ main();
@@ -0,0 +1,173 @@
1
+ ---
2
+ name: langcache
3
+ description: This skill should be used when the user asks to "enable semantic caching", "cache LLM responses", "reduce API costs", "speed up AI responses", "configure LangCache", "check the cache", or mentions Redis LangCache, semantic similarity caching, or LLM response caching. Provides integration with Redis LangCache managed service for semantic caching of prompts and responses.
4
+ version: 1.0.0
5
+ tools: Read, Bash, WebFetch
6
+ ---
7
+
8
+ # Redis LangCache Semantic Caching
9
+
10
+ Integrate [Redis LangCache](https://redis.io/langcache/) for semantic caching of LLM prompts and responses. Reduces costs and latency by returning cached results for semantically similar queries.
11
+
12
+ ## Prerequisites
13
+
14
+ Set credentials in environment or `~/.claude/settings.local.json`:
15
+
16
+ ```bash
17
+ export LANGCACHE_HOST=your-instance.redis.cloud
18
+ export LANGCACHE_CACHE_ID=your-cache-id
19
+ export LANGCACHE_API_KEY=your-api-key
20
+ ```
21
+
22
+ ## Quick Reference
23
+
24
+ | Operation | Command |
25
+ |-----------|---------|
26
+ | Search cache | `./scripts/langcache.sh search "query"` |
27
+ | Store response | `./scripts/langcache.sh store "prompt" "response"` |
28
+ | Check if blocked | `./scripts/langcache.sh check "text"` |
29
+ | Delete entry | `./scripts/langcache.sh delete --id <id>` |
30
+ | Flush cache | `./scripts/langcache.sh flush` |
31
+
32
+ ## Default Caching Policy
33
+
34
+ This policy is **enforced automatically** by the CLI and integration code.
35
+
36
+ ### CACHEABLE (white-list)
37
+
38
+ | Category | Examples | Threshold |
39
+ |----------|----------|-----------|
40
+ | Factual Q&A | "What is X?", "How does Y work?" | 0.90 |
41
+ | Definitions / docs | API docs, command help | 0.90 |
42
+ | Command explanations | "What does `git rebase` do?" | 0.92 |
43
+ | Reply templates | "polite no", "follow-up", "intro" | 0.88 |
44
+ | Style transforms | "make this warmer/shorter" | 0.85 |
45
+
46
+ ### NEVER CACHE (hard blocks)
47
+
48
+ | Category | Patterns | Reason |
49
+ |----------|----------|--------|
50
+ | **Temporal** | today, tomorrow, deadline, ETA, "in 20 min" | Stale immediately |
51
+ | **Credentials** | API keys, passwords, tokens, OTP/2FA | Security |
52
+ | **Identifiers** | emails, phones, account IDs, UUIDs | Privacy/PII |
53
+ | **Personal** | "my wife said", relationships, private chats | Privacy |
54
+
55
+ ## Core Operations
56
+
57
+ ### Search for Cached Response
58
+
59
+ Before calling an LLM, check for semantically similar cached response:
60
+
61
+ ```bash
62
+ # Basic search
63
+ ./scripts/langcache.sh search "What is semantic caching?"
64
+
65
+ # With similarity threshold (0.0-1.0, higher = stricter)
66
+ ./scripts/langcache.sh search "What is semantic caching?" --threshold 0.95
67
+
68
+ # With attribute filtering
69
+ ./scripts/langcache.sh search "query" --attr "model=gpt-5"
70
+ ```
71
+
72
+ **Response (hit):**
73
+ ```json
74
+ {"hit": true, "response": "...", "similarity": 0.94, "entryId": "abc123"}
75
+ ```
76
+
77
+ **Response (miss):**
78
+ ```json
79
+ {"hit": false}
80
+ ```
81
+
82
+ **Response (blocked):**
83
+ ```json
84
+ {"hit": false, "blocked": true, "reason": "temporal_info"}
85
+ ```
86
+
87
+ ### Store New Response
88
+
89
+ After LLM call, cache for future use:
90
+
91
+ ```bash
92
+ # Basic store
93
+ ./scripts/langcache.sh store "What is Redis?" "Redis is an in-memory data store..."
94
+
95
+ # With attributes for organization/filtering
96
+ ./scripts/langcache.sh store "prompt" "response" --attr "model=gpt-5" --attr "category=factual"
97
+ ```
98
+
99
+ ### Check Policy Compliance
100
+
101
+ Test if content would be blocked:
102
+
103
+ ```bash
104
+ ./scripts/langcache.sh check "What's on my calendar today?"
105
+ # Output: BLOCKED: temporal_info
106
+
107
+ ./scripts/langcache.sh check "What is Redis?"
108
+ # Output: ALLOWED: Content can be cached
109
+ ```
110
+
111
+ ### Delete Entries
112
+
113
+ ```bash
114
+ # By ID
115
+ ./scripts/langcache.sh delete --id "abc123"
116
+
117
+ # By attributes (bulk)
118
+ ./scripts/langcache.sh delete --attr "model=gpt-4"
119
+ ```
120
+
121
+ ### Flush Cache
122
+
123
+ ```bash
124
+ ./scripts/langcache.sh flush # Interactive confirmation
125
+ ```
126
+
127
+ ## Integration Pattern
128
+
129
+ Recommended cache-aside pattern for agent workflows:
130
+
131
+ ```
132
+ 1. Receive user prompt
133
+ 2. Check policy: is it cacheable?
134
+ - If blocked → skip cache, call LLM
135
+ 3. Search LangCache for similar cached response
136
+ - If hit (similarity ≥ threshold) → return cached
137
+ 4. Call LLM API
138
+ 5. Store prompt + response in LangCache
139
+ 6. Return response
140
+ ```
141
+
142
+ ## Search Strategies
143
+
144
+ | Strategy | Description |
145
+ |----------|-------------|
146
+ | `semantic` (default) | Vector similarity matching |
147
+ | `exact` | Case-insensitive exact match |
148
+ | `exact,semantic` | Try exact first, fall back to semantic |
149
+
150
+ ```bash
151
+ ./scripts/langcache.sh search "query" --strategy "exact,semantic"
152
+ ```
153
+
154
+ ## Attributes for Cache Partitioning
155
+
156
+ Use attributes to organize and filter cache entries:
157
+
158
+ | Attribute | Purpose |
159
+ |-----------|---------|
160
+ | `model` | Separate caches per LLM model |
161
+ | `category` | `factual`, `template`, `style`, `command` |
162
+ | `version` | Invalidate when prompts change |
163
+ | `user_id` | Per-user isolation (if needed) |
164
+
165
+ ## References
166
+
167
+ - [API Reference](references/api-reference.md) - Complete REST API documentation
168
+ - [Best Practices](references/best-practices.md) - Optimization techniques
169
+
170
+ ## Examples
171
+
172
+ - [examples/basic-caching.sh](examples/basic-caching.sh) - Shell workflow
173
+ - [examples/agent-integration.py](examples/agent-integration.py) - Python pattern with policy enforcement