peter_gibbons
09/13/2025, 8:45 AMVaibhav (BAML 🐑)
09/13/2025, 10:18 AMVaibhav (BAML 🐑)
09/13/2025, 10:19 AMpeter_gibbons
09/13/2025, 7:48 PMZach E.
09/14/2025, 8:49 PMZach E.
09/14/2025, 8:58 PMexhaze
09/22/2025, 6:51 PMexhaze
09/22/2025, 6:52 PMexhaze
09/22/2025, 6:52 PMexhaze
09/22/2025, 7:05 PMclient<llm> ClaudeSonnet4 {
provider "anthropic"
options {
model "claude-sonnet-4-20250514"
max_tokens 8192
api_key env.ANTHROPIC_API_KEY
base_url env.BAML_ANTHROPIC_BASE_URL
}
}
agent-pool.ts
export class AgentPool {
private agents = new Map<AgentId, AgentInstance>();
private bamlProxy: BAMLProxyTsRestServer | null = null;
private bamlProxyPort = 8890;
constructor() {
// Initialize BAML proxy
this.serverReady = this.initializeProxy();
}
private async initializeProxy(): Promise<void> {
try {
// Start BAML proxy server (ts-rest version)
this.bamlProxy = new BAMLProxyTsRestServer(this.bamlProxyPort);
await this.bamlProxy.start();
// Configure BAML to use our proxy instead of direct Anthropic API
// Use BAML-specific env var to avoid conflicts with Claude Code SDK
process.env.BAML_ANTHROPIC_BASE_URL = `http://localhost:${this.bamlProxyPort}`;
// Don't set a dummy API key - it breaks the Claude SDK
// The proxy and SDK will handle their own authentication
console.log(`🔀 BAML Proxy Server started on port ${this.bamlProxyPort}`);
console.log('📍 BAML requests will be routed through isolated Claude instances');
} catch (err) {
console.error('❌ Failed to start proxy server:', err);
throw err;
}
}exhaze
09/22/2025, 7:06 PMexport { type SDKMessage, type Query, query, type Options } from '@anthropic-ai/claude-code';
import { join } from 'node:path';
export class ClaudeIsolatedClient {
query(prompt: string, options: Options & { env?: Record<string, string> } = {}): Query {
this.initializeSync();
// Set up isolated environment
const isolatedEnv = {
...process.env,
HOME: this.instanceHome,
TMPDIR: join(this.instanceHome, 'tmp'),
// Try to override Claude's project directory
CLAUDE_PROJECTS_DIR: join(this.instanceHome, '.claude', 'projects'),
};
// Extract env from options if provided, otherwise use isolatedEnv
const { env = isolatedEnv, ...sdkOptions } = options;
// Use the official SDK with our isolated environment
// The SDK's query function signature doesn't expose env in types but accepts it
try {
const response = query({
prompt,
options: {
...sdkOptions,
// Set cwd to our isolated home if not specified
cwd: sdkOptions.cwd || this.instanceHome,
} as Options,
// Pass the isolated environment directly to the query function
env,
} as Parameters<typeof query>[0] & { env: Record<string, string> });
return response;
} catch (error) {
throw error;
}
}
private initializeSync(): void {
// Create directories synchronously for the SDK
const dirs = [
join(this.instanceHome, '.claude', 'shell-snapshots'),
join(this.instanceHome, '.claude', 'projects'),
join(this.instanceHome, '.config'),
join(this.instanceHome, '.local', 'share'),
join(this.instanceHome, '.local', 'state'),
join(this.instanceHome, '.cache'),
join(this.instanceHome, 'tmp'),
];
for (const dir of dirs) {
mkdirSync(dir, { recursive: true });
}
}
}exhaze
09/22/2025, 7:18 PM