I wanted to use Sentry's CLI tool sentry-cli across multiple organizations, but it lacks native multi-profile support like AWS CLI's --profile.
brew install getsentry/tools/sentry-cli
According to the official docs, configuration is loaded in this priority:
-o, -p, --auth-token)SENTRY_AUTH_TOKEN, SENTRY_ORG, SENTRY_PROJECT).sentryclirc file (searched upward from current directory)~/.sentryclirc (global default)The .sentryclirc filename is fixed — renamed files like .sentryclirc-staging won't be loaded (ref).
Sentry provides an MCP server for direct AI agent integration with Sentry. However, it has several drawbacks:
In the end, a CLI wrapper + AI agent skill is a lighter and more flexible approach.
A zsh function always takes priority over a same-named binary in PATH, so defining a function called sentry-cli automatically wraps the brew-installed binary.
~/.config/sentry-cli/profiles/<name>.env
Simple env file format:
SENTRY_AUTH_TOKEN=sntrys_xxx...
SENTRY_ORG=my-org
SENTRY_URL=https://my-org.sentry.io/
SENTRY_PROJECT should not be fixed in the profile — specify it with -p at runtime since orgs typically contain multiple projects.
Add this to your ~/.zshrc or shell aliases file:
function sentry-cli () {
local _sentry_cli
# whence -p: skip functions, return only binary paths
_sentry_cli=$(whence -p sentry-cli) || { echo "sentry-cli not found" >&2; return 1; }
local profile_dir="${HOME}/.config/sentry-cli/profiles"
local profile=""
local setup=0
local args=()
while [[ $# -gt 0 ]]; do
case "$1" in
--profile=*) profile="${1#--profile=}"; shift ;;
--profile) profile="$2"; shift 2 ;;
--profiles)
if [[ -d "$profile_dir" ]]; then
for f in "$profile_dir"/*.env(N); do echo "${f:t:r}"; done
else
echo "No profiles directory: $profile_dir" >&2
fi
return 0 ;;
--setup) setup=1; shift ;;
*) args+=("$1"); shift ;;
esac
done
if [[ $setup -eq 1 ]]; then
[[ -z "$profile" ]] && { echo "Usage: sentry-cli --profile=<name> --setup" >&2; return 1; }
mkdir -p "$profile_dir"
local pfile="${profile_dir}/${profile}.env"
if [[ ! -f "$pfile" ]]; then
cat > "$pfile" <<TMPL
SENTRY_AUTH_TOKEN=
SENTRY_ORG=${profile}
SENTRY_URL=https://${profile}.sentry.io/
TMPL
fi
${EDITOR:-vim} "$pfile"
return 0
fi
if [[ -z "$profile" ]]; then
"$_sentry_cli" "${args[@]}"
return $?
fi
local pfile="${profile_dir}/${profile}.env"
[[ ! -f "$pfile" ]] && { echo "Profile not found: $pfile" >&2; return 1; }
# Run in subshell to avoid polluting current environment
( set -a; source "$pfile"; set +a; "$_sentry_cli" "${args[@]}" )
}
command -v TrapMy initial implementation used command -v sentry-cli to find the binary path, but zsh's command -v also returns functions — causing infinite recursion and the dreaded maximum nested function level reached; increase FUNCNEST? error.
Use whence -p instead, which skips functions and returns only binary paths. This is a zsh built-in.
# Create a profile (opens editor)
sentry-cli --profile=myorg --setup
# Check connection
sentry-cli --profile=myorg info
# List projects
sentry-cli --profile=myorg projects list
# List releases for a specific project
sentry-cli --profile=myorg releases list -p my-project
# List all profiles
sentry-cli --profiles
# Without profile (normal sentry-cli passthrough)
sentry-cli info
I also registered this wrapper as a Claude Code skill with a SKILL.md file, enabling the AI agent to naturally use sentry-cli --profile=xxx for Sentry operations.
Here's the full skill definition:
---
name: sentry-cli
description: Multi-profile wrapper for Sentry CLI. Release management, sourcemap uploads, event sending, etc.
allowed-tools: Bash(sentry-cli:*)
---
# Sentry CLI (multi-profile wrapper)
A zsh wrapper for using Sentry CLI with multiple profiles.
## Important: Check help before operations
If unsure about subcommands or arguments, read the help first.
sentry-cli --help
sentry-cli <subcommand> --help
## Profile Management
- Create/edit: sentry-cli --profile=<name> --setup
- List profiles: sentry-cli --profiles
- Run with profile: sentry-cli --profile=<name> <subcommand> [options]
- Run without profile: sentry-cli <subcommand> [options]
## Common Subcommands
- info: Check connection and auth status
- releases: List, create, finalize releases
- sourcemaps: Upload sourcemaps
- send-event: Send test events
- deploys: Record deployments
- issues: List and resolve issues
- projects: List projects
Key design decisions:
allowed-tools: Bash(sentry-cli:*) grants the agent permission to execute sentry-cli commands--help before operations prevent incorrect subcommand arguments--profile switchingwhence -p instead of command -v to avoid infinite recursion