Git setup that keeps your AI agent from reading your whole codebase
A developer shares a Git setup to optimize AI agent interaction with large codebases, aiming to reduce costs. Key strategies include treating HEAD as a cache, prioritizing .changed_markers, focusing on changed hunks and functions, and anchoring on function/class names instead of line numbers. For signature changes, git grep -n is used to find callers. After a successful commit, .changed_markers are cleared. This method is applicable across various programming languages.
Unlike general advice, this post offers specific Git commands and file-level strategies like using .changed_markers and git grep -n to manage AI agent access to code.
时间与来源
时间显示为 UTC
显示时区:UTC
本地时区尚不可用,暂时显示 UTC。
发布当时偏移:UTC+02026年9月13日 05:30 UTC
收录当时偏移:UTC+02026年9月13日 14:01 UTC
- 发布
- 2026年9月13日 05:30
- 收录
- 2026年9月13日 14:01
- 来源类型
- 开发者社区
- 档位
- 社区
- 信源状态
- 正常
档位是按信源手工设定的编辑判断,不是逐条打分。
Started my first large coding project recently and my money evaporated. Quickly. This is what I did to save money.
{ echo "# AUTO-GENERATED — do not edit" git add -N . 2>/dev/null git diff -U3 -p HEAD } > .changed_markers
This grabs any changes since the last commit and dumps it into .changed_markers.
Next, add to or create .gitattributes and add this:
*.py diff=python
This just makes git show you the function that changed.
Lastly add these rules to: System prompt, rules file or just paste them into chat once.
1. Treat HEAD as a cache hit, don't re-read files that haven't changed. 2. Read .changed_markers first, before anything else. 3. Only look at the hunks and functions in that file. 4. Anchor on function/class names, never line numbers, they go stale fast. 5. If a function's signature changes, use git grep -n "that_name" to find callers instead of opening the whole file. 6. After a successful commit, erase the contents of .changed_markers
This isn't just for Python. If you're not sure how to run it with your language, just ask your coding agent. It will walk you through it.