-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup-claude-session.sh
More file actions
executable file
·34 lines (27 loc) · 990 Bytes
/
setup-claude-session.sh
File metadata and controls
executable file
·34 lines (27 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env bash
# setup-claude-session.sh
#
# Adds a shell wrapper so every 'claude' invocation gets a unique
# x-litellm-session-id header. This enables session-based routing
# affinity in LiteLLM for better prompt caching.
set -euo pipefail
MARKER="# claude-session-affinity"
SHELL_RC="$HOME/.bashrc"
# Use .zshrc if running zsh
if [ -n "${ZSH_VERSION:-}" ] || [ "$(basename "$SHELL")" = "zsh" ]; then
SHELL_RC="$HOME/.zshrc"
fi
if grep -qF "$MARKER" "$SHELL_RC" 2>/dev/null; then
echo "Session affinity wrapper already installed in $SHELL_RC — skipping."
exit 0
fi
cat >> "$SHELL_RC" << 'WRAPPER'
# claude-session-affinity
# Injects a unique session ID header per claude invocation for LiteLLM routing
claude-session() {
ANTHROPIC_CUSTOM_HEADERS="x-litellm-session-id: $(uuidgen)" command claude "$@"
}
alias claude='claude-session'
WRAPPER
echo "Session affinity wrapper added to $SHELL_RC"
echo "Run 'source $SHELL_RC' or open a new terminal to activate."