🍁 Proud Canadian — hosted and operated in Canada
White paper The digital supply chain Get the white paper
Agent Libre
← All posts
Integration

Pointing Claude Code at a self-hosted endpoint

Three environment variables redirect the client. A fourth, less known, prevents errors that are hard to diagnose.

Claude Code accepts any Messages-API-compatible endpoint via ANTHROPIC_BASE_URL, with ANTHROPIC_AUTH_TOKEN for authentication and ANTHROPIC_MODEL to name the model. That's the foundation, and it fits in three lines of configuration.

What that configuration does not solve: the protocol has no field through which a server declares its context window size. The client counts tokens itself from the usage block of each response, and compares that total against a window it infers from the model identifier. Faced with an identifier it doesn't recognize, it assumes one — rarely the right one.

The symptom is unpleasant: instead of compacting the conversation cleanly before hitting the limit, the client overshoots it and gets an error. The user loses a turn with no way to understand why.

The CLAUDE_CODE_MAX_CONTEXT_TOKENS variable declares the window the client should assume. It applies directly when the model identifier does not start with claude- and carries no extended-context suffix — the case for any self-hosted deployment under its own name. One trap worth knowing: naming your model claude-something disables the variable.

The compaction threshold is set separately with CLAUDE_CODE_AUTO_COMPACT_WINDOW, which accepts only a plain token count. The client caps it at the declared window anyway, so the two variables should be read together.

Previous Throughput or tokens: two ways to buy inference Next The gap is closing, and closing fast
White paper

Your company has two supply chains

The first one you already know. Materials come in, they are transported, stored, transformed, delivered. Every step has a supplier, a lead time, a unit cost. When the margin tightens, you walk down that chain step by step, and you generally know where to look.

The second one moves information instead of materials. A price request comes in and becomes a quote. An order comes in and becomes a production order, an invoice, a confirmed delivery. A site report becomes a change order, or it does not. This chain runs through every one of your departments and it employs a large share of your people.

A question about your consumption?

We measure your actual consumption over one day, free and with no commitment, and tell you whether a fixed-throughput plan works out in your favour — or not.