anthropics / anthropics/claude-code-action

"Prompt is too long": review comment diffHunk (#1584) is added to the prompt with no size limit

Aperta
#1,819 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
bug claude-code-assisted p2 provider:1p
Lingua principale
TypeScript
Stelle
8.9k
Fork
2.1k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

**Describe the bug**

Since #1584 (merged 2026-08-14), `formatReviewComments` appends each inline review comment's `diffHunk` to the tag-mode prompt with no size limit. For a comment on a newly added file, GitHub's `diffHunk` is the whole hunk from the file's first line down to the commented line, so a PR with many inline comments on a long new file embeds that file dozens of times. On one of our PRs this made the prompt far larger than the context window, and every `@claude` request on that PR ended with `Prompt is too long` before any API call.

What the prompt contained on that PR (reconstructed from the REST API, because the `FINAL PROMPT` printed in the log stops partway through `` at about 70 KB):

| Part | Size |
|---|---|
| `diffHunk` of 70 inline review comments | ~3.0 million characters (largest single hunk: 825 lines) |
| PR body, issue comments, review bodies, inline comment bodies | ~0.11 million characters |

48 of the 70 comments are on a file that is no longer in the PR's diff (it was moved in a later commit), but their hunks are still included.

From the job log (`show_full_output: true`):

- `"result": "Prompt is too long"`, `"duration_api_ms": 0`, `"total_cost_usd": 0`
- The request text makes no difference: `@claude /review` and a plain-language request both failed this way.
- With `@claude /review`, the result had `"is_error": false` and `"num_turns": 0`, so the step passed and the tracking comment only said "Claude finished @'s task in 1s" followed by "I'll analyze this and get back to you." Nothing told the user it had failed. (With the plain-language request, `"is_error": true` and the job failed.)

Relevant code, `src/github/data/formatter.ts` on main (0a8d3c9):

```ts
if (comment.diffHunk) {
const diffHunk = sanitizeContent(comment.diffHunk);
formatted += `\n Diff context:\n\`\`\`diff\n${diffHunk}\n\`\`\``;
}
```

together with `reviews(first: 100) { comments(first: 100) { diffHunk } }` in the query. Nothing limits the length of a hunk or the total size.

**To Reproduce**

1. Use a tag-mode workflow (`issue_comment` + `@claude`) with `anthropics/claude-code-action@v1`.
2. Open a PR that adds a long file (ours were Markdown documents of roughly 700–800 lines).
3. Leave many inline review comments on that file, especially far down in it. In our case an automated review bot left about 60 over several pushes.
4. Comment `@claude` with any request on the PR.
5. The job ends with `Prompt is too long` and no API call is made.

To check whether a PR is affected, add up the hunk sizes:

```sh
gh api "repos/OWNER/REPO/pulls/NUMBER/comments?per_page=100" --paginate \
--jq '.[].diff_hunk | length' | awk '{s+=$1} END {print s}'
```

**Expected behavior**

Review comments keep the context #1584 was aiming for, while the prompt stays within the context window. For example:

1. Cut each hunk down to its `@@` header plus the last few lines before the commented line. GitHub's conversation view also shows only a few lines of context.
2. Leave out hunks for outdated comments, or include each file's hunk only once.
3. Give the review-comments section a total size budget and drop the oldest content first.

Separately, when Claude Code returns `Prompt is too long`, the step should fail and the tracking comment should say why. Right now, with a slash-command request, it is reported as a success.

**Workflow yml file**

```yaml
on:
issue_comment:
types: [created]
# (plus pull_request_review_comment, issues, pull_request_review)
jobs:
claude:
if: contains(github.event.comment.body, '@claude')
runs-on: self-hosted
permissions:
contents: write
pull-requests: write
issues: write
id-token: write
actions: read
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 1
- uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
show_full_output: true
additional_permissions: |
actions: read
```

**API Provider**

[x] Anthropic First-Party API (default)
[ ] AWS Bedrock
[ ] GCP Vertex

**Additional context**

- `anthropics/claude-code-action@v1`, which currently equals main (0a8d3c9); Claude Code 2.1.268; model `claude-sonnet-5`; self-hosted Linux ARM64 runner.
- Workarounds we found: `exclude_comments_by_actor` for the bot that posts the inline comments (it filters both the reviews and their inline comments), or running reviews in agent mode via `prompt:`, which does not embed the comment history. Another workflow of ours that uses `prompt:` did not hit this error on the same PR.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.