Skip to content

Commit a412f8e

Browse files
Claudeclaude
andcommitted
fix: make claude code api key helper validation conditional
The validation was failing in smoke-claude workflow because: - Entrypoint validation runs before the user command executes - The config file (~/.claude/config.json) is created by the user command - Previous implementation required config file to exist, causing exit 1 Changes: - Made validation conditional: only validate if config file exists - If config file doesn't exist, log informative message and continue - This allows user commands to create the config file after entrypoint runs - Validation still occurs when config file exists (e.g., mounted from host) Fixes comment 3902171070 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 79b23be commit a412f8e

1 file changed

Lines changed: 26 additions & 24 deletions

File tree

containers/agent/entrypoint.sh

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -123,35 +123,37 @@ fi
123123
# This ensures the apiKeyHelper is properly configured in the config file
124124
# If validation fails, exit before running the agent to prevent using wrong credentials
125125
if [ -n "$CLAUDE_CODE_API_KEY_HELPER" ]; then
126-
echo "[entrypoint] Validating Claude Code API key helper configuration..."
126+
echo "[entrypoint] Claude Code API key helper configured: $CLAUDE_CODE_API_KEY_HELPER"
127127

128-
# Check if config file exists
128+
# Check if config file exists - if it does, validate it
129+
# If it doesn't exist yet, skip validation (it may be created by the user command)
129130
CONFIG_FILE="$HOME/.claude/config.json"
130-
if [ ! -f "$CONFIG_FILE" ]; then
131-
echo "[entrypoint][ERROR] Claude Code config file not found at $CONFIG_FILE"
132-
echo "[entrypoint][ERROR] Cannot verify apiKeyHelper configuration"
133-
exit 1
134-
fi
131+
if [ -f "$CONFIG_FILE" ]; then
132+
echo "[entrypoint] Validating existing Claude Code config file..."
133+
134+
# Check if apiKeyHelper is present in config file
135+
if ! grep -q '"apiKeyHelper"' "$CONFIG_FILE"; then
136+
echo "[entrypoint][ERROR] apiKeyHelper not found in Claude Code config file"
137+
echo "[entrypoint][ERROR] Expected: {\"apiKeyHelper\":\"$CLAUDE_CODE_API_KEY_HELPER\"}"
138+
echo "[entrypoint][ERROR] Actual config:"
139+
cat "$CONFIG_FILE" >&2
140+
exit 1
141+
fi
135142

136-
# Check if apiKeyHelper is present in config file
137-
if ! grep -q '"apiKeyHelper"' "$CONFIG_FILE"; then
138-
echo "[entrypoint][ERROR] apiKeyHelper not found in Claude Code config file"
139-
echo "[entrypoint][ERROR] Expected: {\"apiKeyHelper\":\"$CLAUDE_CODE_API_KEY_HELPER\"}"
140-
echo "[entrypoint][ERROR] Actual config:"
141-
cat "$CONFIG_FILE" >&2
142-
exit 1
143-
fi
143+
# Verify the value matches the environment variable
144+
CONFIGURED_HELPER=$(grep -o '"apiKeyHelper":"[^"]*"' "$CONFIG_FILE" | cut -d'"' -f4)
145+
if [ "$CONFIGURED_HELPER" != "$CLAUDE_CODE_API_KEY_HELPER" ]; then
146+
echo "[entrypoint][ERROR] apiKeyHelper mismatch:"
147+
echo "[entrypoint][ERROR] Environment variable: $CLAUDE_CODE_API_KEY_HELPER"
148+
echo "[entrypoint][ERROR] Config file value: $CONFIGURED_HELPER"
149+
exit 1
150+
fi
144151

145-
# Verify the value matches the environment variable
146-
CONFIGURED_HELPER=$(grep -o '"apiKeyHelper":"[^"]*"' "$CONFIG_FILE" | cut -d'"' -f4)
147-
if [ "$CONFIGURED_HELPER" != "$CLAUDE_CODE_API_KEY_HELPER" ]; then
148-
echo "[entrypoint][ERROR] apiKeyHelper mismatch:"
149-
echo "[entrypoint][ERROR] Environment variable: $CLAUDE_CODE_API_KEY_HELPER"
150-
echo "[entrypoint][ERROR] Config file value: $CONFIGURED_HELPER"
151-
exit 1
152+
echo "[entrypoint] ✓ Claude Code API key helper validated: $CLAUDE_CODE_API_KEY_HELPER"
153+
else
154+
echo "[entrypoint] Config file not found yet - will be created by user command"
155+
echo "[entrypoint] Environment variable set: CLAUDE_CODE_API_KEY_HELPER=$CLAUDE_CODE_API_KEY_HELPER"
152156
fi
153-
154-
echo "[entrypoint] ✓ Claude Code API key helper validated: $CLAUDE_CODE_API_KEY_HELPER"
155157
fi
156158

157159
# Print proxy environment

0 commit comments

Comments
 (0)