You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add configurable working directory with isolated default (#14)
- Default to temporary directory for security isolation
- Validate directory existence before use (fail gracefully)
- Support CLAUDE_CWD environment variable for custom directories
- Add comprehensive cross-platform tests
- Update Docker configuration for workspace mounting
- Add clear documentation for all configuration options
This prevents Claude Code from accessing the wrapper's source code
by default, enhancing security while maintaining flexibility.
Co-authored-by: George Elphick <george.elphick@talieisin.co.uk>
Copy file name to clipboardExpand all lines: README.md
+60-13Lines changed: 60 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -143,8 +143,40 @@ MAX_TIMEOUT=600000
143
143
144
144
# CORS origins
145
145
CORS_ORIGINS=["*"]
146
+
147
+
# Working directory for Claude Code (optional)
148
+
# If not set, uses an isolated temporary directory for security
149
+
# CLAUDE_CWD=/path/to/your/workspace
146
150
```
147
151
152
+
### 📁 **Working Directory Configuration**
153
+
154
+
By default, Claude Code runs in an **isolated temporary directory** to prevent it from accessing the wrapper's source code. This enhances security by ensuring Claude Code only has access to the workspace you intend.
155
+
156
+
**Configuration Options:**
157
+
158
+
1. **Default (Recommended)**: Automatically creates a temporary isolated workspace
159
+
```bash
160
+
# No configuration needed - secure by default
161
+
poetry run python main.py
162
+
```
163
+
164
+
2. **Custom Directory**: Set a specific workspace directory
165
+
```bash
166
+
export CLAUDE_CWD=/path/to/your/project
167
+
poetry run python main.py
168
+
```
169
+
170
+
3. **Via .env file**: Add to your `.env` file
171
+
```env
172
+
CLAUDE_CWD=/home/user/my-workspace
173
+
```
174
+
175
+
**Important Notes:**
176
+
- The temporary directory is automatically cleaned up when the server stops
177
+
- This prevents Claude Code from accidentally modifying the wrapper's own code
This guide provides a comprehensive overview of building, running, and configuring a Docker container for the Claude Code OpenAI Wrapper. Docker enables isolated, portable, and reproducible deployments of the wrapper, which acts as an OpenAI-compatible API server routing requests to Anthropic's Claude models via the official Claude Code Python SDK (v0.0.14+). This setup supports authentication methods like Claude subscriptions (e.g., Max plan via OAuth for fixed-cost quotas), direct API keys, AWS Bedrock, or Google Vertex AI.
248
280
249
-
By containerizing the application, you can run it locally for development, deploy it to remote servers or cloud platforms, and customize behavior through environment variables and volumes. This guide assumes you have already cloned the repository and have the `Dockerfile` in the root directory. For general repository setup (e.g., Claude Code CLI authentication), refer to the sections above.
281
+
By containerizing the application, you can run it locally for development, deploy it to remote servers or cloud platforms, and customise behaviour through environment variables and volumes. This guide assumes you have already cloned the repository and have the `Dockerfile` in the root directory. For general repository setup (e.g., Claude Code CLI authentication), refer to the sections above.
250
282
251
283
## Prerequisites
252
284
Before building or running the container, ensure the following:
@@ -255,7 +287,7 @@ Before building or running the container, ensure the following:
255
287
- **Hardware and Software**:
256
288
- OS: macOS (10.15+), Linux (e.g., Ubuntu 20.04+), or Windows (10+ with WSL2 for optimal volume mounting).
257
289
- Resources: At least 4GB RAM and 2 CPU cores (Claude requests can be compute-intensive; monitor with `docker stats`).
258
-
- Disk: ~500MB for the image, plus space for volumes.
290
+
- Disc: ~500MB for the image, plus space for volumes.
259
291
- Network: Stable internet for builds (dependency downloads) and runtime (API calls to Anthropic).
260
292
- **Optional**:
261
293
- Docker Compose: For multi-service or easier configuration management. Install via Docker Desktop or your package manager (e.g., `sudo apt install docker-compose`).
@@ -283,7 +315,7 @@ The `Dockerfile` in the root defines a lightweight Python 3.12-based image with
- Platform-Specific (e.g., ARM for Raspberry Pi): `docker build --platform linux/arm64 -t claude-wrapper:arm .`.
286
-
- Multi-Stage for Smaller Size: If optimizing, modify the Dockerfile to use multi-stage builds (e.g., separate build and runtime stages).
318
+
- Multi-Stage for Smaller Size: If optimising, modify the Dockerfile to use multi-stage builds (e.g., separate build and runtime stages).
287
319
288
320
If using Docker Compose (see below), build with `docker-compose build`.
289
321
@@ -301,6 +333,20 @@ docker run -d -p 8000:8000 \
301
333
- `-d`: Detached mode (runs in background).
302
334
- `-p 8000:8000`: Maps host port 8000 to the container's 8000 (change left side for host conflicts, e.g., `-p 9000:8000`).
303
335
- `-v ~/.claude:/root/.claude`: Mounts your host's authentication directory for persistent subscription tokens (essential for Claude Max access).
336
+
- **Working Directory**: By default, Claude Code uses an isolated temp directory inside the container.
337
+
338
+
### Running with Custom Workspace
339
+
To give Claude Code access to a specific directory:
340
+
```bash
341
+
docker run -d -p 8000:8000 \
342
+
-v ~/.claude:/root/.claude \
343
+
-v /path/to/your/project:/workspace \
344
+
-e CLAUDE_CWD=/workspace \
345
+
--name claude-wrapper-container \
346
+
claude-wrapper:latest
347
+
```
348
+
- `-v /path/to/your/project:/workspace`: Mounts your project directory into the container.
349
+
- `-e CLAUDE_CWD=/workspace`: Sets Claude's working directory to the mounted workspace.
304
350
- `--name claude-wrapper-container`: Names the container for easy management.
305
351
306
352
### Development Run with Hot Reload
@@ -345,20 +391,21 @@ services:
345
391
- Cleanup: `docker system prune` to remove unused images/volumes.
346
392
347
393
## Custom Configuration Options
348
-
Customize the container's behavior through environment variables, volumes, and runtime flags. Most changes don't require rebuilding—just restart the container.
394
+
Customise the container's behaviour through environment variables, volumes, and runtime flags. Most changes don't require rebuilding—just restart the container.
349
395
350
396
### Environment Variables
351
-
Env vars override defaults and can be set at runtime with `-e` flags or in `docker-compose.yml` under `environment`. They control auth, server settings, and SDK behavior.
397
+
Env vars override defaults and can be set at runtime with `-e` flags or in`docker-compose.yml` under `environment`. They control auth, server settings, and SDK behaviour.
352
398
353
399
- **Core Server Settings**:
354
400
- `PORT=9000`: Changes the internal listening port (default: 8000; update port mapping accordingly).
355
401
- `MAX_TIMEOUT=600`: Sets the request timeout in seconds (default: 300; increase for complex Claude queries).
402
+
- `CLAUDE_CWD=/path/to/workspace`: Sets Claude Code's working directory (default: isolated temp directory for security).
356
403
357
404
- **Authentication and Providers**:
358
405
- `ANTHROPIC_API_KEY=sk-your-key`: Enables direct API key auth (overrides subscription; generate at console.anthropic.com).
359
406
- `CLAUDE_CODE_USE_VERTEX=true`: Switches to Google Vertex AI (requires additional vars like `GOOGLE_APPLICATION_CREDENTIALS=/path/to/creds.json`—mount the file as a volume).
For persistence across runs, use a `.env` file in the root (e.g., `PORT=8000`) and mount it: `-v $(pwd)/.env:/app/.env`. Load vars in code if required.
377
424
378
-
### Volumes for Data Persistence and Customization
425
+
### Volumes for Data Persistence and Customisation
379
426
Volumes mount host directories/files into the container, enabling persistence and config overrides.
380
427
381
428
- **Authentication Volume (Required for Subscriptions)**: `-v ~/.claude:/root/.claude` – Shares tokens and `settings.json` (edit on host for defaults like `"max_tokens": 8192`; restart container to apply).
@@ -401,7 +448,7 @@ For remote access (e.g., from other machines or production deployment), extend t
401
448
### Exposing Locally for Remote Access
402
449
- Bind to All Interfaces: Already done with `--host 0.0.0.0`.
403
450
- Firewall: Open port 8000 on your host (e.g., `ufw allow 8000` on Ubuntu).
404
-
- Tunneling: Use ngrok for temporary exposure: Install ngrok, run `ngrok http 8000`, and use the public URL.
451
+
- Tunnelling: Use ngrok for temporary exposure: Install ngrok, run `ngrok http 8000`, and use the public URL.
405
452
- Security: Always add `API_KEYS` and use HTTPS (via reverse proxy).
0 commit comments