Skip to main content
interlace
Plugin: anthropic-securityRules

no-hardcoded-api-key

Forbid a literal API key in the Anthropic client options

Forbid a literal API key in the Anthropic client options.

Why

A key written into source is committed, pushed, mirrored into every clone and CI cache, and is billable by anyone who reads it. Because rotating it means a code change, leaked keys tend to stay live far longer than they should.

Covers apiKey and authToken on both @anthropic-ai/sdk and @anthropic-ai/claude-agent-sdk. An empty string is treated as a placeholder, not a credential.

Incorrect

import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({ apiKey: 'sk-ant-api03-...' });

Correct

import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });

Did this rule catch something? Star the repo to get new CWE coverage as we ship it โ€” or follow the AI-code-security benchmarks behind these rules.