C
Coder.com3mo ago
Sebo

Claude Code Max auth

How do you retain the authentications for one User across multiple workspaces for a Claude code max plan that does not use api keys?
63 Replies
Codercord
Codercord3mo ago
Codercord
Codercord3mo ago
<#1416506087724679309>
Category
Help needed
Product
Coder (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
matifali
matifali3mo ago
Hi @Sebo we are making it easy in our Claude Code module. The new version should be availble later today, cc: @35C4n0r https://github.com/coder/registry/pull/402/files#diff-3f433388cb775dcc77c38911e23acbd2eb64e26e26c25d46b045724dfe5136bbR30
Sebo
SeboOP3mo ago
Will it retain the Session Token across multiple workspaces ? Or do i need to call Claude setup-token in every workspace again?
matifali
matifali3mo ago
I think it should
noel
noel3mo ago
I believe that you need to pass your anthropic token. This is how I do it for my sessions.
Sebo
SeboOP3mo ago
Is there now an anthropic token for subscription based pricing too?
ztlod ツ
ztlod ツ3mo ago
it does, i'm using with session token for a while by now
ztlod ツ
ztlod ツ3mo ago
i have a older module version but setting this var instead of the token one should work
No description
ztlod ツ
ztlod ツ3mo ago
Also i've pinned CC version to 1.0.100, as it has a bug that configure your instance as PRO plan instead of Max
No description
ztlod ツ
ztlod ツ3mo ago
not sure if they resolved this yet, but i had this problem between 1.0.101 to 1.0.108
ztlod ツ
ztlod ツ3mo ago
GitHub
[Bug] Claude Code fails to recognize MAX subscription tier - defaul...
Environment Platform (select one): Anthropic API AWS Bedrock Google Vertex AI Other: Claude Code CLI Claude CLI version: 1.0.43 (Claude Code) (also tested with v1.0.98) Operating System: macOS 15.6...
ztlod ツ
ztlod ツ3mo ago
btw, good to hear about the new version, i'll update my templates later today You guys here at Coder rocks!
Sebo
SeboOP3mo ago
@ztlod ツ where do you get the OAUTH_Token from? Thanks
ztlod ツ
ztlod ツ3mo ago
Hey, @Sebo first run claude and authenticate (/login) then kill the process and run claude auth-token and it will give a long-living token btw, forget the first step, if i`m not mistaken the command will ask you to login again
Sebo
SeboOP3mo ago
ah nice hm doesn't seem to work for me.
ztlod ツ
ztlod ツ3mo ago
wait, let me double check the command, i've did this step days ago the command don't run? sry claude setup-token is the right command
Sebo
SeboOP2mo ago
nice this works. awesome The token generation part worked, but claude still wants to login again. Not sure why it is not working
matifali
matifali2mo ago
Hi try using the new v3.0.0 module and you should be able to pass a session token
Sebo
SeboOP2mo ago
Thanks. I actually wanted to use claude code in tmux in a workspace. It works by retaining the claude.json config file and setting the env var that you mentioned. Thanks everyone for helping out. Your messages helped me figuring it out. 🚀
noel
noel2mo ago
Wanted to bump this one. I previously had this working, but using Oauth, I now get an authentication error. This github issue is the same: https://github.com/anthropics/claude-code/issues/9802
GitHub
Cannot --resume. OAuth authentication errors contaminating session ...
Bug Description Claude Code --resume Bug Report Summary: Sessions opened via --resume disappear from the resume list on subsequent runs due to OAuth authentication errors contaminating session file...
noel
noel2mo ago
GitHub
OAuth Authentication Not Supported for Highest Plan Tier · Issue #...
Bug Description I have subscribed to highest plan. But I am getting this error related to auth. API Error: 401 {&quot;type&quot;:&quot;error&quot;,&quot;error&quot;:{&quot;type&quot;:&quot;authenti...
ztlod ツ
ztlod ツ2mo ago
i'm still have it working on my templates what cc version are you using?
noel
noel2mo ago
Latest version. 2.0.22
ztlod ツ
ztlod ツ2mo ago
No description
ztlod ツ
ztlod ツ2mo ago
agent api
No description
ztlod ツ
ztlod ツ2mo ago
and my setup is configured with OAUTH + CC Module
noel
noel2mo ago
Mine also worked, and workspaces that were logged in work, but new ones don't. I can reproduce issue inside a docker container, claude just doesn't seem to care that you have an OAUTH token.
ztlod ツ
ztlod ツ2mo ago
what version of cc module are you using? let me check mine
noel
noel2mo ago
latest.
ztlod ツ
ztlod ツ2mo ago
No description
noel
noel2mo ago
Try a fresh docker container just something plain, pass the ENV var for the token, and it says oauth not supported, must login.
ztlod ツ
ztlod ツ2mo ago
for sure. but i run my WK on incus, not docker
noel
noel2mo ago
Hold on I can share a snippet.
ztlod ツ
ztlod ツ2mo ago
but i'll spin up a new one
noel
noel2mo ago
The issue isn't even CC module, just claude in general seems to not care about oauth anymore.
ztlod ツ
ztlod ツ2mo ago
just for ref
ztlod ツ
ztlod ツ2mo ago
No description
ztlod ツ
ztlod ツ2mo ago
empty template from scratch spinning up, incus take a while
noel
noel2mo ago
I have a test image and build it. then passing oauth token gets this.
/bin/bash -c "echo 'Testing Claude with ANTHROPIC_AUTH_TOKEN...' && echo 'what is 2+2?' | claude -p"
Testing Claude with ANTHROPIC_AUTH_TOKEN...
API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"OAuth authentication is currently not supported."},"request_id":"req_011CUGc5oo2sGRPbjjQGQnoY"} · Please run /login
(base)
/bin/bash -c "echo 'Testing Claude with ANTHROPIC_AUTH_TOKEN...' && echo 'what is 2+2?' | claude -p"
Testing Claude with ANTHROPIC_AUTH_TOKEN...
API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"OAuth authentication is currently not supported."},"request_id":"req_011CUGc5oo2sGRPbjjQGQnoY"} · Please run /login
(base)
just simple image like this:
# Test Dockerfile to verify Claude CLI authentication with ANTHROPIC_AUTH_TOKEN
# Based on the Coder Dockerfile but simplified for testing

FROM ubuntu:22.04

# Prevent interactive prompts during package installation
ENV DEBIAN_FRONTEND=noninteractive

# Install basic dependencies
RUN apt-get update && apt-get install -y \
curl \
wget \
git \
ca-certificates \
sudo \
&& rm -rf /var/lib/apt/lists/*

# Install Node.js 20.x (same as Coder Dockerfile)
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y nodejs && \
rm -rf /var/lib/apt/lists/*

# Verify Node.js and npm installation
RUN node --version && npm --version

# Install Claude CLI via npm globally
RUN npm install -g @anthropic-ai/claude-code

# Verify Claude CLI installation
RUN claude --version

# Create a test user (similar to Coder setup)
RUN useradd -m -s /bin/bash -u 1000 testuser && \
echo "testuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/nopasswd

# Switch to test user
USER testuser
WORKDIR /home/testuser

# Set up a basic working directory
RUN mkdir -p /home/testuser/workspace

# Default command: start bash for interactive testing
CMD ["/bin/bash"]
# Test Dockerfile to verify Claude CLI authentication with ANTHROPIC_AUTH_TOKEN
# Based on the Coder Dockerfile but simplified for testing

FROM ubuntu:22.04

# Prevent interactive prompts during package installation
ENV DEBIAN_FRONTEND=noninteractive

# Install basic dependencies
RUN apt-get update && apt-get install -y \
curl \
wget \
git \
ca-certificates \
sudo \
&& rm -rf /var/lib/apt/lists/*

# Install Node.js 20.x (same as Coder Dockerfile)
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y nodejs && \
rm -rf /var/lib/apt/lists/*

# Verify Node.js and npm installation
RUN node --version && npm --version

# Install Claude CLI via npm globally
RUN npm install -g @anthropic-ai/claude-code

# Verify Claude CLI installation
RUN claude --version

# Create a test user (similar to Coder setup)
RUN useradd -m -s /bin/bash -u 1000 testuser && \
echo "testuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/nopasswd

# Switch to test user
USER testuser
WORKDIR /home/testuser

# Set up a basic working directory
RUN mkdir -p /home/testuser/workspace

# Default command: start bash for interactive testing
CMD ["/bin/bash"]
ztlod ツ
ztlod ツ2mo ago
here,
No description
ztlod ツ
ztlod ツ2mo ago
let me check, but i think this env name are wrong ANTHROPIC_AUTH_TOKEN try CLAUDE_CODE_OAUTH_TOKEN
noel
noel2mo ago
both env names from the docs not working for me.
ztlod ツ
ztlod ツ2mo ago
try and let me know
noel
noel2mo ago
Will do. If you're getting something, I must have it messed somewhere. Just don't know where.
ztlod ツ
ztlod ツ2mo ago
on my workspace printenv
ztlod ツ
ztlod ツ2mo ago
No description
ztlod ツ
ztlod ツ2mo ago
it uses CLAUDE_CODE_OAUTH_TOKEN not anthropic this one ANTHROPIC_AUTH_TOKEN don't exist on my envs at all
noel
noel2mo ago
I will try to see what I am doing wrong. I think it's ANTROPIC api key and cc oauth token are conflicting, and I didn't realize. Thanks for the help
noel
noel2mo ago
It is sent in env, but claude doesn't pick it up.
No description
No description
No description
noel
noel2mo ago
coder@issue-350-noeljackson:~$ claude -v
2.0.22 (Claude Code)
coder@issue-350-noeljackson:~$ claude -v
2.0.22 (Claude Code)
Terminal or the claude-code web module. this is the way I am testing it locally:
# Test Dockerfile to verify Claude CLI authentication
# Based on the Coder Dockerfile but simplified for testing

FROM ubuntu:22.04

# Prevent interactive prompts during package installation
ENV DEBIAN_FRONTEND=noninteractive

# Install basic dependencies
RUN apt-get update && apt-get install -y \
curl \
wget \
git \
ca-certificates \
sudo \
&& rm -rf /var/lib/apt/lists/*

# Install Node.js 20.x (same as Coder Dockerfile)
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y nodejs && \
rm -rf /var/lib/apt/lists/*

# Verify Node.js and npm installation
RUN node --version && npm --version

# Install Claude CLI via npm globally
RUN npm install -g @anthropic-ai/claude-code

# Verify Claude CLI installation
RUN claude --version

# Create a test user (similar to Coder setup)
RUN useradd -m -s /bin/bash -u 1000 testuser && \
echo "testuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/nopasswd

# Switch to test user
USER testuser
WORKDIR /home/testuser

# Set up a basic working directory
RUN mkdir -p /home/testuser/workspace

# Default command: start bash for interactive testing
CMD ["/bin/bash"]
# Test Dockerfile to verify Claude CLI authentication
# Based on the Coder Dockerfile but simplified for testing

FROM ubuntu:22.04

# Prevent interactive prompts during package installation
ENV DEBIAN_FRONTEND=noninteractive

# Install basic dependencies
RUN apt-get update && apt-get install -y \
curl \
wget \
git \
ca-certificates \
sudo \
&& rm -rf /var/lib/apt/lists/*

# Install Node.js 20.x (same as Coder Dockerfile)
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y nodejs && \
rm -rf /var/lib/apt/lists/*

# Verify Node.js and npm installation
RUN node --version && npm --version

# Install Claude CLI via npm globally
RUN npm install -g @anthropic-ai/claude-code

# Verify Claude CLI installation
RUN claude --version

# Create a test user (similar to Coder setup)
RUN useradd -m -s /bin/bash -u 1000 testuser && \
echo "testuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/nopasswd

# Switch to test user
USER testuser
WORKDIR /home/testuser

# Set up a basic working directory
RUN mkdir -p /home/testuser/workspace

# Default command: start bash for interactive testing
CMD ["/bin/bash"]
docker build -f Dockerfile.test -t claude-test .
docker build -f Dockerfile.test -t claude-test .
docker run -it --rm \
-e CLAUDE_CODE_OAUTH_TOKEN="put token here" \
-v "$(pwd):/workspace" \
-w /workspace \
claude-test \
bash
docker run -it --rm \
-e CLAUDE_CODE_OAUTH_TOKEN="put token here" \
-v "$(pwd):/workspace" \
-w /workspace \
claude-test \
bash
This results in getting asked for login. I see yours works, but even a simple reproduction locally does not work for me.
ztlod ツ
ztlod ツ2mo ago
run a normal bash without token printenv then unset every token related to anthropic or claudecode then run export CLAUDE_CODE_OAUTH_TOKEN="put token here" claude
noel
noel2mo ago
I did, it's empty just claude code. From what I found, it needs ~/.claude.json or just won't work.
docker run -it --rm \
-e CLAUDE_CODE_OAUTH_TOKEN="token" \
-v "$HOME/.claude:/home/testuser/.claude" \
-v "$HOME/.claude.json:/home/testuser/.claude.json" \
-v "$(pwd):/workspace" \
-w /workspace \
--user testuser \
claude-test \
bash
docker run -it --rm \
-e CLAUDE_CODE_OAUTH_TOKEN="token" \
-v "$HOME/.claude:/home/testuser/.claude" \
-v "$HOME/.claude.json:/home/testuser/.claude.json" \
-v "$(pwd):/workspace" \
-w /workspace \
--user testuser \
claude-test \
bash
I think I see why not working for me. In dockerfile, we are installing claude code, not installing with claude-code web. I am guessing the install for claude-code module does something to setup .claude.json maybe. Or, that's what it seems like.
ztlod ツ
ztlod ツ2mo ago
yes, claude_code module does create a .claude config
noel
noel2mo ago
Thanks. Makes sense.
ztlod ツ
ztlod ツ2mo ago
give up on the minimal test, update your template and try the full cenario
Sebo
SeboOP2mo ago
Sorry to jump in here so late. Solution for us was also that there needs to be a claude config already in place for it to work otherwise claude code goes through the login process again. @noel
noel
noel2mo ago
Yes. I finally found the missing base .claude.json that’s needed. Thanks Sebo!
Sebo
SeboOP2mo ago
With this we were able to put an input field into the new workspace creation form that says "what is your initial prompt?". Then the engineer can start a workspace with coder already starting a tmux claude code session after the workspace is love. In the meantime the engineer can work on something else and come back once the initial output e.g. creating a specification is done.
noel
noel2mo ago
Yes exactly what I am doing. I’m passing all my stuff from GitHub issues. I add a label and it launches the workspace in full force. Kind of amazing!
Sebo
SeboOP2mo ago
Nice How do you connect the both?
ztlod ツ
ztlod ツ2mo ago
Up I want to know aswell :thonk:
noel
noel5w ago
I can share a GitHub action. But essentially it’s just environment vars and coder cli.
- name: Create Coder workspace
env:
CODER_URL: ${{ secrets.CODER_URL }}
CODER_SESSION_TOKEN: ${{ secrets.CODER_TOKEN }}
run: |
# Generate unique workspace name (shortened to avoid length issues)
WORKSPACE_NAME="issue-${{ github.event.issue.number }}-$(echo '${{ github.event.issue.user.login }}' | head -c 20)"

# Create workspace with minimal parameters to avoid shell expansion issues
# The issue body is too complex to pass via CLI, so we'll just pass the reference
coder create "$WORKSPACE_NAME" \
--template="sonica-dev" \
--parameter="git_repo=https://github.com/sonicaapp/sonica.git" \
--parameter="github_issue_number=${{ github.event.issue.number }}" \
--parameter="github_issue_title=${{ steps.issue.outputs.safe_title }}" \
--parameter="github_issue_body=See issue #${{ github.event.issue.number }} for details" \
--parameter="github_issue_branch=${{ steps.issue.outputs.branch_name }}" \
--parameter="AI Prompt=You are working on GitHub Issue #${{ github.event.issue.number }}: ${{ steps.issue.outputs.safe_title }}. You are a helpful AI assistant for the Sonica development workspace." \
--yes

# Get workspace URL
WORKSPACE_URL="${CODER_URL}/@${{ github.event.issue.user.login }}/${WORKSPACE_NAME}"
echo "WORKSPACE_URL=$WORKSPACE_URL" >> $GITHUB_ENV
echo "WORKSPACE_NAME=$WORKSPACE_NAME" >> $GITHUB_ENV


- name: Create Coder workspace
env:
CODER_URL: ${{ secrets.CODER_URL }}
CODER_SESSION_TOKEN: ${{ secrets.CODER_TOKEN }}
run: |
# Generate unique workspace name (shortened to avoid length issues)
WORKSPACE_NAME="issue-${{ github.event.issue.number }}-$(echo '${{ github.event.issue.user.login }}' | head -c 20)"

# Create workspace with minimal parameters to avoid shell expansion issues
# The issue body is too complex to pass via CLI, so we'll just pass the reference
coder create "$WORKSPACE_NAME" \
--template="sonica-dev" \
--parameter="git_repo=https://github.com/sonicaapp/sonica.git" \
--parameter="github_issue_number=${{ github.event.issue.number }}" \
--parameter="github_issue_title=${{ steps.issue.outputs.safe_title }}" \
--parameter="github_issue_body=See issue #${{ github.event.issue.number }} for details" \
--parameter="github_issue_branch=${{ steps.issue.outputs.branch_name }}" \
--parameter="AI Prompt=You are working on GitHub Issue #${{ github.event.issue.number }}: ${{ steps.issue.outputs.safe_title }}. You are a helpful AI assistant for the Sonica development workspace." \
--yes

# Get workspace URL
WORKSPACE_URL="${CODER_URL}/@${{ github.event.issue.user.login }}/${WORKSPACE_NAME}"
echo "WORKSPACE_URL=$WORKSPACE_URL" >> $GITHUB_ENV
echo "WORKSPACE_NAME=$WORKSPACE_NAME" >> $GITHUB_ENV


My prompt for this just says here’s the issue #. Here’s coding guidelines. Here’s playwright MCP server you have access to. And now use the GitHub CLI tool to pull up the issue description and execute on it till it’s complete. I wasted a bunch of time trying to figure out how to dependably pass through huge issue descriptions, using gh cli is easier.

Did you find this page helpful?