CLI -p mode rejects valid prompts with 'Prompt is too long' below model context limit

Resolved 💬 6 comments Opened Nov 25, 2025 by winnal Closed Mar 1, 2026

Description

When using Claude Code CLI in print mode (-p), the CLI rejects prompts with "Prompt is too long" error even when the prompt size is well within the model's actual context window.

Environment

  • Claude Code version: 2.0.52
  • OS: macOS Darwin 24.6.0
  • Model: claude-opus-4-5-20251101 (also tested with claude-sonnet-4-5-20250929)

Steps to Reproduce

  1. Create a prompt that is ~524k characters (~120k tokens)
  2. Run: claude -p --model opus "$(cat large_prompt.txt)"
  3. CLI immediately returns "Prompt is too long" error

Observed Behavior

{"type":"assistant","message":{"content":[{"type":"text","text":"Prompt is too long"}],"error":"invalid_request"}}
{"type":"result","subtype":"success","is_error":true,"duration_ms":1024,"duration_api_ms":0,"num_turns":1,"result":"Prompt is too long"}

Key observations:

  • input_tokens: 0 - The prompt is rejected before reaching the API
  • duration_api_ms: 0 - No API call is made
  • The error occurs regardless of model selected (opus, sonnet, sonnet[1m])

Expected Behavior

  • Opus 4.5 has a 200k token context window
  • Sonnet with extended context (sonnet[1m]) has 1M token context
  • A ~120k token prompt should be accepted and sent to the API

The CLI should not have a hardcoded limit lower than the model's actual context window, or at minimum should respect extended context model variants.

Use Case

This affects automated workflows that use -p mode for code review/analysis tasks with large codebases. The same prompts work fine with other CLI tools (e.g., Codex, Gemini CLI) that don't impose artificial limits below the model's capability.

Workaround Attempted

  • Tried --model opus, --model sonnet, --model sonnet[1m] - all fail
  • Tried with and without --output-format stream-json - same error
  • The limit appears to be in the CLI itself, not configurable via settings or environment variables

Suggested Fix

  1. Remove or significantly increase the CLI's internal prompt size limit for -p mode
  2. Or make it configurable via settings.json or environment variable
  3. Or at minimum, respect the model's actual context window (200k for opus, 1M for extended context variants)

View original on GitHub ↗

This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗