One terminal, two trust levels — running Claude Code against a real subscription and a cheap proxy

Iniciado por joomlamz, Hoje at 02:25

Respostas: 1   |   Visualizações: 5

Tópico anterior - Tópico seguinte

Shanycursos e 1 Visitante estão a ver este tópico.

Olá, caros membros do **webmastersmz.com**! Como especialista em tecnologia, analisei o tópico em inglês *"One terminal, two trust levels — running Claude Code against a real subscription and a cheap proxy"* e trago aqui os pontos principais para a nossa discussão técnica.

### Análise Técnica do Tópico

O tópico aborda uma estratégia avançada de engenharia e gestão de custos para interagir com o assistente de IA **Claude Code** diretamente a partir do terminal. A premissa central gira em torno da criação de dois níveis de confiança (*trust levels*) num único ambiente de trabalho:

1. **A Subscrição Real (Alto Nível de Confiança):**
   - Utilizada para tarefas críticas, produção de código sensível e operações que exigem acesso total, autenticação oficial e máxima segurança. Aqui, o programador confia plenamente na infraestrutura e na API oficial fornecida pela Anthropic.

2. **O Proxy Barco/Alternativo (Baixo Nível de Confiança):**
   - Utilizado para testes rápidos, prototipagem, tarefas repetitivas ou consultas de menor importância onde o custo por *token* precisa ser rigorosamente controlado. Ao utilizar proxies mais baratos (muitas vezes APIs de revenda ou endpoints auto-hospedados), o risco é mitigado caso o serviço intermédio apresente falhas de estabilidade ou levante questões de privacidade.

**O desafio técnico:** Configurar o terminal para alternar dinamicamente entre estes dois contextos de forma fluida, sem expor credenciais sensíveis da subscrição principal nos endpoints de menor confiança, garantindo que o fluxo de trabalho (*workflow*) do desenvolvedor não seja quebrado.

### Por que isto importa para nós?
Esta abordagem reflete uma realidade crescente no desenvolvimento moderno: a necessidade de otimizar custos operacionais com IA sem comprometer a segurança. Gerir chaves de API, variáveis de ambiente e regras de firewall diretamente no terminal exige um bom entendimento de arquitetura de redes e segurança de endpoints.

Como é que vocês gerem os custos das vossas ferramentas de IA no terminal? Já implementaram alguma estratégia de proxy ou preferem manter sempre a via oficial? **Deixem as vossas opiniões e experiências aqui no fórum do webmastersmz.com para enriquecermos este debate!**

---

Para garantir que os vossos projetos e fóruns rodam sem falhas, convido-vos a conhecer as soluções de alojamento de alta performance da AplicHost em https://aplichost.com.

One terminal, two trust levels — running Claude Code against a real subscription and a cheap proxy



Tópico: One terminal, two trust levels — running Claude Code against a real subscription and a cheap proxy
Categoria: Tutoriais | Programação & Tecnologia
Idioma Principal: Português (Conteúdo de Tecnologia)

Descrição do Conteúdo / Informações:
-------------------------------------------------------------------------
Part of an ongoing series on model routing and trust tiering for agentic coding tools. This one's the boring, working half — no bug hunt, just a setup that's been running clean across two machines.



The problem


Claude Code does one thing well: careful, scoped edits with a real plan-then-execute loop behind them, backed by a subscription you're already paying for. Not every task needs that. Exploratory reads, "summarize this directory," draft-and-discard scratch work — most of that doesn't need the most capable model watching every token.

The fix is a second, cheaper backend for that category of work. The catch: Claude Code only speaks Anthropic's Messages API. It has no built-in notion of "same tool, different model." So the question is how to point it somewhere else without giving up the interface.



The stack


Trusted agent:  claude       — real Anthropic subscription, default session
Cheap agent:    claude-cheap — same CLI, routed through a self-hosted proxy
Proxy:          LiteLLM, translating Anthropic-format requests to
DeepSeek V4 (pro for Sonnet-tier calls, flash for Haiku-tier)
served through an OpenRouter API
Transport:      a persistent SSH tunnel from a small VPS back to each machine

The proxy itself wasn't new. It's the same LiteLLM instance already routing a separate content pipeline I run. The actual work here was wiring Claude Code to it: a shell function and a few environment variables.

The core trick and it took me a few week to learn this is to point ANTHROPIC_BASE_URL at LiteLLM's /v1/messages endpoint, not the OpenAI-compatible path LiteLLM also exposes. Claude Code only understands the Anthropic shape, so the OpenAI-shaped endpoint fails in ways that look like a client bug and aren't. Once LiteLLM sits on the right endpoint and translates underneath, Claude Code has no idea it isn't talking to Anthropic.



The one bug worth flagging


Claude Code's Plan Mode attaches a context_management parameter to its requests. Anthropic's API handles it. Most other backends don't recognize it and reject the whole request with a 400 — which looks like Plan Mode itself is broken, when it's a parameter the downstream model was never built to accept.

One-line fix in the LiteLLM config:

litellm_config.yaml
---
drop_params: true

That tells LiteLLM to silently strip unsupported parameters instead of forwarding them and letting the backend reject the call. Plan Mode then works the same regardless of which model is actually answering.



Two commands, deliberately asymmetric


This is the part worth copying more than any proxy config: the trusted and cheap agents don't look the same, on purpose.

claude — the real thing, full subscription, no wrapper. Default terminal, default prompt. It's the session where mistakes cost the most, so I want zero visual noise between me and what it's doing.

claude-cheap — a shell function that drops into an isolated subshell, retitles the tab with a distinct label and icon, and resets on exit. Not aesthetics: at 11pm switching between six tabs, I want it structurally impossible to mistake the cheap, more permissive session for the one running on my subscription. The expensive tool gets no ceremony; the cheap tool gets a costume, because misidentifying that direction is the failure mode worth guarding against.

# --- Cheap agent: DeepSeek via self-hosted LiteLLM proxy ---
claude-cheap() {
(
unset ANTHROPIC_API_KEY
export ANTHROPIC_BASE_URL=http://localhost:3456
export ANTHROPIC_AUTH_TOKEN=anything
export ANTHROPIC_MODEL=deepseek/deepseek-v4-pro
export ANTHROPIC_DEFAULT_SONNET_MODEL=deepseek/deepseek-v4-pro
export ANTHROPIC_DEFAULT_HAIKU_MODEL=deepseek/deepseek-v4-flash
export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
echo -ne "\033]0;🐋 DEEPSEEK-AGENT\007"
claude "$@"
echo -ne "\033]0;Terminal\007"
)
}

The subshell ( ... ) is what makes the exports throwaway — they don't leak into the parent shell once the function returns. ANTHROPIC_AUTH_TOKEN is set to a dummy value because LiteLLM doesn't check it; it just needs something present so Claude Code doesn't refuse to start. CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC cuts calls back to Anthropic's own telemetry endpoints, since this session has no real Anthropic account behind it.



Why bother


Because the goal was never "make Claude Code cheaper." It's a supervisor/executor split: the subscription session does planning, review, anything I'd be upset to see broken. The proxy session handles high-volume, low-stakes work, and its output gets reviewed before it's trusted the same way.

Same shape of decision as picking a cloud model over a local one for a monitoring agent [earlier in this series] — not "which model is smarter," but "which failure mode can I tolerate, and what's the cheapest thing that clears the bar." Here the axis is subscription cost instead of on-device vs. cloud. The underlying question is identical: what am I willing to have wrong, and what's watching for when it is.



What's still open


There's also a local-only variant: same two-tier pattern, but the cheap tier runs entirely on-device instead of through a hosted proxy. That one hit a tool-calling format mismatch — a story of its own, I will write it up separately soon.


Joomlamz
Consultoria em Informática
-------------------------------------------------------
Especialista em Sistemas Web & Manutenção de Servidores.
A desenvolver o novo AplPortal com suporte a PHP 8.
Precisa de ajuda profissional? Contacte-me.

Tags: