[BUG] `claude` on Mac deletes the `.credentials.json` file that `claude` on Linux uses

Status Fixed / completed
Maintainer reply None cached
Activity 9 comments · opened May 29, 2025 · closed Jun 17, 2025

Environment

  • Platform (select one):
  • [x] Anthropic API
  • [ ] AWS Bedrock
  • [ ] Google Vertex AI
  • [ ] Other: <!-- specify -->
  • Claude CLI version: <!-- output of claude --version --> 1.0.5
  • Operating System: <!-- e.g. macOS 14.3, Windows 11, Ubuntu 22.04 --> macOS + ubuntu image
  • Terminal: <!-- e.g. iTerm2, Terminal App --> alacritty

Bug Description

I run claude both on Mac natively and using containers. when I use a container, I map in .claude as a volume to share settings. linux writes its creds to .claude/.credentials.json; mac doesn't use them.

I was finding that I'd need to log into claude code when again fairly often when using containers, and that the creds file was disappearing. I added a probe and it shows that it's the Mac claude process deleting the file — below we can see unlink from a node process.

is that intended? does it expire?! assuming it doesn't expire, ideally claude wouldn't delete files just because it doesn't need them.

sudo fs_usage -w -f filesystem \
       | grep -iE '\.claude/\.credentials\.json'

Password:
09:44:10.978130  access                       (___F)    /Users/maximilian/.claude/.credentials.json                                                                                                                           0.000006   node.36584176
09:44:10.978389  unlink                                 /Users/maximilian/.claude/.credentials.json                                                                                                                           0.000235   node.36584176
09:44:11.114233  lstat64                [  2]           /System/Volumes/Data/Users/maximilian/.claude/.credentials.json                                                                                                       0.000014   fseventsd.450762

View original on GitHub ↗

9 Comments

ghost · 1 year ago

Thanks for the report! This is intended behavior (cleaning up plain text credentials when successfully storing them in macos keychain), but would be curious to hear about your workflow. Would running inside the container with a different CLAUDE_CONFIG_DIR path work for you?

max-sixty · 1 year ago
This is intended behavior (cleaning up plain text credentials when successfully storing them in macos keychain)

ok — though that means it's not possible to run in a container without logging in on each switch to & back

Would running inside the container with a different CLAUDE_CONFIG_DIR path work for you?

I can mount a different path — ~/.claude-linux:~/.claude and have a task which copies over my CLAUDE.md to ~/.claude-linux/ at some frequency I guess? doesn't seem ideal

or if claude is going to clean up things it doesn't use from other OSs, should it put them in OS-specific paths, such as ~/.claude/linux/.credentials.json...

ghost · 1 year ago
have a task which copies over my CLAUDE.md to ~/.claude-linux/ at some frequency

You can use CLAUDE.md imports instead of copying over (i.e. have container dir's CLAUDE.md import your main one)!

max-sixty · 1 year ago

but the current state of claude prevents mounting ~/.claude into the container! so ~/.claude/CLAUDE.md isn't then available in the container

does that make sense?

(unless it's a proposal to have two mounts to differently named locations and then map one back into the other with an import that's invalid on the host)

ghost · 1 year ago

you could create a CLAUDE.md file inside your container mounted dir and then @- import it from ~/.claude/CLAUDE.md to avoid needing two mounts

twt-- · 1 year ago

This sounds like a lot of workarounds for what I'm guessing would actually be a really simple fix in claude code :(. Just give us a config parameter to set so ~/claude/.credentials.json isn't deleted or give us a CLAUDE_CREDENTIALS_FILE env var that we can use in container configs so that we can use ~/.claude/.container-credentials.json as the credentials file.

As for use case, I do almost all of my dev work in devcontainers. This is an example config of how I've got things setup to use claude code. Copy this json to ${mydir}/.devcontainer/devcontainer.json, load ${mydir} in vscode, and then have vscode load up the devcontainer.

{
  "name": "Claude Code Devcontainer Example",
  "image": "mcr.microsoft.com/devcontainers/base:bookworm",
  "mounts": [
    {
      "source": "${localEnv:HOME}/.claude/",
      "target": "/home/vscode/.claude",
      "type": "bind"
    },
    {
      "source": "${localEnv:HOME}/.claude.json",
      "target": "/home/vscode/.claude.json",
      "type": "bind"
    }
  ],
  "features": {
    "ghcr.io/devcontainers/features/node:1": {}
  },
  "onCreateCommand": "npm install -g @anthropic-ai/claude-code"
}

I know devcontainer users are in the minority, but considering you guys maintain a devcontainer feature (https://github.com/anthropics/devcontainer-features/tree/main), it would be really nice if we didn't have to re-login due to the credentials getting deleted on the host machine.

tkowalski29 · 1 year ago

any news?

pvillega · 1 year ago

@levpopov this should be reopened. Using containers to isolate Claude code instances is becoming more popular. The current behaviour is problematic for people using these flows. Either fix this, or, ideally, provide a way for M2M authentication so we don't need to rely on that file.

github-actions[bot] · 1 year ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.