claude-code - 💡(How to fix) Fix Feature Request: SSH-agent-style credential forwarding for remote Claude Code sessions [2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#49136Fetched 2026-04-17 08:49:52
View on GitHub
Comments
2
Participants
3
Timeline
5
Reactions
0
Author
Timeline (top)
labeled ×3commented ×2

Code Example

# Local
eval $(claude-auth-agent)
ssh -R /tmp/claude-auth.sock:$CLAUDE_AUTH_SOCK -p 42222 user@server

# Remote — key never touches the server
export CLAUDE_AUTH_SOCK=/tmp/claude-auth.sock
claude
RAW_BUFFERClick to expand / collapse

Problem

When running Claude Code on a remote server via SSH, credentials (API key or OAuth token) must be stored on the remote filesystem. On shared servers where other users have root access, this is a security concern — root can read tokens from ~/.claude/ or /proc/*/environ.

There is no equivalent to SSH's ssh-agent forwarding, where the secret never leaves the local machine.

Proposed Solution

A local claude-auth-agent daemon (analogous to ssh-agent) that:

  1. Runs on the local machine, holds the API key / OAuth token in memory
  2. Exposes a Unix socket (e.g. CLAUDE_AUTH_SOCK)
  3. The socket is forwarded via ssh -R to the remote server
  4. Remote Claude Code talks to the forwarded socket for API authentication
# Local
eval $(claude-auth-agent)
ssh -R /tmp/claude-auth.sock:$CLAUDE_AUTH_SOCK -p 42222 user@server

# Remote — key never touches the server
export CLAUDE_AUTH_SOCK=/tmp/claude-auth.sock
claude

Why

  • API keys / OAuth tokens never leave the local machine
  • Revocation is instant (kill the local agent)
  • Familiar pattern — every developer already knows ssh-agent forwarding
  • Shared/multi-tenant servers become safe to use

Related Issues

  • #42965 — OAuth broken for remote/headless setups
  • #7100 — Headless/remote authentication (auto-closed)
  • #44089 — Keychain inaccessible from SSH sessions
  • #29717 — SSH_AUTH_SOCK forwarding for 1Password agent

extent analysis

TL;DR

Implement a local claude-auth-agent daemon to securely store and forward API credentials to remote servers via SSH.

Guidance

  • Run the claude-auth-agent daemon on the local machine to hold the API key or OAuth token in memory, exposing a Unix socket for authentication.
  • Forward the socket to the remote server using ssh -R to enable remote Claude Code to authenticate without storing credentials on the server.
  • Set the CLAUDE_AUTH_SOCK environment variable on the remote server to point to the forwarded socket.
  • Verify that the agent is working by checking that the API credentials are not stored on the remote server and that Claude Code can authenticate successfully.

Example

# Local
eval $(claude-auth-agent)
ssh -R /tmp/claude-auth.sock:$CLAUDE_AUTH_SOCK -p 42222 user@server

# Remote
export CLAUDE_AUTH_SOCK=/tmp/claude-auth.sock
claude

Notes

This solution assumes that the claude-auth-agent daemon is implemented and functional. If the daemon is not available, an alternative solution will be needed.

Recommendation

Apply the proposed solution by implementing and using the claude-auth-agent daemon, as it provides a secure way to store and forward API credentials without storing them on the remote server.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING