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.

Mehdi Ben Haddou Mehdi Ben Haddou - Founder of Chessigma (1M+ users) & many small projects - ex Founding Engineer @Uplane (YC F25) - ex Software Engineer @Amazon and @Booking.com legrab legrab I'll fill this later Jaime Orts-Caroff Jaime Orts-Caroff I'm a Senior Android developer, open to work in various fields Jacek Rozanski Jacek Rozanski Senior PHP/Symfony developer and DevOps engineer with 20+ years of professional experience, running opcode.pl (web development agency, est. 2004). Day job: I'm the sole backend developer at merketing company where I own and maintain 11 PHP/Symfony microservices on AWS (ECS Fargate, RDS, S3, CloudFront), handle the full CI/CD pipeline (Bitbucket Pipelines, Docker), and manage monitoring with Sentry and CloudWatch. These services handle high request volumes in production every month. What I bring to AI-built apps: - I audit and fix security issues (OWASP methodology), performance bottlenecks, and architectural problems in codebases generated by Cursor, Claude Code, Lovable, Bolt, and v0 - I refactor AI-generated prototypes into production-grade applications with proper error handling, testing, and clean architecture (SOLID, DDD, hexagonal architecture) - I set up the infrastructure AI tools don't touch: AWS hosting, CI/CD pipelines, automated deployments, database optimization, monitoring, and alerting - I integrate external services: payment providers, email systems, partner APIs, SSO/auth Tech stack: PHP 8.x, Symfony, React, Next.js, PostgreSQL, MySQL, Docker, AWS (ECS, RDS, S3, SQS/SNS, CloudFront), Terraform, Supabase. I also use AI tools daily (Claude Code, Cursor) in my own workflow, so I understand both the strengths and the gaps in AI-generated code. Based in Poland (CET timezone). Available for async work and calls during EU/US business hours. zipking zipking I am a technologist and product builder dedicated to creating high-impact solutions at the intersection of AI and specialized markets. Currently, I am focused on PropScan (EstateGuard), an AI-driven SaaS platform tailored for the Japanese real estate industry, and exploring the potential of Archify. As an INFJ-T, I approach development with a "systems-thinking" mindset—balancing technical precision with a deep understanding of user needs. I particularly enjoy the challenge of architecting Vertical AI SaaS and optimizing Small Language Models (SLMs) to solve specific, real-world business problems. Whether I'm in a CTO-level leadership role or hands-on with the code, I thrive on building tools that turn complex data into actionable value. David Olverson David Olverson Solo dev shipping production apps with AI-assisted development. I specialize in rescuing broken Lovable/Bolt/Cursor builds and taking them to production. 10+ apps shipped including SaaS CRMs, gaming platforms, real estate tools, and Discord bots. Stack: Next.js 16, TypeScript, Tailwind CSS, FastAPI, PostgreSQL, Prisma. I use Claude Code with 50+ custom skills for rapid delivery. Average turnaround: 2-4 weeks from broken prototype to production. Pratik Pratik SWE with 15+ years of experience building and maintaining web apps and extensive BE infrastructure Rudra Bhikadiya Rudra Bhikadiya I build and fix web apps across Next.js, Node.js, and DBs. Comfortable jumping into messy code, broken APIs, and mysterious bugs. If your project works in theory but not in reality, I help close that gap. prajwalfullstack prajwalfullstack Hi Im a full stack developer, a vibe coded MVP to Market ready product, I'm here to help Jared Hasson Jared Hasson Full time lead founding dev at a cyber security saas startup, with 10 yoe and a bachelor's in CS. Building & debugging software products is what I've spent my time on for forever

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