Skip to content

[BUG] OAuth authentication not persisting in Docker container despite credentials file being saved #22066

Description

@Lc-1900

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

I have been attempting to use Claude Code with my Synology NAS. Install works fine, but every time I open an instance of Claude, I am asked to set up (Dark mode, etc) and then reauthenticate. I initially ran into a segmentation fault and as a workaround attempted to use a docker container. I'm not sure if what I am attempting to do is even actually possible. Details follow.

Environment

  • Synology NAS DS1522+ (AMD Ryzen, x86_64)
  • DSM 7.2.2-72806 Update 5
  • Docker 24.0.2
  • Node 20 (official Docker image)
  • Claude Code installed via npm install -g @anthropic-ai/claude-code

Background

Native installation on Synology fails with a segmentation fault when running claude, likely due to incompatibility with Synology's environment. Docker is used as a workaround.

Issue

OAuth authentication does not persist between container runs, despite the credentials file being correctly saved and mounted.

Docker setup:
docker run -it --rm --hostname claude-nas \
-v /path/to/.claude-docker:/root/.claude \
-v /volume1:/volume1 \
-w $(pwd) claude-code

What happens:

  1. Run container, authenticate via OAuth successfully
  2. Exit with /exit
  3. Verify ~/.claude-docker/.credentials.json exists and contains valid tokens
  4. Run container again
  5. Claude Code prompts for authentication again

What Should Happen?

What I expected (or in any case wanted) to happen:
Authentication should persist since the .credentials.json file is saved and mounted at /root/.claude.

Troubleshooting attempted:

  • Confirmed credentials file is saved with valid tokens
  • Used absolute paths for volume mount
  • Added fixed --hostname to container
  • Verified mount works from inside container

Error Messages/Logs

Steps to Reproduce

As above:

  1. Create a Docker image with Claude Code:
    sudo docker build -t claude-code - << 'EOF'
    FROM node:20
    RUN npm install -g @anthropic-ai/claude-code
    ENTRYPOINT ["claude"]
    EOF

  2. Create a directory to persist config:
    mkdir -p ~/.claude-docker

  3. Run the container with the config directory mounted:
    sudo docker run -it --rm --hostname claude-nas \
    -v ~/.claude-docker:/root/.claude \
    -v /volume1:/volume1 \
    -w /volume1 \
    claude-code

  4. Complete OAuth authentication when prompted (select "Yes, log in" and follow the browser flow)

  5. After successful login, exit Claude Code:
    /exit

  6. Verify credentials were saved:
    sudo cat ~/.claude-docker/.credentials.json
    This shows valid tokens including accessToken, refreshToken, and expiresAt.

  7. Run the container again with the same command from step 3

Expected: Claude Code should recognize existing credentials and skip authentication.

Actual: Claude Code prompts for authentication again, as if no credentials exist.

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.27 (Claude Code)

Platform

Anthropic API

Operating System

Other

Terminal/Shell

Other

Additional Information

I'm connecting to my NAS from macOS and running Claude via Synology default shell (ash/sh) via SSH

Additional Attempted Troubleshooting

  • Confirmed credentials file contains valid tokens with future expiry
  • Used absolute paths for volume mount instead of ~
  • Added fixed --hostname to ensure consistent container identity
  • Verified the mount is accessible inside the container

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions