This page walks you through a complete, production-grade Go client that connects to the keychain-auth daemon over Unix domain sockets on macOS and Linux, or Windows Named Pipes on Windows. You will learn how to enforceDocumentation Index
Fetch the complete documentation index at: https://theseventeen-2abbdf80.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
SOCK_CLOEXEC to prevent file descriptor leaks, send batch write requests, and retrieve secrets in a single round trip using prefix matching.
Full client implementation
The following is a complete, production-grade Go client you can paste into amain.go file and extend for your integration.
Key sections explained
Creating the socket with SOCK_CLOEXEC
On macOS and Linux, the client creates the raw file descriptor directly via This is not a post-creation flag set — the flag is applied atomically at socket creation time, eliminating the race window between
syscall.Socket rather than using the higher-level net.Dial. The second argument combines syscall.SOCK_STREAM with syscall.SOCK_CLOEXEC in a single atomic syscall:socket() and a separate fcntl(FD_CLOEXEC) call.Cross-platform connection: Unix socket vs Windows Named Pipe
The client detects the platform at runtime using On macOS the socket is at
runtime.GOOS and branches accordingly:~/Library/Application Support/keychain-auth/agent.sock. On Linux it uses $XDG_RUNTIME_DIR/keychain-auth/agent.sock (fallback: ~/.cache/keychain-auth/agent.sock). On Windows, the Named Pipe path is fixed at \\.\pipe\keychain-auth.Sending a batch write request
A batch write groups multiple targets and values into a single request. The The
targets and values arrays must have the same length — the daemon rejects mismatched arrays with malformed_request.SendRequest method marshals the struct to JSON, appends a newline terminator, and writes it to the connection in one call.Sending a prefix read request
Setting Your binary policy must have
Match to "prefix" and supplying a trailing-slash target tells the daemon to enumerate and return all keys whose names begin with that prefix. This retrieves an entire environment’s secrets in a single round trip instead of N individual reads.can_search: true for prefix reads to be authorized, because the daemon must enumerate keys server-side to resolve the prefix.Parsing the response
The daemon always responds with a single newline-terminated JSON line. When
SendRequest reads up to the newline using bufio.Reader.ReadBytes, then unmarshals into the Response struct:Status is not "success", the Reason field contains one of the documented reason codes such as unregistered_binary_pending_approval, service_not_allowed, or action_not_in_policy. Your integration should handle each of these explicitly.