$ recombobulate _
home / tips / use-apikeyhelper-to-rotate-credentials-automatically
148

Use apiKeyHelper to Rotate Credentials Automatically

recombobulate @recombobulate · Mar 26, 2026 · Configuration
use-apikeyhelper-to-rotate-credentials-automatically

If your team uses short-lived tokens from a vault or credential manager, hardcoding an API key won't cut it. The apiKeyHelper setting lets you point Claude Code at a script that returns a fresh key on demand.

{
  "apiKeyHelper": "~/.claude/get-api-key.sh"
}

Your script just needs to print a valid API key to stdout:

#!/bin/bash
# Fetch a short-lived token from your secrets manager
vault read -field=api_key secret/claude-code

Claude Code calls this script after 5 minutes of inactivity or immediately on an HTTP 401 response. If you need a different refresh interval, set the CLAUDE_CODE_API_KEY_HELPER_TTL_MS environment variable:

# Refresh every 2 minutes instead of the default 5
export CLAUDE_CODE_API_KEY_HELPER_TTL_MS=120000

One thing to watch: if your helper script takes longer than 10 seconds, Claude Code shows a warning in the prompt bar. If you're seeing that regularly, check whether your credential script can be optimised.

Note that apiKeyHelper only applies to terminal CLI sessions. Claude Desktop and remote sessions use OAuth exclusively.

Stop hardcoding keys. Let Claude Code fetch fresh credentials from your vault automatically.


via Claude Code Docs — Authentication

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Describe Your Users in CLAUDE.md So Claude Writes Appropriate Copy, Error Messages, and UX

When Claude writes error messages, button labels, validation text, or onboarding flows, it defaults to generic developer-speak. Add a "Users" section to your CLAUDE.md describing who your actual users are — their technical level, industry jargon, and what they care about — so Claude writes copy that makes sense to THEM, not to developers.

recombobulate @recombobulate · 1 month ago
1
Create Custom Agents with --agent for Scoped Sessions

Use the --agent flag with custom markdown files in .claude/agents/ to launch purpose-built Claude sessions with restricted tools and scoped system prompts.

recombobulate @recombobulate · 1 month ago
106
Add Known Gotchas and Pitfalls to Your CLAUDE.md So Claude Avoids Mistakes Your Team Already Made

Every project has traps — the billing module that silently fails if you forget to queue the job, the legacy table with column names that don't match the model, the config value that must be set before tests run. Document these gotchas in your CLAUDE.md so Claude avoids the same mistakes your team spent days debugging.

recombobulate @recombobulate · 1 month ago