[BUG] When running Claude Code from an Automator service on macOS, Claude cannot read my login credentials
Environment
- Platform (select one):
- [ ] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [x] Other: Claude Max Plan
- Claude CLI version: 0.2.117
- Operating System: macOS
- Terminal: Automator's
Run Shell Scriptaction
Bug Description
I want to create an Automator service / Quick Action that that invokes Claude Code in non-interactive (-p) mode. I can create a workflow and add a run shell script action with the contents:
cat | /usr/local/bin/claude -p "Review this code"
This actually works if I run the workflow within Automator! However, if I save it as a service that takes in text, highlight some text within an app, and run the service from the context menu, I always get an error: Invalid API key · Please run /login.
Because I'm using the Claude Max plan instead of an API key, I can't fix this problem by setting the ANTHROPIC_API_KEY environment variable.
I can see that my oauth credentials are saved in Keychain Access as Claude Code-credentials. I can also successfully access the credentials from my Automator service via security find-generic-password -s "Claude Code-credentials" -w. However, as far as I can tell there is no way to pass this information to Claude Code itself.
I think this use case may be too niche for the team to fix. However, I would appreciate any information on how I can supply my login to Claude non-interactively, or even what npm package Claude uses internally to read and write credentials to Keychain Access, since this may be an upstream issue.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗