[FEATURE] Proactive warning when file attachments exceed remaining context window
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
I attached a file to VS Code (running Claude Code) that was approximately 183k tokens. The file attached with no problems and there was no visual indication that the file size was an issue.
However, as soon as I typed a message and hit enter, I received a "Prompt is too long" error message. This indicated the context window (200k) was overloaded. Consequently, new messages will not go through, causing the session to essentially die. This workflow allows users to unknowingly "brick" their session because there is no feedback until it is too late.
Proposed Solution
I propose adding a check during the file attachment process that calculates the estimated token count of the file against the remaining context window.
If (Current Context + New File Tokens) > Context Limit:
- Display a warning to the user immediately upon attachment (e.g., "File is ~183k tokens and exceeds remaining context").
- Prevent the prompt from being sent until the context is reduced or the file is removed.
This would prevent users from accidentally sending prompts that represent immediate failures.
Alternative Solutions
Currently, the only alternative is for the user to manually verify file sizes/token counts before attaching them, or to restart the session entirely after the error occurs.
Priority
High - Significant impact on productivity
Feature Category
CLI commands and flags
Use Case Example
- User opens a Claude Code session in VS Code.
- User drags and drops a large file (e.g., a large source code file or log) that is 183k tokens.
- Current Behavior: The file attaches silently. The user types "Analyze this" and hits Enter. The API rejects the request ("Prompt is too long"), and the session enters an error state where no further messages can be sent.
- Desired Behavior: As soon as the file is attached, the UI warns: "This file is too large for the current session context." The user sees this, deletes the attachment, and splits the file or clears context before proceeding, saving the session.
Additional Context
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗