skalpel 1.3.0 → 2.0.1
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 +21 -0
- package/README.md +138 -66
- package/dist/cli/index.js +913 -21
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/proxy-runner.js +75 -28
- package/dist/cli/proxy-runner.js.map +1 -1
- package/dist/index.cjs +86 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +86 -35
- package/dist/index.js.map +1 -1
- package/dist/proxy/index.cjs +76 -28
- package/dist/proxy/index.cjs.map +1 -1
- package/dist/proxy/index.d.cts +1 -0
- package/dist/proxy/index.d.ts +1 -0
- package/dist/proxy/index.js +76 -28
- package/dist/proxy/index.js.map +1 -1
- package/package.json +25 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Skalpel AI
|
|
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
CHANGED
|
@@ -1,116 +1,188 @@
|
|
|
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 coding agents on your machine
|
|
31
|
+
- Configure Claude Code and Codex agents automatically
|
|
32
|
+
- Set shell environment variables in your `.bashrc`/`.zshrc`
|
|
33
|
+
- Begin optimizing 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. Run the setup wizard to configure Claude Code
|
|
52
|
+
npx skalpel setup
|
|
43
53
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
messages: [{ role: 'user', content: 'Hello' }],
|
|
47
|
-
});
|
|
54
|
+
# 3. Verify everything is working
|
|
55
|
+
npx skalpel doctor
|
|
48
56
|
```
|
|
49
57
|
|
|
50
|
-
##
|
|
58
|
+
## What Gets Configured
|
|
59
|
+
|
|
60
|
+
### Claude Code
|
|
61
|
+
|
|
62
|
+
Claude Code is auto-configured during setup. `ANTHROPIC_BASE_URL` is set in `~/.claude/settings.json` to route API calls through the proxy. Only API endpoints (`/v1/messages`, `/v1/complete`) are routed through Skalpel for optimization; auth endpoints pass directly to Anthropic.
|
|
63
|
+
|
|
64
|
+
### Shell Environment (`~/.bashrc`, `~/.zshrc`)
|
|
65
|
+
|
|
66
|
+
Environment variables are added for tools that read them directly:
|
|
51
67
|
|
|
52
68
|
```bash
|
|
53
|
-
|
|
69
|
+
# BEGIN SKALPEL PROXY - do not edit manually
|
|
70
|
+
export ANTHROPIC_BASE_URL="http://localhost:18100"
|
|
71
|
+
export OPENAI_BASE_URL="http://localhost:18101"
|
|
72
|
+
# END SKALPEL PROXY
|
|
54
73
|
```
|
|
55
74
|
|
|
56
|
-
|
|
75
|
+
### Proxy Config (`~/.skalpel/config.json`)
|
|
57
76
|
|
|
58
|
-
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"apiKey": "sk-skalpel-YOUR_KEY",
|
|
80
|
+
"remoteBaseUrl": "http://skalpel-production-554359744.us-west-2.elb.amazonaws.com",
|
|
81
|
+
"anthropicPort": 18100,
|
|
82
|
+
"openaiPort": 18101
|
|
83
|
+
}
|
|
84
|
+
```
|
|
59
85
|
|
|
60
|
-
|
|
86
|
+
## CLI Commands
|
|
61
87
|
|
|
62
|
-
|
|
88
|
+
| Command | Description |
|
|
89
|
+
|---|---|
|
|
90
|
+
| `npx skalpel` | Run the setup wizard |
|
|
91
|
+
| `npx skalpel start` | Start the proxy |
|
|
92
|
+
| `npx skalpel stop` | Stop the proxy |
|
|
93
|
+
| `npx skalpel status` | Show proxy status and uptime |
|
|
94
|
+
| `npx skalpel doctor` | Verify configuration and connectivity |
|
|
95
|
+
| `npx skalpel logs` | View proxy logs |
|
|
96
|
+
| `npx skalpel logs -f` | Follow proxy logs in real time |
|
|
97
|
+
| `npx skalpel uninstall` | Remove proxy, configs, and shell modifications |
|
|
63
98
|
|
|
64
|
-
###
|
|
99
|
+
### Flags
|
|
65
100
|
|
|
66
|
-
|
|
101
|
+
| Flag | Description |
|
|
102
|
+
|---|---|
|
|
103
|
+
| `--api-key <key>` | Provide Skalpel API key (skips interactive prompt) |
|
|
104
|
+
| `--auto` | Non-interactive mode (requires `--api-key`) |
|
|
67
105
|
|
|
68
|
-
|
|
106
|
+
## Streaming Support
|
|
69
107
|
|
|
70
|
-
|
|
108
|
+
Skalpel fully supports Anthropic's SSE streaming protocol. When Claude Code sends a streaming request (`"stream": true`), the proxy:
|
|
71
109
|
|
|
72
|
-
|
|
110
|
+
- Detects the streaming flag in the request body
|
|
111
|
+
- Forwards to the backend with all original headers
|
|
112
|
+
- Pipes SSE events (`message_start`, `content_block_delta`, `message_stop`) directly back to Claude Code
|
|
113
|
+
- Preserves upstream headers like `anthropic-request-id`
|
|
73
114
|
|
|
74
|
-
|
|
115
|
+
No buffering, no modification of the stream — chunks flow through in real time.
|
|
75
116
|
|
|
76
|
-
##
|
|
117
|
+
## Headers
|
|
77
118
|
|
|
78
|
-
The
|
|
119
|
+
The proxy adds these headers to every request forwarded to the Skalpel backend:
|
|
79
120
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
- `
|
|
121
|
+
| Header | Value | Purpose |
|
|
122
|
+
|---|---|---|
|
|
123
|
+
| `X-Skalpel-API-Key` | Your Skalpel key | Backend authentication |
|
|
124
|
+
| `X-Skalpel-Source` | `claude-code` | Traffic source identification |
|
|
125
|
+
| `X-Skalpel-Agent-Type` | `claude-code` | Agent type for optimization routing |
|
|
126
|
+
| `X-Skalpel-SDK-Version` | `proxy-1.0.0` | SDK version tracking |
|
|
84
127
|
|
|
85
|
-
|
|
128
|
+
The original `x-api-key` header (your Anthropic key) is forwarded as-is.
|
|
86
129
|
|
|
87
|
-
##
|
|
130
|
+
## Codex Support
|
|
131
|
+
|
|
132
|
+
Skalpel also supports OpenAI Codex on port 18101. The same `--auto` flow detects and configures both agents if present.
|
|
133
|
+
|
|
134
|
+
## SDK Integration
|
|
135
|
+
|
|
136
|
+
For programmatic use in your own applications:
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
import { createSkalpelClient } from 'skalpel';
|
|
140
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
141
|
+
|
|
142
|
+
const client = createSkalpelClient(new Anthropic(), {
|
|
143
|
+
apiKey: process.env.SKALPEL_API_KEY!,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const response = await client.messages.create({
|
|
147
|
+
model: 'claude-sonnet-4-20250514',
|
|
148
|
+
max_tokens: 1024,
|
|
149
|
+
messages: [{ role: 'user', content: 'Hello' }],
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
See the [API Reference](#api-reference) for all SDK options.
|
|
154
|
+
|
|
155
|
+
## API Reference
|
|
156
|
+
|
|
157
|
+
### `createSkalpelClient<T>(client: T, options: SkalpelClientOptions): T`
|
|
158
|
+
|
|
159
|
+
Wraps an existing OpenAI or Anthropic client. All API calls route through the Skalpel proxy with automatic fallback on errors.
|
|
160
|
+
|
|
161
|
+
### `createSkalpelAnthropic(options): Promise<Anthropic>`
|
|
162
|
+
|
|
163
|
+
Creates a pre-configured Anthropic client pointing at the Skalpel proxy.
|
|
164
|
+
|
|
165
|
+
### `createSkalpelOpenAI(options): Promise<OpenAI>`
|
|
166
|
+
|
|
167
|
+
Creates a pre-configured OpenAI client pointing at the Skalpel proxy.
|
|
168
|
+
|
|
169
|
+
### Configuration Options
|
|
88
170
|
|
|
89
171
|
```typescript
|
|
90
172
|
interface SkalpelClientOptions {
|
|
91
173
|
apiKey: string; // Skalpel API key (sk-skalpel-*)
|
|
92
174
|
workspace?: string; // Workspace ID
|
|
93
|
-
baseURL?: string; // Proxy URL (default:
|
|
175
|
+
baseURL?: string; // Proxy URL (default: production ALB)
|
|
94
176
|
fallbackOnError?: boolean; // Fall back to direct provider (default: true)
|
|
95
177
|
timeout?: number; // Request timeout in ms (default: 30000)
|
|
96
178
|
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
179
|
}
|
|
102
180
|
```
|
|
103
181
|
|
|
104
|
-
##
|
|
105
|
-
|
|
106
|
-
The SDK is written in TypeScript and ships with full type declarations. All types are exported:
|
|
182
|
+
## Uninstall
|
|
107
183
|
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
SkalpelClientOptions,
|
|
111
|
-
SkalpelMetadata,
|
|
112
|
-
SkalpelConfig,
|
|
113
|
-
SupportedProvider,
|
|
114
|
-
InitConfig,
|
|
115
|
-
} from 'skalpel';
|
|
184
|
+
```bash
|
|
185
|
+
npx skalpel uninstall
|
|
116
186
|
```
|
|
187
|
+
|
|
188
|
+
This removes the proxy and cleans up shell environment variables. If a previous version of Skalpel modified `~/.claude/settings.json`, uninstall will also clean up those changes.
|