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

[Feature Request] Add repository-level setting to disable automatic Git context loading

Open ariashira opened this issue 1 year ago • 2 comments

Problem

Claude Code automatically loads Git information (git status, commit history from .git/logs/HEAD, etc.) at the start of every session. While this is helpful for active development projects, it can be unnecessary for certain types of repositories.

Observed Token Consumption

In a repository with 73 commit entries in .git/logs/HEAD:

  • Commit history alone: ~4,000 tokens (~55 tokens per entry)
  • Additional Git metadata: ~14,000 tokens
  • Total Git context: ~18,000 tokens per session

For personal repositories like note-taking systems where Git operations are infrequent, this context is rarely used but consumes tokens in every session.

Scaling Impact

The token cost scales with repository history:

  • Small repos (10-20 commits): ~3,000-5,000 tokens
  • Medium repos (50-100 commits): ~10,000-20,000 tokens
  • Large repos (200+ commits): ~25,000+ tokens

Proposed Solution

Add a repository-level setting in .claude/settings.local.json to control Git context loading:

{
  "git": {
    "autoLoadContext": false
  }
}

Or more granular control:

{
  "git": {
    "includeStatus": true,      // git status (minimal cost)
    "includeHistory": false,     // .git/logs/HEAD
    "maxHistoryEntries": 5       // limit history entries if included
  }
}

Benefits

  1. Token efficiency: Significant savings for repos where Git context is rarely needed
  2. Faster session startup: Less context to process
  3. Repository-specific configuration: Enable/disable per repository based on workflow
  4. Backward compatible: Default behavior remains unchanged (all context loaded)

Use Cases

Repos that benefit from disabled Git context:

  • Personal note-taking/memo systems
  • Documentation-only repositories
  • Single-developer projects with minimal Git operations
  • Knowledge bases where commits are infrequent

Repos that should keep Git context:

  • Team development projects
  • Active feature development with frequent commits/PRs
  • Projects requiring Git workflow awareness

Current Workaround

We implemented a workaround that reduces .git/logs/HEAD to 2 entries after each commit:

tail -2 .git/logs/HEAD > /tmp/HEAD.new && mv /tmp/HEAD.new .git/logs/HEAD

Result: Saves ~4,000 tokens (commit history portion only)
Limitation: The remaining ~14,000 tokens of Git metadata are still loaded

This demonstrates the need for a proper configuration option.

Related Issues

  • #1104 (addressed indexing performance, but not context loading control)

Implementation Notes

  • This is a repository-level setting (.claude/settings.local.json), not global
  • Only affects automatic context loading at session start
  • Git commands (git status, git commit, etc.) would still work normally when explicitly invoked
  • Suggestion: Load Git context on-demand when Git-related keywords are detected in user input

Thank you for considering this feature request!

ariashira avatar Oct 22 '25 01:10 ariashira

Found 2 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/8245
  2. https://github.com/anthropics/claude-code/issues/9096

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 Oct 22 '25 01:10 github-actions[bot]

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

github-actions[bot] avatar Oct 30 '25 14:10 github-actions[bot]