feat: Claude Desktop personal/work profile launchers, claude:// dispatcher and handlers (Linux only)

This commit is contained in:
bcherb2 committed 2026-11-18 01:30:14 -05:00
1 parent b4d8701665
commit 9baaf78522
11 files changed
+172

No files matched your search

+14
View File
@@ -30,6 +30,20 @@ README.md
# box once and then leaves herdr's rewrites alone.) # box once and then leaves herdr's rewrites alone.)
.config/btop/btop.conf .config/btop/btop.conf
# Claude Desktop profile launchers (personal/work), their xdg-open shims, the
# claude:// dispatcher and their .desktop entries. Claude Desktop on Linux is
# the community package at /usr/bin/claude-desktop; macOS has the real app and
# no .desktop files, so none of this applies there.
{{ if ne .chezmoi.os "linux" }}
.local/bin/claude-personal
.local/bin/claude-work
.local/bin/claude-url-dispatch
.local/share/claude-shims
.local/share/claude-shims/**
.local/share/applications
.local/share/applications/**
{{ end }}
# Belt and braces on the tier boundary. The public repo does not manage any of # Belt and braces on the tier boundary. The public repo does not manage any of
# these and must never start: a stray `chezmoi add ~/.config/gh` would # these and must never start: a stray `chezmoi add ~/.config/gh` would
# otherwise sweep up an OAuth token, and the same for the bws token and the # otherwise sweep up an OAuth token, and the same for the bws token and the
@@ -0,0 +1,32 @@
{{- if eq .chezmoi.os "linux" -}}
#!/bin/sh
# Point the claude:// and claude-cli:// URL schemes at our handlers.
#
# ~/.config/mimeapps.list is rewritten by every desktop and by xdg-mime itself,
# so it is not a file this repo can own. Setting the two defaults through
# xdg-mime touches only those two lines.
#
# claude:// -> claude-url-dispatch, which routes OAuth callbacks and
# deep links to the Claude Desktop profile that asked for
# them. The packaged com.anthropic.Claude.desktop starts an
# unflagged instance that cannot keep the sign-in.
# claude-cli:// -> Claude Code's own handler.
#
# Linux only (the template renders empty elsewhere, and chezmoi skips an empty
# script). Skipped with a note when xdg-mime is absent, e.g. a headless box.
# It re-runs when this file changes, or when a handler's .desktop does:
# dispatch {{ include "dot_local/share/applications/claude-url-dispatch.desktop.tmpl" | sha256sum }}
# cli {{ include "dot_local/share/applications/create_claude-code-url-handler.desktop.tmpl" | sha256sum }}
set -u
if ! command -v xdg-mime >/dev/null 2>&1; then
echo "claude URL handlers: xdg-mime not found, skipped" >&2
exit 0
fi
rc=0
xdg-mime default claude-url-dispatch.desktop x-scheme-handler/claude || rc=1
xdg-mime default claude-code-url-handler.desktop x-scheme-handler/claude-cli || rc=1
[ "$rc" -eq 0 ] || echo "claude URL handlers: xdg-mime failed; set them by hand with xdg-mime default" >&2
exit 0
{{ end -}}
+17
View File
@@ -0,0 +1,17 @@
#!/bin/zsh
# Claude Desktop — isolated "personal" profile.
# --user-data-dir : separate Electron profile; also separates the
# single-instance lockfile, which is what allows a
# second concurrent instance to run at all.
# --password-store : app only auto-detects on KDE; XFCE would fall back
# to basic_text, where safeStorage is unavailable and
# OAuth tokens do not survive a restart.
# --class : distinct WM_CLASS so xfwm/taskbar treats the two
# windows as separate apps.
export CLAUDE_CONFIG_DIR="${CLAUDE_CONFIG_DIR:-$HOME/.claude}"
export PATH="$HOME/.local/share/claude-shims/personal:$PATH"
exec /usr/bin/claude-desktop \
--user-data-dir="$HOME/.local/share/claude-personal" \
--password-store=gnome-libsecret \
--class=ClaudePersonal \
"$@"
+45
View File
@@ -0,0 +1,45 @@
#!/bin/zsh
# Routes claude:// URLs (OAuth callbacks, deep links) to the correct profile.
#
# The packaged entry runs plain `claude-desktop %U` with no flags, which
# starts an unflagged default-profile instance that has no keyring backend
# and cannot save the sign-in. This picks the right profile instead.
#
# Ordering:
# 1. A fresh hint written by that profile's xdg-open shim when the app
# opened the browser -- this is the authoritative signal, and it is
# consumed on use so it can never misroute a later link.
# 2. Whichever profile is the only one running.
# 3. The most recently started instance, else personal.
#
# Handing the URL to the profile wrapper is safe: Electron's second-instance
# handler forwards it into the running instance with that --user-data-dir.
url="$1"
hint="$HOME/.config/claude-profile-target"
HINT_MAX_AGE=600 # seconds; ignore an abandoned sign-in attempt
running() { pgrep -f -- "--user-data-dir=$HOME/.local/share/claude-$1" >/dev/null 2>&1 }
target=""
if [[ -r "$hint" ]]; then
age=$(( $(date +%s) - $(stat -c %Y "$hint") ))
if (( age <= HINT_MAX_AGE )); then
candidate="$(<"$hint")"
[[ "$candidate" == (personal|work) ]] && target="$candidate"
fi
rm -f "$hint"
fi
if [[ -z "$target" ]]; then
if running personal && ! running work; then
target=personal
elif running work && ! running personal; then
target=work
else
target=$(for p in personal work; do
pid=$(pgrep -f -- "--user-data-dir=$HOME/.local/share/claude-$p" | head -1)
[[ -n "$pid" ]] && echo "$(ps -o lstart= -p $pid | xargs -I{} date -d {} +%s) $p"
done | sort -rn | head -1 | cut -d' ' -f2)
target="${target:-personal}"
fi
fi
exec "$HOME/.local/bin/claude-$target" "$url"
+17
View File
@@ -0,0 +1,17 @@
#!/bin/zsh
# Claude Desktop — isolated "work" profile.
# --user-data-dir : separate Electron profile; also separates the
# single-instance lockfile, which is what allows a
# second concurrent instance to run at all.
# --password-store : app only auto-detects on KDE; XFCE would fall back
# to basic_text, where safeStorage is unavailable and
# OAuth tokens do not survive a restart.
# --class : distinct WM_CLASS so xfwm/taskbar treats the two
# windows as separate apps.
export CLAUDE_CONFIG_DIR="${CLAUDE_CONFIG_DIR:-$HOME/.claude-work}"
export PATH="$HOME/.local/share/claude-shims/work:$PATH"
exec /usr/bin/claude-desktop \
--user-data-dir="$HOME/.local/share/claude-work" \
--password-store=gnome-libsecret \
--class=ClaudeWork \
"$@"
@@ -0,0 +1,10 @@
[Desktop Entry]
Name=Claude (Personal)
Comment=Claude Desktop — personal account
GenericName=AI Assistant
Exec={{ .chezmoi.homeDir }}/.local/bin/claude-personal %U
Icon=claude-desktop
Type=Application
StartupNotify=true
StartupWMClass=ClaudePersonal
Categories=Utility;Development;
@@ -0,0 +1,6 @@
[Desktop Entry]
Name=Claude (profile-aware link handler)
Exec={{ .chezmoi.homeDir }}/.local/bin/claude-url-dispatch %u
Type=Application
NoDisplay=true
MimeType=x-scheme-handler/claude;
@@ -0,0 +1,10 @@
[Desktop Entry]
Name=Claude (Work)
Comment=Claude Desktop — work account
GenericName=AI Assistant
Exec={{ .chezmoi.homeDir }}/.local/bin/claude-work %U
Icon=claude-desktop
Type=Application
StartupNotify=true
StartupWMClass=ClaudeWork
Categories=Utility;Development;
@@ -0,0 +1,7 @@
[Desktop Entry]
Name=Claude Code URL Handler
Comment=Handle claude-cli:// deep links for Claude Code
Exec="{{ .chezmoi.homeDir }}/.local/bin/claude" --handle-uri %u
Type=Application
NoDisplay=true
MimeType=x-scheme-handler/claude-cli;
@@ -0,0 +1,7 @@
#!/bin/sh
# PATH shim, injected only into the "personal" Claude instance.
# Electron shells out to xdg-open (via PATH) to open the browser for
# sign-in. Recording the profile here is what lets the claude:// callback
# find its way back to the instance that actually started the login.
printf '%s' "personal" > "$HOME/.config/claude-profile-target" 2>/dev/null
exec /usr/bin/xdg-open "$@"
+7
View File
@@ -0,0 +1,7 @@
#!/bin/sh
# PATH shim, injected only into the "work" Claude instance.
# Electron shells out to xdg-open (via PATH) to open the browser for
# sign-in. Recording the profile here is what lets the claude:// callback
# find its way back to the instance that actually started the login.
printf '%s' "work" > "$HOME/.config/claude-profile-target" 2>/dev/null
exec /usr/bin/xdg-open "$@"