How to Authenticate Agents
Set up authentication so Headjack containers can use your AI subscriptions or API keys. All credentials are stored securely in the system keychain and automatically injected into containers at runtime.
Prerequisites
- Headjack installed
- For subscription authentication: The CLI for your chosen agent installed and a valid subscription
- For API key authentication: An API key from the provider
Authentication Methods
Each agent supports two authentication methods:
| Method | Billing | Best For |
|---|---|---|
| Subscription | Uses your existing subscription (Claude Pro/Max, ChatGPT Plus/Pro, Gemini) | Users with active subscriptions |
| API Key | Pay-per-use API billing | Users without subscriptions or who prefer usage-based billing |
Claude
Run the authentication command:
hjk auth claude
Choose your authentication method when prompted:
Subscription (Claude Pro/Max)
- Select option 1
- In a separate terminal, run
claude setup-token - Complete the browser login flow
- Copy the token (starts with
sk-ant-) - Paste it when prompted
API Key
- Select option 2
- Enter your Anthropic API key (starts with
sk-ant-api)
Gemini
Run the authentication command:
hjk auth gemini
Choose your authentication method when prompted:
Subscription (Google AI)
If you have existing Gemini CLI credentials (~/.gemini/), they are automatically detected.
If not found:
- Run
geminiin a separate terminal - Complete the Google OAuth login
- Run
hjk auth geminiagain
API Key
- Select option 2
- Enter your Google AI API key (starts with
AIza)
Codex
Run the authentication command:
hjk auth codex
Choose your authentication method when prompted:
Subscription (ChatGPT Plus/Pro/Team)
If you have existing Codex CLI credentials (~/.codex/auth.json), they are automatically detected.
If not found:
- Run
codex loginin a separate terminal - Complete the OAuth flow in your browser
- Run
hjk auth codexagain
API Key
- Select option 2
- Enter your OpenAI API key (starts with
sk-)
Verification
After authentication, verify by running an agent:
hjk run my-feature --agent claude # or gemini, codex
The agent should authenticate without prompting for login.
Switching Authentication Methods
To switch between subscription and API key:
hjk auth claude # Select the other option
hjk recreate my-feature # Recreate container with new credentials
Notes
- Subscription credentials use your subscription, not API billing
- API key credentials are billed per-use through the provider's API
- Credentials are stored in the system keychain (macOS Keychain, GNOME Keyring, etc.)
- Re-run the auth command if authentication fails or tokens expire