--- title: Claude Code: auth login succeeds in the browser, then "not logged in" (~/.claude owned by root) date: 2026-06-28 summary: claude auth login completes in the browser, then Claude Code says it is not logged in and gives up after a few retries. ~/.claude was owned by root after claude had once been run as root with the user's HOME, so the token file could not be written. chown the directory back to the user. tags: claude-code, linux, arch, permissions, sudo environment: Arch Linux (three machines); Claude Code version not recorded; on one machine installed with npm into ~/.npm-global author: shaun, written up with Claude status: published --- ## Symptoms Running `claude auth login` as a normal user: - The browser OAuth flow completes and says the app is authorized. - Claude Code then reports that it is **not logged in**, retries about three times, and gives up. - `claude auth status` shows: ```json {"loggedIn": false, "authMethod": "none"} ``` - No `~/.claude/.credentials.json` is ever created. ## Root cause `~/.claude/` (and `~/.claude/skills/`) were owned by **root**, mode 755: ```bash ls -ld ~/.claude ~/.claude/skills # owner shows as root instead of the user ``` Claude Code saves the OAuth token to `~/.claude/.credentials.json`. The user cannot create files in a root-owned directory, so the token is never written and every check reads "logged out". The login itself works; only saving it fails. The directory had been created by a single run of `claude` **as root with the user's HOME** during setup (a `sudo claude`, or a skills install run as root). Nothing kept re-breaking it; it was a one-off. The exact command that did it was not identified, only the time window from the directory timestamps. ## Fix Give the directory back to the user, then log in again: ```bash sudo chown -R user:user ~/.claude claude auth login claude auth status # should now report "loggedIn": true ``` After the `chown`, `claude auth login` saved the credentials normally. The same latent problem was found and fixed on two other machines set up the same way. To avoid it: **do not run `claude` as root with a normal user's HOME** (`sudo claude`, or root with `HOME` pointing at a user's home). It leaves `~/.claude` owned by root and silently breaks that user's login and skill sync. ## Unrelated: "claude: command not found" in some shells On one machine there was a second, unrelated symptom: typing `claude` in an interactive shell gave `command not found`. Claude Code was installed with npm into `~/.npm-global`, and `~/.npm-global/bin` was added to `PATH` only in `~/.bash_profile`, not in `~/.bashrc`. Login shells found `claude`; non-login interactive shells did not. Fix: add it in `~/.bashrc` too: ```bash export PATH="$HOME/bin:$HOME/.npm-global/bin:$PATH" ```