Fix Claude Code Password Exposure in GitHub Repositories

GeneralFix Claude Code Password Exposure in GitHub Repositories

What Causes This Issue

Claude Code, Anthropic’s command-line coding agent, includes a Don’t Ask Again option that suppresses permission prompts for file operations. When enabled during sessions involving sensitive files — such as .env configurations, SSH keys, or API token stores — the tool may write those secrets into its own session logs or temporary output files. Developers who subsequently commit their project directories to public GitHub repositories inadvertently push those artifacts, exposing credentials to anyone cloning the repo.

Researchers identified 1,122 public GitHub files containing live secrets traced to this behavior. The leak occurs because Claude Code’s local history mechanism stores command context, including file reads and writes, in plaintext within the user’s home directory. If a developer runs git add . or similar broad staging commands, those hidden logs ride along into version control.

Users in the Apple Support Community report this affects macOS developers using Homebrew or direct binary installs of Claude Code. The issue compounds when gitignore rules omit the tool’s hidden directories, typically ~/.claude-code/ or project-level .claude/ folders.

Step-by-Step Fixes

  1. Rotate every exposed credential immediately. Treat each leaked token, key, or password as compromised. Generate new secrets in the issuing service (AWS, GitHub, Stripe, database consoles) and revoke the old ones. Do not wait to audit — rotate first.
  2. Remove sensitive files from Git history. Use git filter-repo or the older git filter-branch to purge the offending blobs from all commits. Example: git filter-repo --path ~/.claude-code --invert-paths. Force-push the rewritten history to GitHub with git push --force-with-lease.
  3. Add Claude Code directories to global gitignore. Create or edit ~/.gitignore_global and append:
    .claude-code/
    .claude/
    claude-code.log
    Then run git config --global core.excludesfile ~/.gitignore_global.
  4. Disable “Don’t Ask Again” for sensitive operations. In Claude Code’s interactive prompt, never select the persistent allow option when the tool requests access to .env, .ssh/, *.pem, or any file containing secrets. Re-enable per-request approvals in the tool’s settings file (~/.claude-code/config.json) by setting "persistentPermissions": false.
  5. Scan your repository for residual secrets. Run git secrets --scan-history or trufflehog git file://. --since-commit=HEAD~100 to confirm no credentials remain in reachable history.
  6. Enable GitHub secret scanning and push protection. In each affected repository’s Settings > Security > Secret scanning, turn on both Push protection and Validity checks. This blocks future commits containing recognized token patterns.

Additional Solutions

Adopt a pre-commit hook that runs a secret detector on every staged change. Tools like detect-secrets or ggshield integrate with pre-commit frameworks and catch leaks before they leave your machine. Configure the hook to scan for high-entropy strings, AWS keys, GitHub PATs, and database URLs.

Use a dedicated credentials manager such as 1Password CLI, Bitwarden CLI, or macOS Keychain via security command instead of plaintext .env files. Reference secrets at runtime through environment variable injection (op run --, bw get password) so they never touch disk.

Containerize development environments with devcontainers or orbstack on macOS. Mount only the source code into the container; keep Claude Code’s logs and config inside the ephemeral container filesystem, which is excluded from git by default.

Audit GitHub Actions workflows that may have cached compromised artifacts. Check actions/cache entries and workflow logs for leaked values. Invalidate and regenerate any deployment keys or service account tokens used in CI pipelines.

Consider switching to Claude Code’s –no-persist flag (if available in your version) which disables local session logging entirely. Verify with claude-code --help or the official changelog.

When to Contact Apple Support

This issue originates in third-party software (Claude Code) and GitHub’s platform, not in macOS, Xcode, or Apple services. Contact Apple Support only if:

  • Keychain Access shows unexpected entries created by Claude Code that you cannot delete.
  • System Integrity Protection (SIP) alerts indicate the tool attempted to modify protected paths.
  • You suspect the binary was replaced by a malicious supply-chain attack distributed through a compromised Homebrew tap or DMG.

For credential rotation, repository rewriting, or GitHub secret scanning configuration, engage the respective service providers or your organization’s security team.

FAQ

Does this affect only public repositories?
No. Private repositories are equally vulnerable to insider access or future visibility changes. Remediate all affected remotes.

Can I recover rotated secrets from Git history after force-push?
GitHub retains orphaned blobs for up to 90 days in its garbage collection window. Use the GitHub REST API to purge cached views, or open a support ticket requesting expedited removal.

Is Claude Code the only AI coding tool with this risk?
Similar tools (Cursor, Windsurf, GitHub Copilot CLI) may write local logs containing file contents. Apply the same gitignore, pre-commit, and secret-scanning discipline universally.

How do I verify my global gitignore is active?
Run git check-ignore -v ~/.claude-code/session.log. It should return the matching rule from ~/.gitignore_global.

What if I cannot force-push because of branch protection rules?
Coordinate with repository admins to temporarily allow force-pushes on affected branches, or use GitHub’s UI to delete and recreate the branch from a clean local copy.

Neil S
Neil S
Neil is a highly qualified Technical Writer with an M.Sc(IT) degree and an impressive range of IT and Support certifications including MCSE, CCNA, ACA(Adobe Certified Associates), and PG Dip (IT). With over 10 years of hands-on experience as an IT support engineer across Windows, Mac, iOS, and Linux Server platforms, Neil possesses the expertise to create comprehensive and user-friendly documentation that simplifies complex technical concepts for a wide audience.
Watch & Subscribe Our YouTube Channel
YouTube Subscribe Button

Latest From Hawkdive

You May like these Related Articles

blog fix iphone battery drain after ios update 20261107

Fix iPhone Battery Drain After iOS Update: Complete Guide

Stop rapid battery drain after iOS update. Step-by-step fixes from Apple Support Community solutions and expert troubleshooting for iPhone.
blog claude code email leak fix macos 20261106

Claude Code Email Leak: Fix Privacy Issue on macOS

Stop Claude Code from sending your email to websites. Step-by-step fixes for the privacy leak reported by Apple Support Community users.
blog apple intelligence not working fix 20261105

Apple Intelligence Not Working? Fix Common Issues on iPhone & Mac

Apple Intelligence failing to activate or respond? Troubleshoot on-device AI features, Siri integration, and model download errors with step-by-step fixes.
blog fix cpp26 disapproved error xcode mac 20261104

Fix C++26 Disapproved Error in Xcode on Mac

Resolve the C++26 disapproved error in Xcode with step-by-step fixes for compiler flags, project settings, and toolchain updates on macOS.
blog fix slow large git repositories macos performance 20261103

Fix Slow Large Git Repositories on macOS: Performance Guide

Speed up large Git repos on macOS with proven fixes: configure fsmonitor, tune pack files, enable sparse checkout, and optimize Xcode integration.
blog smart tv privacy apple ecosystem guide 20261102

Smart TV Privacy Risks: Protect Your Apple Ecosystem Data

Stop smart TV tracking on your Apple devices. Learn which TVs respect privacy, how to disable ACR, and secure AirPlay and HomeKit connections.
blog fix chatgpt account takeover iphone security guide 20261101

Fix ChatGPT Account Takeover on iPhone: Security Guide

Secure your ChatGPT account on iPhone after reported takeover risks. Step-by-step fixes for unauthorized access, password reset loops, and Sign in with Apple issues.
blog wii remote mac bluetooth pairing fix 20261031

Nintendo Wii Remote Not Connecting to Mac: Bluetooth Pairing Fixes

Fix Wii Remote Bluetooth pairing failures on Mac. Step-by-step guide for macOS Sequoia, Sonoma, and older versions. Covers sync issues, Dolphin emulator, and Apple Silicon.
blog herdr native app ios fixes login sync crashes 20261030

Herdr Native App Not Working on iOS: Fixes for Login, Sync & Crashes

Herdr iOS app crashing, failing to login, or not syncing? Step-by-step fixes for the new native Mastodon client from Apple Support Community reports.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.