gemini-cli - ✅(Solved) Fix Sending this message (9 tokens) might exceed the context window limit (-31,601,307 tokens left). Please try reducing the size of your message or use the /compress command to compress the chat history. [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
google-gemini/gemini-cli#26188Fetched 2026-04-30 06:44:42
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Participants
Timeline (top)
cross-referenced ×1labeled ×1

Fix Action

Fixed

PR fix notes

PR #26201: fix(core): clamp remaining context tokens

Description (problem / solution / changelog)

Summary

  • Clamp remainingTokenCount at zero before emitting ContextWindowWillOverflow.
  • Prevent user-facing overflow warnings from showing impossible negative token counts when the current prompt already exceeds the model limit.
  • Add a regression test for the over-limit current prompt case.

Fixes #26188.

Tests

  • npm test --workspace @google/gemini-cli-core -- client.test.ts
  • npm run typecheck --workspace @google/gemini-cli-core
  • npx prettier --check packages/core/src/core/client.ts packages/core/src/core/client.test.ts

Changed files

  • packages/core/src/core/client.test.ts (modified, +35/-0)
  • packages/core/src/core/client.ts (modified, +4/-2)
RAW_BUFFERClick to expand / collapse

What happened?

Sending this message (9 tokens) might exceed the context window limit (-31,601,307 tokens left). Please try reducing the size of your message or use the /compress command to compress the chat history.

What did you expect to happen?

Sending this message (9 tokens) might exceed the context window limit (-31,601,307 tokens left). Please try reducing the size of your message or use the /compress command to compress the chat history.

Client information

  • CLI Version: 0.40.0
  • Git Commit: 3d5bdc052
  • Session ID: c5705f4d-a6b5-4db4-bb45-17b26b9f549c
  • Operating System: win32 v22.17.0
  • Sandbox Environment: no sandbox
  • Model Version: auto-gemini-3
  • Auth Type: oauth-personal
  • Memory Usage: 968.8 MB
  • Terminal Name: xterm.js(6.1.0-beta.197)
  • Terminal Background: #242424
  • Kitty Keyboard Protocol: Supported
  • IDE Client: VS Code

Login information

No response

Anything else we need to know?

No response

extent analysis

TL;DR

Reduce the size of the message or use the /compress command to avoid exceeding the context window limit.

Guidance

  • Verify the message size by checking the token count before sending to ensure it's within the allowed limit.
  • Use the /compress command to compress the chat history and reduce the message size.
  • Consider breaking down large messages into smaller, more manageable chunks to avoid hitting the context window limit.
  • Review the client information to ensure that the CLI version, model version, and other settings are up-to-date and compatible.

Notes

The provided information does not specify the exact cause of the issue, but the error message suggests that the message size is the primary concern. The guidance provided is based on the error message and may not be exhaustive.

Recommendation

Apply workaround: Reduce the message size or use the /compress command, as this is the most straightforward solution to avoid exceeding the context window limit.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

gemini-cli - ✅(Solved) Fix Sending this message (9 tokens) might exceed the context window limit (-31,601,307 tokens left). Please try reducing the size of your message or use the /compress command to compress the chat history. [1 pull requests, 1 participants]