Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions mise/tasks/vm/claude
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,27 @@ echo "Syncing credentials from host to VM..."
# Ensure .claude directory exists in VM
ssh "${HOSTNAME}" 'mkdir -p ~/.claude'

# Copy .claude.json configuration file
scp ~/.claude.json "${HOSTNAME}:~/.claude.json"

# Extract and copy credentials based on host OS
if [[ "${HOST_OS}" == "mac" ]]; then
# Extract from macOS Keychain and pipe directly to VM
if ! security find-generic-password -s "Claude Code-credentials" -w 2>/dev/null | \
jq -c 'del(.claudeAiOauth.refreshToken)' | \
ssh "${HOSTNAME}" 'cat > ~/.claude/.credentials.json'; then
# Try extracting from macOS Keychain with both possible service names
if security find-generic-password -s "Claude Code-credentials" -w 2>/dev/null | \
jq -c 'del(.claudeAiOauth.refreshToken)' | \
ssh "${HOSTNAME}" 'cat > ~/.claude/.credentials.json'; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compare to the diff -- this dropped logic to strip the refresh token, which shouldn't go into the VM (otherwise it breaks the host's single-use refresh token)

echo "Found credentials under 'Claude Code-credentials'"
elif security find-generic-password -s "Claude Code" -w 2>/dev/null | \
ssh "${HOSTNAME}" 'read key && jq --arg key "$key" ".primaryApiKey = \$key" ~/.claude.json > ~/.claude.json.tmp && mv ~/.claude.json.tmp ~/.claude.json'; then
echo "Found credentials under 'Claude Code'"
else
echo "Error: Could not find Claude Code credentials in macOS Keychain"
echo "Please ensure you are logged in to Claude Code on the host"
exit 1
fi

# Set appropriate permissions
ssh "${HOSTNAME}" 'chmod 700 ~/.claude && chmod 600 ~/.claude/.credentials.json 2>/dev/null || chmod 600 ~/.claude.json'
elif [[ "${HOST_OS}" == "linux" ]]; then
# Copy directly from Linux filesystem
if ! cat ~/.claude/.credentials.json | \
Expand All @@ -55,12 +66,9 @@ elif [[ "${HOST_OS}" == "linux" ]]; then
echo "Please ensure you are logged in to Claude Code on the host"
exit 1
fi
fi

# Copy .claude.json configuration file
scp ~/.claude.json "${HOSTNAME}:~/.claude.json"

# Set appropriate permissions
ssh "${HOSTNAME}" 'chmod 700 ~/.claude && chmod 600 ~/.claude/.credentials.json'
# Set appropriate permissions
ssh "${HOSTNAME}" 'chmod 700 ~/.claude && chmod 600 ~/.claude/.credentials.json'
fi

echo "Claude Code installed and configured in ${HOSTNAME}"
2 changes: 1 addition & 1 deletion mise/tasks/vm/create-post
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ if [[ -d /tmp/idle-shutdown ]]; then
sudo systemctl daemon-reload
sudo systemctl enable --now idle-shutdown.timer
rm -rf /tmp/idle-shutdown
fi
fi
Loading