Using CodeCompanion with Anthropic signed-in account (Like Claude Code) #1984
Replies: 4 comments 26 replies
-
|
Oh my god, man, you're amazing |
Beta Was this translation helpful? Give feedback.
-
|
I tried to create an adapter with oauth flow, now the oauth flow has passed, but when requesting, the token will report the lack of scope. I also encountered this problem in opencode. https://github.com/jinzhongjia/codecompanion.nvim/tree/anthropic_oauth |
Beta Was this translation helpful? Give feedback.
-
|
Should I copy the whole |
Beta Was this translation helpful? Give feedback.
-
|
This is the one I created, similar but does auto refresh and some other stuff -- https://gist.github.com/stuckinsnow/99e5ab2a779a2ac66e6537d2ca56f51b |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This isn’t the most conventional approach — but it works.
Antropic.Logged.mp4
Claude Code lets you use an Anthropic Pro subscription account and call Claude models without being charged for wasted API tokens. Of course, there’s a daily quota, but in my experience it’s surprisingly generous — I was able to work the entire day without hitting the limit. That’s incredible, considering how expensive Anthropic tokens normally are.
To figure out how Claude Code manages this, I read through some docs and ran a man-in-the-middle proxy to capture the requests and responses being sent to Anthropic’s API. Here’s what I found:
Authorizationheader.How do you get a valid signed-in token?
On macOS:
Open the Keychain Access app and search for “Claude Code”. View the entry to reveal the token, then export it to an environment variable:
export ANTHROPIC_BEARER_TOKEN=xxxxOn other systems:
Use a tool like
mitmproxyto intercept Claude Code’s traffic, then capture and copy the bearer token from one of the API calls.I’ve now built a simple custom adapter that lets our CodeCompanion plugin use Anthropic as if we were logged in through Claude Code — without needing a direct API key:
(Paste this in y
It will be awesome if someone get this adapter as inspiration to make the OAuth authentication as well.
Beta Was this translation helpful? Give feedback.
All reactions