Created
May 29, 2026 08:48
-
-
Save schappim/aa283479f4a226c51d03f278839f1ea4 to your computer and use it in GitHub Desktop.
Prevent Claude from forcing you to log in again when accessing Claude via SSH on your machine.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # `cl` wrapper: keep ~/.claude/.credentials.json in sync with the macOS | |
| # Keychain on local (GUI) runs so SSH sessions — which can't read Keychain — | |
| # fall back to the credentials file. See ~/.claude for the fallback logic. | |
| cl() { | |
| if [ -z "$SSH_CONNECTION" ] && [ -z "$SSH_CLIENT" ] && [ -z "$SSH_TTY" ]; then | |
| local cred | |
| cred=$(security find-generic-password -a "$USER" -s "Claude Code-credentials" -w 2>/dev/null) | |
| if [ -n "$cred" ]; then | |
| mkdir -p ~/.claude | |
| print -r -- "$cred" > ~/.claude/.credentials.json | |
| chmod 600 ~/.claude/.credentials.json | |
| fi | |
| elif [ ! -s ~/.claude/.credentials.json ]; then | |
| print -u2 -- "cl: no ~/.claude/.credentials.json on this SSH session — run \`cl\` once locally to sync the Keychain token, then retry." | |
| return 1 | |
| fi | |
| command claude --dangerously-skip-permissions "$@" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment