惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
G
Google Developers Blog
J
Java Code Geeks
C
Check Point Blog
Last Week in AI
Last Week in AI
Microsoft Azure Blog
Microsoft Azure Blog
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
L
LangChain Blog
有赞技术团队
有赞技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 司徒正美
IT之家
IT之家
Martin Fowler
Martin Fowler
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tailwind CSS Blog
U
Unit 42
Jina AI
Jina AI
Microsoft Security Blog
Microsoft Security Blog
I
InfoQ

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How to use your Claude Pro/Max subscription with the Agen...
Aviv Shaked · 2026-05-10 · via DEV Community

If you pay for Claude Pro or Max and also script things against Claude from your own code, you might be double-paying. Anthropic keeps subscription billing and API credits as completely separate accounts — and the regular anthropic SDK only knows about the API one. But there's an officially-supported path that lets the Claude Agent SDK bill against your subscription instead. Here's how it works in Python and TypeScript.

A small companion repo with the full setup, both languages side by side, and worked examples:

👉 github.com/avivshaked/prototype-with-claude-max

Here's the mental model.

The two-token mental model

Anthropic keeps two separate billing relationships:

Auth What it is Where you pay
ANTHROPIC_API_KEY Console API key Pay-as-you-go API credits
CLAUDE_CODE_OAUTH_TOKEN OAuth token from claude setup-token Your Pro/Max subscription

The regular anthropic SDK only knows about the first one. The Agent SDK (claude-agent-sdk for Python, @anthropic-ai/claude-agent-sdk for TypeScript) wraps the Claude Code CLI, which natively understands both — and on the OAuth path, every call lands on your subscription quota.

The hello-world

Generate the token:

npm install -g @anthropic-ai/claude-code
claude setup-token   # opens a browser, returns a 1-year token

Enter fullscreen mode Exit fullscreen mode

Drop it into .env:

CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-...

Enter fullscreen mode Exit fullscreen mode

Then in Python:

import asyncio, os, sys
from dotenv import load_dotenv

load_dotenv()
if os.environ.get("ANTHROPIC_API_KEY"):
    sys.exit("ANTHROPIC_API_KEY is set — it would shadow your OAuth token. unset it.")

from claude_agent_sdk import query, ClaudeAgentOptions, AssistantMessage, TextBlock

async def main():
    async for msg in query(
        prompt="Say hello in one short sentence.",
        options=ClaudeAgentOptions(allowed_tools=[]),
    ):
        if isinstance(msg, AssistantMessage):
            for block in msg.content:
                if isinstance(block, TextBlock):
                    print(block.text)

asyncio.run(main())

Enter fullscreen mode Exit fullscreen mode

That's it. Bills against your Max subscription, not API credits. The repo has the same thing in TypeScript, plus a WebSearch + token-by-token streaming example.

The gotcha worth knowing about

Auth precedence on the SDK is:

  1. cloud creds → 2. ANTHROPIC_AUTH_TOKEN → 3. ANTHROPIC_API_KEY → 4. apiKeyHelper → 5. CLAUDE_CODE_OAUTH_TOKEN → 6. interactive /login

If you have ANTHROPIC_API_KEY exported from another project (and you almost certainly do), it silently wins over your OAuth token. You'll be billing API credits while thinking you're using your subscription.

unset ANTHROPIC_API_KEY

Enter fullscreen mode Exit fullscreen mode

The repo includes a check_auth.py / check-auth.ts script that tells you exactly which auth method is winning, so you can diagnose instead of guessing.

⚠️ Personal use only

This works because the OAuth token is licensed for individual use through Claude Code and the Agent SDK. Do not ship a multi-user app on it:

  • You'd run everyone's traffic through one person's quota — you'd hit rate limits in seconds at any real load.
  • It likely violates Anthropic's terms. Pro/Max plans are for individual use, and as of April 2026 Anthropic actively blocks third-party harnesses that try to bridge subscription auth into other tools.
  • A leaked token = anyone can drain your subscription until you rotate it.

For production, you swap the auth method, not the SDK — the Agent SDK itself is production-grade. Point at ANTHROPIC_API_KEY from console.anthropic.com and you're good.

The repo

Top-level README with the full story, plus per-language READMEs for Python and TypeScript with setup instructions, three worked examples each (hello, check_auth, news with streaming + WebSearch), and a troubleshooting table.

Repo: avivshaked/prototype-with-claude-max

If you've been double-paying for Anthropic, this fixes it for personal scripts in about 5 minutes.