Claude Code security

API Keys and Secrets Hardcoded in Source Code

Claude Code generated code with API keys, database passwords, or other secrets hardcoded directly in source files. These credentials are now committed to your Git repository and visible to anyone with access to the code.

This is one of the most common security mistakes in AI-assisted development. The AI often places real credentials inline to make the code immediately functional, without considering that the code will be version-controlled and potentially shared.

You may discover this when GitHub sends a secret scanning alert, when a third-party service notifies you of leaked credentials, or when you notice unexpected charges on your cloud account.

Error Messages You Might See

GitHub Secret Scanning: API key detected in commit Warning: Possible credential leak found Authentication failed: API key has been revoked Billing alert: Unauthorized usage detected on your account
GitHub Secret Scanning: API key detected in commitWarning: Possible credential leak foundAuthentication failed: API key has been revokedBilling alert: Unauthorized usage detected on your account

Common Causes

  • Credentials pasted into prompts — You shared API keys in your prompt and Claude Code embedded them directly in the generated files
  • No .env file pattern — The generated project doesn't use environment variables or a .env file for configuration
  • Missing .gitignore — Even if a .env file exists, it's not listed in .gitignore and gets committed
  • Config files with real values — Application config files (config.json, settings.py) contain production credentials as defaults
  • Test files with real keys — Integration tests or seed scripts use actual API keys instead of test/mock credentials

How to Fix It

  1. Search your entire codebase — Use tools like trufflehog, gitleaks, or grep for patterns like 'sk-', 'AKIA', 'ghp_', or 'password=' across all files and Git history
  2. Move all secrets to environment variables — Replace hardcoded values with process.env.KEY_NAME or os.environ['KEY_NAME'] and create a .env.example with placeholder values
  3. Rotate every exposed credential immediately — Generate new keys for every service whose credentials were committed, even if the repo is private
  4. Scrub Git history — Use git filter-branch or BFG Repo Cleaner to remove secrets from past commits
  5. Add pre-commit hooks — Install detect-secrets or gitleaks as a pre-commit hook to prevent future leaks

Real developers can help you.

Taufan Taufan I’m a product-focused engineer and tech leader who builds scalable systems and turns ideas into production-ready platforms. Over the past years, I’ve worked across startups and fast-moving teams, leading backend architecture, improving system reliability, and shipping products used by thousands of users. My strength is not just writing code — but connecting product vision, technical execution, and business impact. legrab legrab I'll fill this later Anthony Akpan Anthony Akpan Developer with 8 years of experience building softwares fro startups ISHANTDEEP SINGH ISHANTDEEP SINGH Senior Software Engineer with 7+ years of experience in React, JavaScript, TypeScript, Next.js, and Node.js. I’ve also worked as a tech lead for startups, owning end-to-end technical execution including architecture, development, scaling, and delivery. I bring a strong mix of hands-on coding, product thinking, and technical leadership, and I’m comfortable building products from scratch as well as improving and scaling existing systems. Matthew Jordan Matthew Jordan I've been working at a large software company named Kainos for 2 years, and mainly specialise in Platform Engineering. I regularly enjoy working on software products outside of work, and I'm a huge fan of game development using Unity. I personally enjoy Python & C# in my spare time, but I also specialise in multiple different platform-related technologies from my day job. Luca Liberati Luca Liberati I work on monoliths and microservices, backends and frontends, manage K8s clusters and love to design apps architecture Krishna Sai Kuncha Krishna Sai Kuncha Experienced Professional Full stack Developer with 8+ years of experience across react, python, js, ts, golang and react-native. Developed inhouse websearch tooling for AI before websearch was solved : ) Basel Issmail Basel Issmail ’m a Senior Full-Stack Developer and Tech Lead with experience designing and building scalable web platforms. I work across the full development lifecycle, from translating business requirements into technical architecture to delivering reliable production systems. My work focuses on modern web technologies, including TypeScript, Angular, Node.js, and cloud-based architectures. I enjoy solving complex technical problems and helping teams turn product ideas and prototypes into working platforms that can grow and scale. In addition to development, I often collaborate closely with product managers, business analysts, designers, and QA teams to ensure that solutions align with both technical and business goals. I enjoy working with startups and product teams where I can contribute both as a hands-on engineer and as a technical partner in designing and delivering impactful software. Tejas Chokhawala Tejas Chokhawala Full-stack engineer with 5 years experience building production web apps using React, Next.js and TypeScript. Focused on performance, clean architecture and shipping fast. Experienced with Supabase/Postgres backends, Stripe billing, and building AI-assisted developer tools. AUXLE AUXLE I am a Full Stack Developer experienced in building Websites, Web apps and Cross Platform Mobile Apps for Startups and Companies.

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help

Frequently Asked Questions

Are my API keys compromised if they were in a private repo?

Treat them as compromised. Private repos can be forked, cloned by team members, or exposed through CI logs. Always rotate keys that were ever committed to any repository.

How do I remove secrets from Git history?

Use BFG Repo Cleaner or git filter-repo to rewrite history. After cleaning, force-push and have all collaborators re-clone. The old commits may still exist in forks or cached copies.

Related Claude Code Issues

Can't fix it yourself?
Real developers can help.

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help