[FEATURE]: Avoid auto-inlining large SVG files when pasting file path in TUI #9365

Open
opened 2026-02-16 18:12:16 -05:00 by yindo · 0 comments
Owner

Originally created by @ChuranNeko on GitHub (Feb 14, 2026).

Originally assigned to: @thdxr on GitHub.

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Problem

When pasting an .svg file path into the TUI input, OpenCode automatically reads the SVG file and inlines its full content into the model request.

For large SVG files, this can:

  • Exceed model context limits
  • Cause truncation of previous conversation
  • Increase token cost significantly
  • Slow down responses
  • Fail requests silently or unexpectedly

This behavior is surprising because the user only intended to reference a file path, not inject the entire SVG content into the prompt.
While SVG makes the issue easy to reproduce due to large inline path data, the underlying problem applies to any large text-based resource file. The root cause is unconditional file inlining without token-awareness.

Reproduction

  1. Copy an SVG file path, e.g.
    /home/Projects/nekopage/Page/public/favicon.svg
  2. Paste it into OpenCode TUI input.
  3. Send any message.

Observed:

  • TUI labels it as [SVG: ]
  • OpenCode still inlines the entire SVG content into the request
  • API returns: "Input exceeds context window of this model"

Why This Is Problematic

SVG is technically a text file, but semantically it is an image resource.

Large SVG files often contain:

  • Massive path data
  • Long inline style blocks
  • Thousands of vector commands

In most cases, the model does not need the entire raw XML content.

Automatic full inlining is unsafe for:

  • Token usage
  • Cost control
  • Context window stability
  • Predictability in TUI usage

Proposed Solution

Introduce a size-aware and type-aware file injection policy.

Suggested Behavior

  1. Detect file type (.svg or content starting with <svg)
  2. Estimate file size or token count
  3. If above a configurable threshold:
    • Do NOT auto-inline full content
    • Instead:
      • Include file path only
      • Or include a structured summary
      • Or prompt user for confirmation

Example UX

Detected large SVG (142KB, ~18k tokens).
Using summary mode. Use --expand to inline full file.

Config Options

  • max_auto_inline_tokens
  • auto_inline_svg: true/false
  • large_text_policy: inline | summary | path_only | prompt_user

Expected Outcome

  • Prevent accidental context overflow
  • Improve cost control
  • Make TUI behavior more predictable
  • Provide smarter file handling for resource-like files

Evidence / Logs

  • After pasting the SVG path, the TUI shows it was recognized as an SVG resource reference:

    [SVG: /home/Projects/nekopage/Page/public/favicon.svg]

  • However, OpenCode still reads and inlines the full SVG XML content into the outgoing request.

  • The provider returns an error:

    "Input exceeds context window of this model"

This indicates the request payload is already over the context limit at send time, caused by automatic file inlining rather than user intent.

  • Attached a large SVG sample in this issue for easy reproduction.
    (The file is intentionally large to trigger the current auto-inlining behavior.)
Image Image

Image

Originally created by @ChuranNeko on GitHub (Feb 14, 2026). Originally assigned to: @thdxr on GitHub. ### Feature hasn't been suggested before. - [x] I have verified this feature I'm about to request hasn't been suggested before. ### Describe the enhancement you want to request ## Problem When pasting an .svg file path into the TUI input, OpenCode automatically reads the SVG file and inlines its full content into the model request. For large SVG files, this can: - Exceed model context limits - Cause truncation of previous conversation - Increase token cost significantly - Slow down responses - Fail requests silently or unexpectedly This behavior is surprising because the user only intended to reference a file path, not inject the entire SVG content into the prompt. While SVG makes the issue easy to reproduce due to large inline path data, the underlying problem applies to any large text-based resource file. The root cause is unconditional file inlining without token-awareness. ## Reproduction 1. Copy an SVG file path, e.g. /home/Projects/nekopage/Page/public/favicon.svg 2. Paste it into OpenCode TUI input. 3. Send any message. Observed: - TUI labels it as [SVG: <path>] - OpenCode still inlines the entire SVG content into the request - API returns: "Input exceeds context window of this model" ## Why This Is Problematic SVG is technically a text file, but semantically it is an image resource. Large SVG files often contain: - Massive path data - Long inline style blocks - Thousands of vector commands In most cases, the model does not need the entire raw XML content. Automatic full inlining is unsafe for: - Token usage - Cost control - Context window stability - Predictability in TUI usage ## Proposed Solution Introduce a size-aware and type-aware file injection policy. ### Suggested Behavior 1. Detect file type (.svg or content starting with <svg) 2. Estimate file size or token count 3. If above a configurable threshold: - Do NOT auto-inline full content - Instead: - Include file path only - Or include a structured summary - Or prompt user for confirmation ### Example UX Detected large SVG (142KB, ~18k tokens). Using summary mode. Use --expand to inline full file. ### Config Options - max_auto_inline_tokens - auto_inline_svg: true/false - large_text_policy: inline | summary | path_only | prompt_user ## Expected Outcome - Prevent accidental context overflow - Improve cost control - Make TUI behavior more predictable - Provide smarter file handling for resource-like files ## Evidence / Logs - After pasting the SVG path, the TUI shows it was recognized as an SVG resource reference: [SVG: /home/Projects/nekopage/Page/public/favicon.svg] - However, OpenCode still reads and inlines the full SVG XML content into the outgoing request. - The provider returns an error: "Input exceeds context window of this model" This indicates the request payload is already over the context limit at send time, caused by automatic file inlining rather than user intent. - Attached a large SVG sample in this issue for easy reproduction. (The file is intentionally large to trigger the current auto-inlining behavior.) <img width="1919" height="1079" alt="Image" src="https://github.com/user-attachments/assets/acf010f7-d5c9-439b-aa8c-1a2bb522c54c" /> <img width="1919" height="1079" alt="Image" src="https://github.com/user-attachments/assets/cfe8552c-216f-490b-8fdb-da495dd7ae3f" /> ![Image](https://github.com/user-attachments/assets/174bae8c-040c-43d7-a957-945802044ddf)
yindo added the discussion label 2026-02-16 18:12:16 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#9365