Skip to content

Route Claude Code launches through key-scrubbing wrappers so it never sees ANTHROPIC_API_KEY, keeping all usage billed to your Claude Chat account instead of your API key.

Notifications You must be signed in to change notification settings

instantlyeasy/claude-code-billing-guard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Claude Code billing guard

These launchers make sure Claude Code never sees ANTHROPIC_API_KEY, so sessions bill to your Claude Chat account instead of an Anthropic API key. They cover both the CLI and the opcode desktop app.

Quick start

Platform support: scripts target macOS; they also work on Linux if opcode/claude are on PATH or you set OPCODE_BIN/CLAUDE_CODE_BIN. Windows is not supported.

Install (no dependencies)

From a clone of this repo:

bash scripts/install.sh

Install location defaults to ~/.local/bin; override with TARGET_DIR=/your/bin bash scripts/install.sh.

Ensure your PATH includes the target directory (e.g. add export PATH="$HOME/.local/bin:$PATH" to your shell rc).

Scripts are Bash and embed their own shebangs, so you can invoke the installer from zsh/fish with bash scripts/install.sh. On Linux, just ensure opcode/claude are on PATH or set OPCODE_BIN/CLAUDE_CODE_BIN.

Clean uninstall: removes the only two installed files (no other traces):

bash scripts/install.sh --uninstall

You can also curl | bash the installer directly from the raw URL if you prefer:

curl -fsSL https://raw.githubusercontent.com/instantlyeasy/claude-code-billing-guard/main/scripts/install.sh | bash

To pin to a tag (recommended once releases exist):

curl -fsSL https://raw.githubusercontent.com/instantlyeasy/claude-code-billing-guard/v1.0.0/scripts/install.sh | bash

To change the install location when piping:

TARGET_DIR="$HOME/.local/bin" curl -fsSL https://raw.githubusercontent.com/instantlyeasy/claude-code-billing-guard/main/scripts/install.sh | bash

Claude Code CLI

Run Claude Code through the wrapper so the API key is scrubbed before the process starts:

claude-code-chat [normal-claude-code-args]

If you prefer an alias, append this to ~/.zshrc:

echo "alias claude-code='claude-code-chat'" >> ~/.zshrc

opcode desktop app (Tauri build)

Start the GUI with the same scrubbed environment. Always launch via the wrapper (or an alias to it); double-clicking the app or calling the bundle binary directly skips the guard and may pass ANTHROPIC_API_KEY.

The launcher tries common macOS paths; if you installed elsewhere, set OPCODE_BIN to the executable inside your app bundle (e.g. /Applications/opcode.app/Contents/MacOS/opcode).

OPCODE_BIN=/Applications/opcode.app/Contents/MacOS/opcode opcode-chat
# or rely on the defaults if you installed to /Applications
opcode-chat

For convenience, append this alias to ~/.zshrc:

echo "alias opcode='OPCODE_BIN=/Applications/opcode.app/Contents/MacOS/opcode opcode-chat'" >> ~/.zshrc

If you want opcode on your PATH to always point at the guard, symlink it:

ln -sf "$HOME/.local/bin/opcode-chat" "$HOME/.local/bin/opcode"

Per-project safety (direnv)

If you keep ANTHROPIC_API_KEY around for other tools, add a .envrc in your Claude projects so any shell and editor spawned there drops the key automatically:

unset ANTHROPIC_API_KEY
unset ANTHROPIC_API_KEY_FILE
unset ANTHROPIC_API_KEY_PATH

Then run direnv allow in that directory.

Verification

  • In the shell you use to launch Claude Code or opcode, run env | grep ANTHROPIC_API_KEY; it should print nothing.
  • Start a Claude Code session and confirm usage lands in your Claude Chat account (not the Anthropic API key account).

Why this approach

Billing selection happens as soon as Claude Code detects ANTHROPIC_API_KEY in its environment. Plugins or config inside the session cannot reliably override that early detection, so removing the key from the process environment is the most robust solution.

About

Route Claude Code launches through key-scrubbing wrappers so it never sees ANTHROPIC_API_KEY, keeping all usage billed to your Claude Chat account instead of your API key.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages