claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

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

Open verbraucher opened this issue 5 months ago • 8 comments

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

verbraucher avatar Sep 26 '25 20:09 verbraucher

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

github-actions[bot] avatar Sep 26 '25 20:09 github-actions[bot]

+1

sebastiancarlos avatar Oct 07 '25 18:10 sebastiancarlos

+1

KJ7LNW avatar Nov 07 '25 18:11 KJ7LNW

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

LadislavSopko avatar Nov 28 '25 11:11 LadislavSopko

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.

perhmm avatar Dec 12 '25 03:12 perhmm

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!

PaulRBerg avatar Dec 18 '25 13:12 PaulRBerg

Workaround:

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

anonysquirrel avatar Dec 18 '25 22:12 anonysquirrel