[BUG] System prompt wastes >10k tokens on large git repos that cannot be disabled

Open 💬 19 comments Opened Sep 26, 2025 by verbraucher

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Problem

Claude Code automatically loads git repository information into the system prompt.
In large repos/monorepos, this consumes >20k tokens that cannot be disabled.

Evidence

Using /context command shows:

  • With .git: System prompt 23.7k tokens
  • Without .git: System prompt 3.1k tokens
  • Impact: ~20k tokens wasted

Current Behavior

Setting permissions.deny has no effect:

json

{
  "permissions": {
    "deny": ["Read(./.git/**)", "Read(./.git)", "Write(./.git/**)", "Write(./.git)"]
  }
}

The git context is loaded during initialization, before permission rules are evaluated.

Why This Matters

  • Performance: Slower startup, unnecessary API calls
  • Context: 10%+ of available context consumed before any work
  • Workaround: Must rename .git folder, breaking git workflow

What Should Happen?

Claude Code should respect permissions.deny rules BEFORE loading git context, or provide a configuration option to disable git loading entirely.

Expected behavior:

  • When .git is in permissions.deny, no git data should be loaded
  • System prompt should be ~3k tokens, not 23k+ tokens
  • OR a --no-git or sth. else flag should be available to skip git detection

Error Messages/Logs

No errors - silent token consumption in system prompt.
See /context output screenshots showing 20k+ token difference.

Steps to Reproduce

  1. Clone any large repository with 10000+ commits
  2. Add to .claude/settings.json:
   {"permissions": {"deny": ["Read(./.git/**)", "Read(./.git)"]}}
  1. Start Claude Code: claude
  2. Run /context command
  3. Note "System prompt" size (will be >20k tokens)
  4. Exit Claude, rename: mv .git .git.bak
  5. Start Claude Code again: claude
  6. Run /context command
  7. Compare system prompt (now ~3k tokens)
  8. Difference = wasted git context tokens

Claude Model

Sonnet (default)

Claude Code Version

1.0.127

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

WSL (Windows Subsystem for Linux)

Additional Information

Related Issues

  • #1104 - Closed incorrectly, deny patterns don't prevent git loading

View original on GitHub ↗

19 Comments

github-actions[bot] · 9 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/1104
  2. https://github.com/anthropics/claude-code/issues/7781
  3. https://github.com/anthropics/claude-code/issues/1857

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

sebastiancarlos · 9 months ago

+1

KJ7LNW · 8 months ago

+1

LadislavSopko · 7 months ago

The same problem here: It add me more then 10k tokens in prompt.

perhmm · 7 months ago

While I don't have this specific issue. I wish there was an option to disable this behavior.

When I ask Claude Code to review recent code changes based on a diff I find it having the commit messages in its context gives it a bias to confirm what the git messages is claiming the changes are doing rather then just looking at the code.

PaulRBerg · 7 months ago

I just wasted 10% of my weekly context usage because of this behavior (loading gitStatus in context, by default, without any ability to turn it off).

Claude has accidentally produced a large git commit message (2000 lines long), which was being loaded in every single chat.

Please make it possible to disable this behavior 🙏 Loading the git status is not necessary for most tasks!

anonysquirrel · 7 months ago

Workaround:

cp ~/npm-global/bin/claude ~/npm-global/bin/claude.bak
vim ~/npm-global/bin/claude
:%s/CQ("git"/CQ("true git"/g
:wq
sherzhen · 6 months ago

+1

github-actions[bot] · 5 months ago

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

PaulRBerg · 5 months ago

please keep open

maddog986 · 4 months ago

These commit messages are injected after CLAUDE.md and can not be turned off. I have found that the commit messages can override CLAUDE.md instructions.

LadislavSopko · 4 months ago

commit message can override CLAUDE.md, wait!!! commit message can influent CC behaviour in some way? What?

PaulRBerg · 4 months ago

Yeah @maddog986 can you explain what do you mean by commits overriding CLAUDE.md instructions?

aslo WDYM by commit messages being injected after CLAUDE.md, can you show your logs?

KJ7LNW · 4 months ago

It totally makes sense. They load the recent commit messages into the system instructions because they think it's useful (but it rarely is)....

But of course if any of your commit messages have verbiage that overrides something in your instructions file, then they will conflict and one of them will win or perhaps just cause confusion.

LadislavSopko · 4 months ago

hm.. not nice in any way, id like to have choice to ask to read commit messages, ....

maddog986 · 4 months ago
Yeah @maddog986 can you explain what do you mean by commits overriding CLAUDE.md instructions? aslo WDYM by commit messages being injected after CLAUDE.md, can you show your logs?

Git commit messages are injected after CLAUDE.md. Claude has a natural tendency to ignore instructions when its "easier to Grep" than follow the instructions. Having the commit file names and descriptions is a larger signal than the instructions. According to Claude itself, its a path of less resistance (than following the rules/instructions), so it does it. If its straight up ignoring instructions, injected 3 times before the git commits, I would say that is a potential backdoor.

I made a simple test instance, with a test repo, with malicious git commit messages. Luckly Claude ignored those instructions, as it was "obvious" to Claude (with like 1% context), but if Claude was near full context, its attention to details tends to be more "fast than safe", so I'm sure someone could figure out a cleaver prompt injection via malicious git comments.

Regardless, the commit messages do influence the behavior of Claude.

edit: To further add, since this cannot be turned off, I figured ill exploit it in my own way. I now have Claude craft commit messages with breadcrumbs to call MCP commands (custom mcp server that stores the who/what/why/when/where/session notes organically, can recall it anytime). Now on a new session (or after a compact), Claude sees the recent commit history with breadcrumbs, and we can pick up where we left off, or I can ask "what did we do yesterday" and get full details.

benvanik · 4 months ago

this feature is killing me - I run agents in worktrees that always have changes, and it actively makes claude dumber :(

kwaegel · 4 months ago

This also causes massive performance problems in some cases. When trying to run a Linux (WSL2) version of Claude Code in a Windows shared filesystem over the 9P bridge, I've seen the implicit git status call can add a massive ~10 minutes delay building the prompt.

I know WSL2 shared FS usage isn't ideal, but it's mostly usable as long as you avoid Git operations.

LadislavSopko · 4 months ago

this feature should be configurable as rest of the system, it has no sense be obligated to have it. It can be handy for some one, and killer for others, thats all.