Skip to content

Commit fce40fa

Browse files
authored
Add Nix development environment and Claude guidance file (#4)
# Add Nix development environment and Claude.ai integration This PR adds support for Nix development environments and improves Claude.ai integration: 1. Added a `CLAUDE.md` file that provides guidance to Claude Code when working with this repository, including: - Project overview and architecture explanation - Development commands and testing instructions - Environment variable documentation 2. Added Nix development environment support: - Created `flake.nix` and `flake.lock` for reproducible development environments - Configured development shell with bun, nodejs, and code quality tools - Added treefmt integration for consistent code formatting 3. Updated `.gitignore` to exclude Nix-related files: - `.direnv` - `.envrc` - `.claude` These changes make it easier for developers using Nix to contribute to the project and improve the experience when using Claude Code with this repository.
2 parents 8639be0 + 46362ef commit fce40fa

File tree

6 files changed

+224
-2
lines changed

6 files changed

+224
-2
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
3232

3333
# Finder (MacOS) folder config
3434
.DS_Store
35+
36+
.direnv
37+
.envrc
38+
.claude

CLAUDE.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
anyclaude is a proxy wrapper for Claude Code that enables using alternative LLM providers (OpenAI, Google, xAI, Azure) through the Anthropic API format. It intercepts Anthropic API calls and translates them to/from the Vercel AI SDK format for the specified provider.
8+
9+
## Architecture
10+
11+
The proxy works by:
12+
13+
1. Spawning a local HTTP server that mimics the Anthropic API
14+
2. Intercepting `/v1/messages` requests containing `<provider>/<model>` format
15+
3. Converting Anthropic message format to AI SDK format
16+
4. Routing to the appropriate provider (OpenAI, Google, xAI, Azure)
17+
5. Converting responses back to Anthropic format
18+
6. Setting `ANTHROPIC_BASE_URL` to point Claude Code at the proxy
19+
20+
Key components:
21+
22+
- `src/main.ts`: Entry point that sets up providers and spawns Claude with proxy
23+
- `src/anthropic-proxy.ts`: HTTP server that handles request/response translation
24+
- `src/convert-anthropic-messages.ts`: Bidirectional message format conversion
25+
- `src/convert-to-anthropic-stream.ts`: Stream response conversion
26+
- `src/json-schema.ts`: Schema adaptation for different providers
27+
28+
## Development Commands
29+
30+
```bash
31+
# Install dependencies
32+
bun install
33+
34+
# Build the project (creates dist/main.js with shebang)
35+
bun run build
36+
37+
# The build command:
38+
# 1. Compiles TypeScript to CommonJS for Node.js compatibility
39+
# 2. Adds Node shebang for CLI execution
40+
```
41+
42+
## Testing
43+
44+
Test the proxy manually:
45+
46+
```bash
47+
# Run in proxy-only mode to get the URL
48+
PROXY_ONLY=true bun run src/main.ts
49+
50+
# Test with a provider
51+
OPENAI_API_KEY=your-key bun run src/main.ts --model openai/gpt-4
52+
```
53+
54+
## Environment Variables
55+
56+
Required for each provider:
57+
58+
- `OPENAI_API_KEY` + optional `OPENAI_API_URL` for OpenAI/OpenRouter
59+
- `GOOGLE_API_KEY` + optional `GOOGLE_API_URL` for Google
60+
- `XAI_API_KEY` + optional `XAI_API_URL` for xAI
61+
- `AZURE_API_KEY` + optional `AZURE_API_URL` for Azure
62+
- `ANTHROPIC_API_KEY` + optional `ANTHROPIC_API_URL` for Anthropic passthrough
63+
64+
Special modes:
65+
66+
- `PROXY_ONLY=true`: Run proxy server without spawning Claude Code
67+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Use Claude Code with OpenAI, Google, xAI, and other providers.
1414

1515
```sh
1616
# Use your favorite package manager (bun, pnpm, and npm are supported)
17-
$ pnpm install -g anyclaude
17+
$ pnpm install -g anyclaude
1818

1919
# anyclaude is a wrapper for the Claude CLI
2020
# `openai/`, `google/`, `xai/`, and `anthropic/` are supported

flake.lock

Lines changed: 96 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
description = "AnyClaude development environment";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
treefmt-nix.url = "github:numtide/treefmt-nix";
8+
};
9+
10+
outputs = { self, nixpkgs, flake-utils, treefmt-nix }:
11+
flake-utils.lib.eachDefaultSystem (system:
12+
let
13+
pkgs = nixpkgs.legacyPackages.${system};
14+
15+
treefmt = treefmt-nix.lib.evalModule pkgs {
16+
projectRootFile = "flake.nix";
17+
programs = {
18+
nixpkgs-fmt.enable = true;
19+
shfmt.enable = true;
20+
shellcheck.enable = true;
21+
};
22+
};
23+
in
24+
{
25+
# Format the source tree
26+
formatter = treefmt.config.build.wrapper;
27+
28+
# Check formatting
29+
checks.formatting = treefmt.config.build.check self;
30+
31+
devShells.default = pkgs.mkShell {
32+
buildInputs = with pkgs; [
33+
# Primary runtime and package manager
34+
bun
35+
36+
# Node.js for compatibility (required by some tools)
37+
nodejs_22
38+
39+
# Code quality tools (already included by treefmt)
40+
treefmt.config.build.wrapper
41+
42+
# Version control
43+
git
44+
45+
# Utilities
46+
jq
47+
ripgrep
48+
bat
49+
];
50+
51+
# Environment variables
52+
NODE_ENV = "development";
53+
};
54+
});
55+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232
"scripts": {
3333
"build": "bun build --target node --outfile dist/main.js ./src/main.ts --format cjs && sed -i '0,/^/s//#!\\/usr\\/bin\\/env node\\n/' ./dist/main.js"
3434
}
35-
}
35+
}

0 commit comments

Comments
 (0)