Projects Blog Tools Music Contact
← All Posts
Tech September 8, 2026

Claude Code and GitHub: Nine Agent Prompts We Lost to One .gitignore Line

By: Evgeny Padezhnov

Illustration for: Claude Code and GitHub: Nine Agent Prompts We Lost to One .gitignore Line

Claude Code and GitHub: Nine Agent Prompts We Lost to One .gitignore Line

A case study from a fleet of 52 repositories. Every number is from our own project registry and git history.

We run Claude Code agents across a registry of 52 projects — 29 active, 35 under git, 33 with a GitHub remote. Five active projects have no repository at all, which is its own quiet problem: their code exists only on one box.

This is not a guide to connecting Claude Code to GitHub. It is what we learned about what has to be in the repository when the thing using the repository is an autonomous agent — starting with the day nine of our agent definitions turned out not to be in git, and nobody noticed for months.

The incident

Claude Code reads custom agent definitions from .claude/agents/*.md. Each file is the system prompt for one role: a critic, an investigator, a planner.

Line 12 of our .gitignore was this:

.claude/

Ignoring the CLI's cache directory looks obviously right. It also ignores the agent definitions living inside it. Six prompts were in the index anyway, because at some point someone ran git add -f on them. The other nine had never been committed at all.

Then the box was rebuilt from backup. Git restored the six. The backup contained the same six. The remaining nine — critic, investigator, architect, planner, strategist, risk-analyst, researcher, step-verifier, summary-extractor — were gone as content, unrecoverable from anything we own.

The agents did not fail. That is the part worth sitting with.

Why it stayed invisible for months

Two independent guards were in place, and both were dead.

The code path did not check. Our launcher passed --agent <name> to the CLI without verifying that a file for that name existed. A fallback existed — a table of short built-in system prompts — but its own comment says it exists "in case --agent does not work", and it only ever applied on the API models, not on the CLI branch. So a missing definition produced no error, no warning, no log line. The role kept running, on whatever default the CLI gives an unknown agent name.

The test caught it and nobody read it. A unit test asserted the prompts load from the bot directory. It was failing. It was also one of twelve failures across five files, and a suite that is red everywhere is a suite nobody reads. The signal was there, correctly, and buried in noise we had learned to ignore.

That is the rule I would carry to any project: a red test suite means the guard is switched off, however routine the twelve failures look one by one. Work through them one at a time, because a real finding sits somewhere in the list of stale ones.

The fix, and the honesty problem inside it

Three changes, one commit:

# Claude CLI cache — EXCEPT the custom agent files.
.claude/*
!.claude/agents/*.md

The launcher now checks whether the file exists before passing --agent, and falls back with a warning in the log when it does not. And the test was rewritten from asserting a count to asserting an invariant: every role has either a file or a fallback prompt. A count goes stale the day you add a role; an invariant does not.

There is a second lesson buried in this, and it is uncomfortable. The commit message that fixed the bug contained a wrong number — it said six of sixteen roles had files. Sixteen was not reproducible anywhere; the real figure was twelve roles naming a file, three of which actually had one. We only caught it weeks later, and the source of the wrong number was our own commit. Numbers written into a commit message become canon. Nobody re-derives them; they get copied into the next document, and into the one after that.

What actually needs to live in the repository

The general rule we now apply: if a file has to exist after the machine is rebuilt, it is in git — no exceptions, and git add -f on top of an ignore rule is not a system. It saves exactly the files someone happened to remember.

For a Claude Code fleet, that means these, all of which are easy to leave out:

The inverse also holds. Not everything the CLI writes into .claude/ belongs in a repository: session caches and transcripts are machine-local noise, and this is exactly why the blanket ignore looked correct in the first place. The narrow pattern — ignore the directory, un-ignore the files that are configuration — is the whole fix.

One deliberate exception we made

Seventeen of our repositories have their .env committed. That is a decision, not an accident: every repository is private, the committed value equals the live one, and it means a rebuild restores a working service instead of a service missing its credentials.

It is defensible only with a boundary drawn around it, and ours is: the class of key that cannot be rotated cheaply — object-storage credentials, the backup encryption password — lives in exactly one repository, and that one is audited separately. If you copy this pattern without that boundary, you have not copied the pattern.

What I would tell someone wiring Claude Code to GitHub

Where the numbers come from


FAQ

Does Claude Code need a GitHub repository to work? No. But anything the agent relies on — agent definitions, skills, hook settings, CLAUDE.md — disappears with the machine unless it is committed somewhere.

Should .claude/ be in .gitignore? Not as a whole directory. Ignore the cache, keep the configuration: .claude/* followed by !.claude/agents/*.md and the equivalent for skills and settings.

How do I know an agent is running with the prompt I think it has? Ask your launcher to verify the file exists before it passes the name, and log the fallback. Without that check, a missing prompt looks exactly like a working one.

Is committing .env ever acceptable? Only in private repositories, and only with an explicit boundary around keys that cannot be rotated cheaply. It is a trade, not a shortcut.

Information is accurate as of the publication date. Terms, prices, and regulations may change — verify with relevant professionals.

✦ Squeeze AI
  1. Строка `.claude/` в .gitignore выглядела как исключение кеша CLI, но заодно молча стирала кастомные агентные промпты, лежащие в той же папке — 9 из 15 никогда не попали в git и оказались невосстановимы после пересборки бокса.
  2. Отсутствие проверки на существование файла агента не приводило к ошибке — роль просто продолжала работать на дефолтном промпте CLI, без лога и без сбоя.
  3. Тест, который ловил проблему, был красным вместе с 11 другими — а красный набор тестов никто не читает; правило: красный сьют = страховка выключена, независимо от того, насколько рутинными кажутся остальные фейлы.
  4. Фикс — точечное исключение `.claude/agents/*.md` из игнора плюс проверка существования файла перед запуском агента с фолбэком.

Powered by B1KEY