記事一覧へ
# キャリアを救う.gitignore(完全ファイル同梱)
darkzodchi
@zodchiii
The .gitignore That Saves Your Career (Full File Included)
7
21
154
74K
Anthropicは、誰かがignoreファイルに1行を加え忘れただけで、自社の512,000行のソースコードを漏えいさせました。彼らに起きるなら、あなたにも起きます。
数時間以内にコードはGitHubにミラーされ、2時間で5万スターを獲得しました。おそらくGitHub史上もっとも急成長したリポジトリです。
あなたの.gitignoreは、初日にコピーしてからずっと触っていないテンプレートのままでしょう。
本当に入れるべき内容は以下の通りです 👇
本題に入る前に、Telegramチャンネルでは毎日AIとvibe codingに関するメモを共有しています: https://t.me/zodchixquant🧠
なぜデフォルトの.gitignoreテンプレートでは不十分なのか
GitHubのデフォルトテンプレートが扱うのは基本だけです: node_modules、pycache、.DS_Store。これらはAIコーディングツールが存在する前に書かれたものです。
2026年、あなたのプロジェクトには2年前には存在しなかったファイルがあります:
.claude/ → Claude Codeの設定。シェルコマンド内にAPIトークンが入っている
.cursor/ → Cursor AIのルールと設定
.aider* → Aiderのチャット履歴と設定
.env → これは誰でも知っている、しかし...
.env.local → ...これを忘れる人が多い
.env.development → ...これも
.env.production → ...これは特に
.claude/ディレクトリは最新の脅威です。Claude Codeはsettings.jsonをここに保存します。もしAPIトークンが入ったbashコマンドを事前承認している場合、それらのトークンは、デフォルトでnpm、PyPI、RubyGemsにパッケージングされてしまうファイルの中に置かれていることになります。
Lakeraのセキュリティ研究者は2026年4月にこれを確認しました: Python、Ruby、JavaScriptのビルドツールはすべて、プロジェクトディレクトリのファイルをパッケージに含めます。
.claude/がignoreファイルに入っていなければ、トークンが埋め込まれた承認済みシェルコマンドが公開レジストリに出荷されてしまいます。
実際に漏洩しているファイル群
過去12か月の実際のインシデントに基づきます:
Tier 1 - 即座に金銭被害が出るシークレット:
.env、.env.local、.env.production、.env.development
.claude/settings.json(トークン入りの事前承認コマンドを含む)
*.pem、*.key(SSL証明書と秘密鍵)
credentials.json、service-account.json(クラウドプロバイダーキー)
.npmrc、.pypirc(パッケージレジストリのトークン)
Tier 2 - アカウント乗っ取りを可能にするシークレット:
.aws/credentials
.ssh/id_rsa、.ssh/config
.docker/config.json(レジストリ認証)
.kube/config(クラスターアクセス)
.terraform/terraform.tfstate(パスワードを平文で含む)
Tier 3 - 公開すべきでない情報:
.vscode/settings.json(ときどきトークンを含む)
.idea/(データベースパスワード入りのJetBrains設定)
*.sqlite、*.db(ユーザーデータ入りローカルDB)
coverage/(内部ファイルパスを露出させる可能性)
.claude/memory/(Claudeのプロジェクトに関するメモ)
GitGuardianの2026年レポート: 昨年GitHub上で2,900万件のシークレットが漏洩。2022年に漏洩した認証情報の64%は、2026年でもまだ有効でした。誰もrevokeしていなかったということです。
ほぼ誰も追加していない.gitignoreルール
ほぼすべてのプロジェクトで欠けている行は次の通りです:
# AIツールの設定(2025-2026で新登場)
.claude/
.cursor/
.aider*
.continue/
.cody/
.codex/
AIコーディングツール以前は不要でした。今やどのプロジェクトにも、潜在的にシークレットを含むAI設定ディレクトリが少なくとも一つあります。ほとんどの開発者はツールを追加し、数週間使い、.gitignoreを更新することを思いつかないままです。
# 環境ファイル(全バリアント)
.env
.env.*
!.env.example
!.env.exampleの例外は重要です。新メンバーがどの変数を設定すべきか分かるよう、テンプレート(ダミー値入り)はコミットしたいですが、実際の値はコミットしたくありません。
# クラウド認証情報
.aws/
.azure/
.gcloud/
.terraform/terraform.tfstate
.terraform/terraform.tfstate.backup
Terraformのstateファイルは特に注意が必要です。データベースパスワードやAPIキーを含むインフラ状態を平文で保存します。本番DBの認証情報が公開GitHubリポジトリの.tfstateファイルに置かれているのを何度も見ました。
罠: .gitignoreは既にコミット済みのファイルには効かない
これが命取りになるミスです。.envを既にコミットした「あと」で.gitignoreに追加する。ファイルはまだgit履歴に残っています。リポジトリをcloneした人は誰でも、git log --all -- .envを実行してすべてのバージョンを見られます。
.gitignoreへの追加は、将来のコミットを防ぐだけです。実際にファイルを履歴から削除するには:
bash
# 追跡から外しつつローカルファイルは保持
git rm --cached .env
git commit -m "chore: remove .env from tracking"
# git履歴全体から削除する場合(核オプション)
# 先にBFG Repo-Cleanerをインストール
bfg --delete-files .env
git reflog expire --expire=now --all
git gc --prune=now --aggressive
git push --force
履歴をクリーンにした後は、そのファイルにかつてあった全認証情報をローテートしてください。Stripeキーが3か月間git履歴にあったなら、すでにスクレイプされたと考えるべきです。GitGuardianは、bot がpush後数分以内に公開リポジトリをスキャンしていることを発見しました。
Anthropicの教訓: .npmignoreも重要
.gitignoreはgitリポジトリを守ります。しかしパッケージを公開するとき、npm/PyPI/RubyGemsは異なるignoreファイルを使います:
npm → .npmignore(または package.json の "files" フィールド)
PyPI → MANIFEST.in または pyproject.toml の excludes
Ruby → .gemspecのfilesリスト
Anthropicの漏洩は、source mapsに対する.npmignoreエントリがなかったために起きました。彼らの.gitignoreはおそらく問題なかったでしょう。npmパッケージがすべてを含めてしまったのです。
パッケージを公開するなら、必ず公開前にdry runを実行してください:
# npm - パッケージ化される内容を確認
npm pack --dry-run
# Python - sdistを確認
python -m build --sdist
tar -tzf dist/*.tar.gz | grep -E '\.env|\.claude|secret'
完全な.gitignore(コピペ即用)
Node.js / TypeScript
# Dependencies
node_modules/
.pnp.*
# Build
dist/
build/
.next/
out/
# Environment
.env
.env.*
!.env.example
# AI tools
.claude/
.cursor/
.aider*
.continue/
.cody/
.codex/
# Secrets & credentials
*.pem
*.key
*.p12
*.pfx
credentials.json
service-account*.json
.npmrc
.aws/
.ssh/
.docker/config.json
# IDE
.vscode/settings.json
.idea/
# OS
.DS_Store
Thumbs.db
# Logs & coverage
*.log
coverage/
.nyc_output/
# Terraform
.terraform/
*.tfstate
*.tfstate.backup
Python
Python
# Virtual environments
venv/
.venv/
env/
# Build
__pycache__/
*.py[cod]
*.egg-info/
dist/
build/
# Environment
.env
.env.*
!.env.example
# AI tools
.claude/
.cursor/
.aider*
.continue/
.cody/
# Secrets & credentials
*.pem
*.key
credentials.json
service-account*.json
.pypirc
.aws/
.ssh/
# IDE
.vscode/settings.json
.idea/
# OS
.DS_Store
# Jupyter
.ipynb_checkpoints/
# Logs & coverage
*.log
htmlcov/
.coverage
# Terraform
.terraform/
*.tfstate
*.tfstate.backup
GO
Go
# Binary
bin/
*.exe
# Environment
.env
.env.*
!.env.example
# AI tools
.claude/
.cursor/
.aider*
.continue/
# Secrets
*.pem
*.key
credentials.json
service-account*.json
.aws/
.ssh/
# IDE
.vscode/settings.json
.idea/
# OS
.DS_Store
# Vendor (optional)
# vendor/
# Coverage
coverage.out
*.prof
チェックリスト
次にpushする前に:
1. .claude/ は.gitignoreに入っているか?
2. すべての.envバリアントはカバーされているか(.env、.env.*、!.env.example)?
3. 過去にコミットしたシークレットがgit履歴にないか確認したか?
4. パッケージを公開する場合: .npmignore / MANIFEST.in はあるか?
5. npm pack --dry-run を実行して実際に出荷される内容を確認したか?
6. クラウド認証情報ディレクトリ(.aws/、.ssh/)は除外されているか?
7. .terraform/terraform.tfstate は除外されているか?
Anthropicは1行を忘れて512,000行のソースコードを漏洩しました。あなたの.gitignoreは、人生で最も安いセキュリティ投資です。今日アップデートしてください。
Telegramチャンネルでは、AI、金融、vibe codingに関するメモを毎日共有しています: https://t.me/zodchixquant
お読みいただきありがとうございます🙏🏼
自分の記事を公開したいですか?
プレミアムにアップグレード
6:19 PM · May 2, 2026
·
74.5K
Views
7
21
154
394

securityclaude-setupgitignoresecretsDevOps
キャリアを救う.gitignore(完全版同梱)
♥ 154↻ 14
原文を表示 / Show original
# The .gitignore That Saves Your Career (Full File Included)
darkzodchi
@zodchiii
The .gitignore That Saves Your Career (Full File Included)
7
21
154
74K
Anthropic leaked 512,000 lines of their own source code because someone forgot to add one line to an ignore file. If it happens to them, it's happening to you.
Within hours the code was mirrored on GitHub and got 50,000 stars in two hours, likely the fastest-growing repository in GitHub history.
Your .gitignore is probably a template you copied on day one and never touched.
Here's what actually needs to be in it 👇
Before we dive in, I share daily notes on AI & vibe coding in my Telegram channel: https://t.me/zodchixquant🧠
Why default .gitignore templates aren't enough
GitHub's default templates cover the basics: node_modules, pycache, .DS_Store. They were written before AI coding tools existed.
In 2026 your project has new files that didn't exist two years ago:
.claude/ → Claude Code settings with API tokens in shell commands
.cursor/ → Cursor AI rules and configs
.aider* → Aider chat history and configs
.env → everyone knows this one, but...
.env.local → ...most people forget this one
.env.development → ...and this one
.env.production → ...especially this one
The .claude/ directory is the newest threat. Claude Code stores your settings.json there, and if you've pre-approved bash commands with API tokens in them, those tokens are now sitting in a file that gets packaged into npm, PyPI, and RubyGems by default.
Lakera security researchers confirmed this in April 2026: build tools for Python, Ruby, and JavaScript all package files from your project directory.
If .claude/ isn't in your ignore file, your approved shell commands with embedded secrets ship to the public registry.
The files that actually leak
Based on real incidents from the past 12 months:
Tier 1 - secrets that cost money immediately:
.env, .env.local, .env.production, .env.development
.claude/settings.json (contains pre-approved commands with tokens)
*.pem, *.key (SSL certificates and private keys)
credentials.json, service-account.json (cloud provider keys)
.npmrc, .pypirc (package registry tokens)
Tier 2 - secrets that enable account takeover:
.aws/credentials
.ssh/id_rsa, .ssh/config
.docker/config.json (registry auth)
.kube/config (cluster access)
.terraform/terraform.tfstate (contains passwords in plaintext)
Tier 3 - information that shouldn't be public:
.vscode/settings.json (sometimes contains tokens)
.idea/ (JetBrains configs with database passwords)
*.sqlite, *.db (local databases with user data)
coverage/ (can reveal internal file paths)
.claude/memory/ (Claude's notes about your project)
GitGuardian's 2026 report: 29 million secrets leaked on GitHub last year. 64% of credentials leaked in 2022 were still valid in 2026. Nobody revoked them.
The .gitignore rules nobody adds
These are the lines missing from almost every project:
# AI tool configs (NEW in 2025-2026)
.claude/
.cursor/
.aider*
.continue/
.cody/
.codex/
Before AI coding tools, you didn't need these. Now every project has at least one AI config directory with potential secrets. Most developers add the tool, use it for weeks, and never think to update .gitignore.
# Environment files (all variants)
.env
.env.*
!.env.example
The !.env.example exception is important. You want to commit the template (with dummy values) so new team members know which variables to set. You don't want to commit the actual values.
# Cloud credentials
.aws/
.azure/
.gcloud/
.terraform/terraform.tfstate
.terraform/terraform.tfstate.backup
Terraform state files deserve special attention. They store your infrastructure state in plaintext, including database passwords and API keys. I've seen production database credentials sitting in public GitHub repos inside .tfstate files.
The trap: .gitignore doesn't fix files already committed
This is the mistake that kills people. You add .env to .gitignore after you've already committed it. The file is still in your git history. Anyone who clones your repo can run git log --all -- .env and see every version.
Adding to .gitignore only prevents future commits. To actually remove a file from history:
bash
# Remove from tracking but keep the local file
git rm --cached .env
git commit -m "chore: remove .env from tracking"
# To remove from entire git history (nuclear option)
# Install BFG Repo-Cleaner first
bfg --delete-files .env
git reflog expire --expire=now --all
git gc --prune=now --aggressive
git push --force
After cleaning history, rotate every credential that was ever in that file. If your Stripe key was in git history for 3 months, assume it's been scraped. GitGuardian found that bots scan public repos within minutes of a push.
The Anthropic lesson: .npmignore matters too
.gitignore protects your git repository. But when you publish a package, npm/PyPI/RubyGems use different ignore files:
npm → .npmignore (or "files" field in package.json)
PyPI → MANIFEST.in or pyproject.toml excludes
Ruby → .gemspec files list
Anthropic's leak happened because they had no .npmignore entry for source maps. Their .gitignore was probably fine. The npm package included everything.
If you publish packages, always run a dry run before publishing:
# npm - see what gets packaged
npm pack --dry-run
# Python - check your sdist
python -m build --sdist
tar -tzf dist/*.tar.gz | grep -E '\.env|\.claude|secret'
The full .gitignore (copy-paste ready)
Node.js / TypeScript
# Dependencies
node_modules/
.pnp.*
# Build
dist/
build/
.next/
out/
# Environment
.env
.env.*
!.env.example
# AI tools
.claude/
.cursor/
.aider*
.continue/
.cody/
.codex/
# Secrets & credentials
*.pem
*.key
*.p12
*.pfx
credentials.json
service-account*.json
.npmrc
.aws/
.ssh/
.docker/config.json
# IDE
.vscode/settings.json
.idea/
# OS
.DS_Store
Thumbs.db
# Logs & coverage
*.log
coverage/
.nyc_output/
# Terraform
.terraform/
*.tfstate
*.tfstate.backup
Python
Python
# Virtual environments
venv/
.venv/
env/
# Build
__pycache__/
*.py[cod]
*.egg-info/
dist/
build/
# Environment
.env
.env.*
!.env.example
# AI tools
.claude/
.cursor/
.aider*
.continue/
.cody/
# Secrets & credentials
*.pem
*.key
credentials.json
service-account*.json
.pypirc
.aws/
.ssh/
# IDE
.vscode/settings.json
.idea/
# OS
.DS_Store
# Jupyter
.ipynb_checkpoints/
# Logs & coverage
*.log
htmlcov/
.coverage
# Terraform
.terraform/
*.tfstate
*.tfstate.backup
GO
Go
# Binary
bin/
*.exe
# Environment
.env
.env.*
!.env.example
# AI tools
.claude/
.cursor/
.aider*
.continue/
# Secrets
*.pem
*.key
credentials.json
service-account*.json
.aws/
.ssh/
# IDE
.vscode/settings.json
.idea/
# OS
.DS_Store
# Vendor (optional)
# vendor/
# Coverage
coverage.out
*.prof
The checklist
Before your next push:
1. Is .claude/ in your .gitignore?
2. Are ALL .env variants covered (.env, .env.*, !.env.example)?
3. Have you checked git history for previously committed secrets?
4. If you publish packages: do you have .npmignore / MANIFEST.in?
5. Have you run npm pack --dry-run to see what actually ships?
6. Are cloud credential directories (.aws/, .ssh/) excluded?
7. Is .terraform/terraform.tfstate excluded?
Anthropic forgot one line and leaked 512,000 lines of source code. Your .gitignore is the cheapest security investment you'll ever make. Update it today.
I share daily notes on AI, finance, and vibe coding in my Telegram channel: https://t.me/zodchixquant
Thanks for reading🙏🏼
Want to publish your own Article?
Upgrade to Premium
6:19 PM · May 2, 2026
·
74.5K
Views
7
21
154
394