anthropics / anthropics/claude-code-action

Add capability to keep generated files out of the context window

Open
#431 1 comment 2 reactions 0 assignees View on GitHub
enhancement p3
Dominant language
TypeScript
Stars
8.9k
Forks
2.1k
Avg merge
3d 9h
Merged PRs (30d)
10

Description

# Problem

The AI currently receives all changed files in its context, including generated files marked with linguist-generated=true in .gitattributes. This leads to:

- Unnecessary token consumption from generated files (e.g., **/go/**/*.generated.go)
- Reduced context space for human-authored code
- AI potentially analyzing/reviewing generated code that shouldn't be modified

# Current Behavior

The formatChangedFilesWithSHA function in src/github/data/formatter.ts processes all files without filtering:

```
export function formatChangedFilesWithSHA(
changedFiles: GitHubFileWithSHA[],
): string {
return changedFiles
.map(
(file) =>
`- ${file.path} (${file.changeType}) +${file.additions}/-${file.deletions} SHA: ${file.sha}`,
)
.join("\n");
}
```

# Proposed Solution

Add filtering to exclude files marked as generated in .gitattributes before formatting. This could be implemented by:

1. Option A: Parse .gitattributes and filter files with linguist-generated=true
2. Option B: Use GitHub's Linguist API data if available
3. Option C: Add a configuration option to specify file patterns to exclude

Example .gitattributes patterns that should be filtered:

```
*.generated.go linguist-generated=true
**/dist/** linguist-generated=true
**/build/** linguist-generated=true
*.min.js linguist-generated=true
```

Expected Outcome

- Reduced token usage in AI prompts
- AI focuses on human-authored code for reviews and analysis
- More efficient use of context window
- Optional: Configuration to override this behavior when generated file analysis is needed

Implementation Areas

- src/github/data/formatter.ts - Add filtering logic
- src/github/data/fetcher.ts - Filter earlier in the pipeline
- Consider adding user configuration option for this feature

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.