Skip to content
Download

DOCS / CONFIGURATION

Anthropic API key

Four Birch features call the Anthropic API directly: AI code review, per-comment fix suggestions, ✨ commit-message generation, and conflict-resolution suggestions. All four need the ANTHROPIC_API_KEY environment variable — and because GUI apps don’t read your shell profile the way a terminal does, setting it visibly to Birch is the whole trick this page teaches.

FeatureWhere you use it
AI code reviewAI code review, the Automatically review new PRs toggle (Settings → AI), and birch review run
Comment fix suggestionsThe fix-suggestion action on PR comments — currently unreachable; see the caution below
✨ Commit-message generationThe ✨ button in the Changes tab’s commit box
Conflict suggestionsThe AI suggest button in the conflict resolver

All four run on a Claude Sonnet model chosen by the app; the model is not configurable. See AI in Birch for how these Anthropic API features relate to the agent CLI.

  • Agent workspaces. The agent in a workspace terminal is your own CLI (claude, codex, …) authenticating the way it always does — typically your subscription. Workspaces work fine with no ANTHROPIC_API_KEY set.
  • ✨ PR title generation. The sparkle button in the Create PR dialog also runs your own agent CLI, spending your subscription limits or that CLI’s own key — never this API key.

Two steps — a shell profile alone is not enough, because apps launched from Finder or the Dock never read it.

1. Shell profile — covers the birch CLI in your terminal:

~/.zshrc
export ANTHROPIC_API_KEY="sk-ant-…"

2. launchctl setenv — covers the Birch app itself:

terminal
launchctl setenv ANTHROPIC_API_KEY "sk-ant-…"

Then quit and relaunch Birch. launchctl setenv lasts until you log out or reboot; to make it permanent, add a LaunchAgent that re-applies it at login:

~/Library/LaunchAgents/anthropic-api-key.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key><string>anthropic-api-key</string>
<key>ProgramArguments</key>
<array>
<string>/bin/launchctl</string>
<string>setenv</string>
<string>ANTHROPIC_API_KEY</string>
<string>sk-ant-…</string>
</array>
<key>RunAtLoad</key><true/>
</dict>
</plist>
  • The ✨ commit-message button appears in the Changes tab’s commit box once Birch sees the key.

  • A CLI review completes instead of erroring:

    terminal
    birch review run <pr-id>
  • Without the key, AI actions fail with: AI provider is not configured. Set ANTHROPIC_API_KEY. If you still see that after setting the variable, Birch was started before the variable existed — quit and relaunch.

Every action is a single, bounded API request billed to your Anthropic account: review reports and fix suggestions are capped at roughly 4,000 response tokens each, conflict suggestions slightly above that, and commit messages are far shorter. The one multiplier to watch is Automatically review new PRs (Settings → AI): with it on, each newly discovered PR triggers a review during background sync. It defaults to off, and it deliberately never runs on the first sync of a repository.

  • Birch never persists the key — it is not written to Birch’s database or settings; it lives only in your environment.
  • Don’t put the key in a repository .env file: worktree carryover copies .env* into every new agent workspace by default, where the agent can read it.
  • Treat it like a password: keep it out of commits and shared dotfiles, and rotate it from your Anthropic console if it leaks.