https://www.boundaryml.com logo
Does baml work with Claude code or is it
# general
p
Does baml work with Claude code or is it an api only tool?
v
currently its api only!
its a way to call llm apis. We've been thinking on how to help with agent sdks as well, but nothing concrete to offer yet
p
Ty bb!
z
This would be really cool, I'm doing some pretty advanced multi-agent stuff in claude code using subagents, commands, and hooks. and when you have to update a concept/reference in a markdown that have references in other files CC does, its a pain, manual, and error prone. For the longest time I have wanted to build some sort of CC artifact generator, where the "things" cc uses are modeled, so if you make an update, anything that references that "thing" gets updated. My thought was you'd model this in some sort of graph or some other datastruct, and then "generate" projections for the various different tools. Aka, I could define the orchestration, agent definitions, output style, etc, and then "generate" all the markdown that CC uses. I made this high level spec for myself to write down my ideas, but never found time to work on it. Something like this in BAML would be really powerful, not sure what the implementation would look like, but I wrote down some of my ideas wanted to share incase any of this gives any ideas.
Ignore the eval stuff I was building into the app, I was thinking of a single product where I could manage the model, and then eval different configs of the model, and agents performance. So it was a 2 in 1 product (artifact generation for CC, but also eval) https://cdn.discordapp.com/attachments/1416344054022668369/1416890992644194394/SoTModel_CC_Artifacts.md?ex=68c87e11&is=68c72c91&hm=3c7c2a7bfa4c95d1367294ecc288ee7a685c52e650d100fbc54e43b953f6969f&
p
You have a repo for all that
e
BAML works fine with claude code actually
I see calling an LLM these days without BAML like walking around SF downtown wrapped in $100 bills
here's how we did it for claude code:
clients.baml
Copy code
client<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
Copy code
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;
    }
  }
claude-isolated-client.ts
Copy code
export { 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 });
    }
  }
}
here's the overall flow. we did this because multiple concurrent claude code instances don't play with each other (at least a month ago, these days who knows - but we liked the isolation so just kept it) https://cdn.discordapp.com/attachments/1416344054022668369/1419764753907060786/CleanShot_2025-09-23_at_04.17.102x.png?ex=68d2f277&is=68d1a0f7&hm=b0022f091244e616c28b3541d3c06961a2f3eba7a01adfbdbe629634fa289460&