CLI tools that keep credentials in the macOS Keychain (glab, gh, anything
built on go-keyring or SecKeychain) authenticate fine in a regular
terminal window but fail inside tmux or an agent runtime on the same
machine. glab reports Unauthenticated; security find-generic-password -w prints nothing for an item that exists; writes fail with
User interaction is not allowed. The token is valid, so the failure is
easy to misdiagnose as an expired or missing credential.
securityd scopes Keychain access to the security session of the calling
process, not to the user. A login GUI session is Aqua; processes
spawned through launchd agents, SSH, or other headless paths run in a
Background session. In a Background session, securityd refuses every
Keychain operation that could require user interaction: writes fail
loudly, protected reads return empty data silently.
Check which session a shell is in:
launchctl managernameAqua means Keychain works. Background means keyring-backed tools
will fail no matter how valid the stored token is.
tmux clients do not inherit the security session of the terminal that
attaches. Every pane inherits the session of the tmux server, which is
created by the first tmux invocation and lives until kill-server.
A server started from a launchd agent or another Background context
poisons every session inside it for the server's whole lifetime, even
when you attach from a GUI terminal. The same applies to any agent
runtime launched inside such a server.
Start the tmux server from a GUI terminal in the logged-in desktop
session. Do not use launchctl managername to verify panes: the tmux
server daemonizes, so it reports Background regardless of where it was
born. What it does inherit from its parent is the user namespace that
carries Keychain rights, so an Aqua-born server keeps Keychain access
and a Background-born server does not, while both print the same label.
Verify functionally, with a read of a real protected item:
security find-generic-password -s "<your-item>" -w | wc -c
# > 0 from an Aqua-born server, 0 from a Background-born oneIf a Background server is already running, there are two options.
tmux kill-server destroys all existing sessions and lets the next
tmux start the server in Aqua. To keep the old sessions alive, run a
second server on a dedicated socket instead:
tmux -L aqua new -s work-L aqua creates an independent server bound to the Aqua session; the
old server keeps its sessions until you retire it. Attach with
tmux -L aqua attach from then on.
A quick probe for any running server without attaching:
tmux new-session -d -s probe \
'security find-generic-password -s "<your-item>" -w | wc -c > /tmp/probe; sleep 1'
sleep 1; cat /tmp/probe; tmux kill-session -t probe- Before trusting a keyring-backed CLI in a shell, check
launchctl managernameonce (outside tmux) or run the secret-read probe (inside tmux); both are cheaper than chasing token hypotheses. - Launch agent runtimes that need Keychain (release tooling, keyring auth) from an Aqua terminal or an Aqua-born tmux server.
- git over SSH is unaffected: ssh-agent and key files do not go through securityd session checks, so repository access keeps working from Background sessions even when the Keychain does not.