skalpel 1.0.4 → 1.0.5
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/README.md +146 -66
- package/dist/cli/index.js +0 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/proxy-runner.js +0 -2
- package/dist/cli/proxy-runner.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -1,116 +1,196 @@
|
|
|
1
|
-
# Skalpel
|
|
1
|
+
# Skalpel
|
|
2
2
|
|
|
3
|
-
Optimize
|
|
3
|
+
Optimize Claude Code prompts to reduce credit usage. Skalpel sits between Claude Code and the Anthropic API, optimizing prompts before they reach the provider — saving you money without changing how you work.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## How It Works
|
|
6
6
|
|
|
7
|
-
```bash
|
|
8
|
-
npm install skalpel
|
|
9
7
|
```
|
|
8
|
+
Claude Code --> Skalpel Proxy (local) --> Skalpel Backend (AWS) --> Anthropic API
|
|
9
|
+
Intercepts requests Optimizes prompts Returns response
|
|
10
|
+
Adds tracking headers Reduces token usage
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
1. A local proxy runs on your machine (port 18100)
|
|
14
|
+
2. Claude Code is configured to send API requests to the proxy instead of `api.anthropic.com`
|
|
15
|
+
3. The proxy forwards requests to the Skalpel backend, which optimizes prompts for lower token usage
|
|
16
|
+
4. The optimized request is sent to Anthropic, and the response streams back to Claude Code
|
|
17
|
+
|
|
18
|
+
Your Anthropic API key stays in the request chain — Skalpel never stores it.
|
|
10
19
|
|
|
11
20
|
## Quick Start
|
|
12
21
|
|
|
13
|
-
|
|
22
|
+
One command to install, detect Claude Code, and start optimizing:
|
|
14
23
|
|
|
15
|
-
|
|
24
|
+
```bash
|
|
25
|
+
npx skalpel --api-key sk-skalpel-YOUR_KEY --auto
|
|
26
|
+
```
|
|
16
27
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
28
|
+
This will:
|
|
29
|
+
- Start the local proxy on ports 18100 (Anthropic) and 18101 (OpenAI)
|
|
30
|
+
- Detect Claude Code on your machine
|
|
31
|
+
- Configure `~/.claude/settings.json` with `ANTHROPIC_BASE_URL=http://localhost:18100`
|
|
32
|
+
- Set shell environment variables in your `.bashrc`/`.zshrc`
|
|
33
|
+
- Begin optimizing all Claude Code API traffic immediately
|
|
20
34
|
|
|
21
|
-
|
|
22
|
-
apiKey: process.env.SKALPEL_API_KEY!,
|
|
23
|
-
workspace: 'my-workspace',
|
|
24
|
-
});
|
|
35
|
+
### Interactive Setup
|
|
25
36
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
37
|
+
For a guided setup with prompts:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npx skalpel
|
|
31
41
|
```
|
|
32
42
|
|
|
33
|
-
|
|
43
|
+
The wizard walks you through API key entry, agent detection, and proxy configuration.
|
|
34
44
|
|
|
35
|
-
|
|
45
|
+
### Manual Setup
|
|
36
46
|
|
|
37
|
-
```
|
|
38
|
-
|
|
47
|
+
```bash
|
|
48
|
+
# 1. Start the proxy
|
|
49
|
+
npx skalpel start
|
|
39
50
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
51
|
+
# 2. Configure Claude Code
|
|
52
|
+
npx skalpel agent configure
|
|
43
53
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
54
|
+
# 3. Verify everything is working
|
|
55
|
+
npx skalpel doctor
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## What Gets Configured
|
|
59
|
+
|
|
60
|
+
### Claude Code (`~/.claude/settings.json`)
|
|
61
|
+
|
|
62
|
+
Skalpel adds an environment override so Claude Code routes API calls through the local proxy:
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"env": {
|
|
67
|
+
"ANTHROPIC_BASE_URL": "http://localhost:18100"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
48
70
|
```
|
|
49
71
|
|
|
50
|
-
|
|
72
|
+
### Shell Environment (`~/.bashrc`, `~/.zshrc`)
|
|
73
|
+
|
|
74
|
+
Environment variables are added for tools that read them directly:
|
|
51
75
|
|
|
52
76
|
```bash
|
|
53
|
-
|
|
77
|
+
# BEGIN SKALPEL PROXY - do not edit manually
|
|
78
|
+
export ANTHROPIC_BASE_URL="http://localhost:18100"
|
|
79
|
+
export OPENAI_BASE_URL="http://localhost:18101"
|
|
80
|
+
# END SKALPEL PROXY
|
|
54
81
|
```
|
|
55
82
|
|
|
56
|
-
|
|
83
|
+
### Proxy Config (`~/.skalpel/config.json`)
|
|
57
84
|
|
|
58
|
-
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"apiKey": "sk-skalpel-YOUR_KEY",
|
|
88
|
+
"remoteBaseUrl": "http://skalpel-production-554359744.us-west-2.elb.amazonaws.com",
|
|
89
|
+
"anthropicPort": 18100,
|
|
90
|
+
"openaiPort": 18101
|
|
91
|
+
}
|
|
92
|
+
```
|
|
59
93
|
|
|
60
|
-
|
|
94
|
+
## CLI Commands
|
|
61
95
|
|
|
62
|
-
|
|
96
|
+
| Command | Description |
|
|
97
|
+
|---|---|
|
|
98
|
+
| `npx skalpel` | Run the setup wizard |
|
|
99
|
+
| `npx skalpel start` | Start the proxy |
|
|
100
|
+
| `npx skalpel stop` | Stop the proxy |
|
|
101
|
+
| `npx skalpel status` | Show proxy status and uptime |
|
|
102
|
+
| `npx skalpel doctor` | Verify configuration and connectivity |
|
|
103
|
+
| `npx skalpel logs` | View proxy logs |
|
|
104
|
+
| `npx skalpel logs -f` | Follow proxy logs in real time |
|
|
105
|
+
| `npx skalpel uninstall` | Remove proxy, configs, and shell modifications |
|
|
63
106
|
|
|
64
|
-
###
|
|
107
|
+
### Flags
|
|
65
108
|
|
|
66
|
-
|
|
109
|
+
| Flag | Description |
|
|
110
|
+
|---|---|
|
|
111
|
+
| `--api-key <key>` | Provide Skalpel API key (skips interactive prompt) |
|
|
112
|
+
| `--auto` | Non-interactive mode (requires `--api-key`) |
|
|
67
113
|
|
|
68
|
-
|
|
114
|
+
## Streaming Support
|
|
115
|
+
|
|
116
|
+
Skalpel fully supports Anthropic's SSE streaming protocol. When Claude Code sends a streaming request (`"stream": true`), the proxy:
|
|
117
|
+
|
|
118
|
+
- Detects the streaming flag in the request body
|
|
119
|
+
- Forwards to the backend with all original headers
|
|
120
|
+
- Pipes SSE events (`message_start`, `content_block_delta`, `message_stop`) directly back to Claude Code
|
|
121
|
+
- Preserves upstream headers like `anthropic-request-id`
|
|
122
|
+
|
|
123
|
+
No buffering, no modification of the stream — chunks flow through in real time.
|
|
69
124
|
|
|
70
|
-
|
|
125
|
+
## Headers
|
|
71
126
|
|
|
72
|
-
|
|
127
|
+
The proxy adds these headers to every request forwarded to the Skalpel backend:
|
|
73
128
|
|
|
74
|
-
|
|
129
|
+
| Header | Value | Purpose |
|
|
130
|
+
|---|---|---|
|
|
131
|
+
| `X-Skalpel-API-Key` | Your Skalpel key | Backend authentication |
|
|
132
|
+
| `X-Skalpel-Source` | `claude-code` | Traffic source identification |
|
|
133
|
+
| `X-Skalpel-Agent-Type` | `claude-code` | Agent type for optimization routing |
|
|
134
|
+
| `X-Skalpel-SDK-Version` | `proxy-1.0.0` | SDK version tracking |
|
|
75
135
|
|
|
76
|
-
|
|
136
|
+
The original `x-api-key` header (your Anthropic key) is forwarded as-is.
|
|
77
137
|
|
|
78
|
-
|
|
138
|
+
## Codex Support
|
|
79
139
|
|
|
80
|
-
|
|
81
|
-
- `SkalpelTimeoutError` — request timed out.
|
|
82
|
-
- `SkalpelRateLimitError` (429) — rate limit exceeded, includes `retryAfter`.
|
|
83
|
-
- `SkalpelUnavailableError` (5xx) — proxy unavailable.
|
|
140
|
+
Skalpel also supports OpenAI Codex on port 18101. The same `--auto` flow detects and configures both agents if present.
|
|
84
141
|
|
|
85
|
-
|
|
142
|
+
## SDK Integration
|
|
86
143
|
|
|
87
|
-
|
|
144
|
+
For programmatic use in your own applications:
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
import { createSkalpelClient } from 'skalpel';
|
|
148
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
149
|
+
|
|
150
|
+
const client = createSkalpelClient(new Anthropic(), {
|
|
151
|
+
apiKey: process.env.SKALPEL_API_KEY!,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const response = await client.messages.create({
|
|
155
|
+
model: 'claude-sonnet-4-20250514',
|
|
156
|
+
max_tokens: 1024,
|
|
157
|
+
messages: [{ role: 'user', content: 'Hello' }],
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
See the [API Reference](#api-reference) for all SDK options.
|
|
162
|
+
|
|
163
|
+
## API Reference
|
|
164
|
+
|
|
165
|
+
### `createSkalpelClient<T>(client: T, options: SkalpelClientOptions): T`
|
|
166
|
+
|
|
167
|
+
Wraps an existing OpenAI or Anthropic client. All API calls route through the Skalpel proxy with automatic fallback on errors.
|
|
168
|
+
|
|
169
|
+
### `createSkalpelAnthropic(options): Promise<Anthropic>`
|
|
170
|
+
|
|
171
|
+
Creates a pre-configured Anthropic client pointing at the Skalpel proxy.
|
|
172
|
+
|
|
173
|
+
### `createSkalpelOpenAI(options): Promise<OpenAI>`
|
|
174
|
+
|
|
175
|
+
Creates a pre-configured OpenAI client pointing at the Skalpel proxy.
|
|
176
|
+
|
|
177
|
+
### Configuration Options
|
|
88
178
|
|
|
89
179
|
```typescript
|
|
90
180
|
interface SkalpelClientOptions {
|
|
91
181
|
apiKey: string; // Skalpel API key (sk-skalpel-*)
|
|
92
182
|
workspace?: string; // Workspace ID
|
|
93
|
-
baseURL?: string; // Proxy URL (default:
|
|
183
|
+
baseURL?: string; // Proxy URL (default: production ALB)
|
|
94
184
|
fallbackOnError?: boolean; // Fall back to direct provider (default: true)
|
|
95
185
|
timeout?: number; // Request timeout in ms (default: 30000)
|
|
96
186
|
retries?: number; // Max retries (default: 2)
|
|
97
|
-
headers?: Record<string, string>;// Additional custom headers
|
|
98
|
-
verbose?: boolean; // Log fallback events (default: false)
|
|
99
|
-
onFallback?: (error, provider) => void; // Callback on fallback
|
|
100
|
-
onMetadata?: (metadata) => void; // Callback with optimization info
|
|
101
187
|
}
|
|
102
188
|
```
|
|
103
189
|
|
|
104
|
-
##
|
|
105
|
-
|
|
106
|
-
The SDK is written in TypeScript and ships with full type declarations. All types are exported:
|
|
190
|
+
## Uninstall
|
|
107
191
|
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
SkalpelClientOptions,
|
|
111
|
-
SkalpelMetadata,
|
|
112
|
-
SkalpelConfig,
|
|
113
|
-
SupportedProvider,
|
|
114
|
-
InitConfig,
|
|
115
|
-
} from 'skalpel';
|
|
192
|
+
```bash
|
|
193
|
+
npx skalpel uninstall
|
|
116
194
|
```
|
|
195
|
+
|
|
196
|
+
This removes the proxy, restores `~/.claude/settings.json` from backup, and cleans up shell environment variables.
|