on main help sign in
fix: reduce max read size from 5mb to 1mb for view and fetch tools (#2447)

5MB is way too much. Many models simply don't have the context windows to handle that. 1MB seems to works well. Worth noting that: * For the view tool, the model will be instruced to read in pieces * For the fetch tool, the content will be truncated with a note To reproduce (I tested with Kimi K2.5), use the following prompt: read this: https://developers.openai.com/api/reference/resources/responses

commitdfc57d4c1d779da45197d6b5ec6569cf515e4d77 authorAndrey Nering <andreynering@users.noreply.github.com> dateMon 23 Mar 2026, 17:29 (7 months ago) parent0c6fb42
2 files changed+11−12
internal/agent/tools/fetch.go+8−9 internal/agent/tools/view.go+3−3
internal/agent/tools/fetch.go+8−9
@@ -16,7 +16,10 @@ import (
1616 "github.com/charmbracelet/crush/internal/permission"
1717)
1818
19−const FetchToolName = "fetch"
19+const (
20+ FetchToolName = "fetch"
21+ MaxFetchSize = 1 * 1024 * 1024 // 1MB
22+)
2023
2124//go:embed fetch.md
2225var fetchDescription []byte
@@ -105,11 +108,7 @@ func NewFetchTool(permissions permission.Service, workingDir string, client *htt
105108 return fantasy.NewTextErrorResponse(fmt.Sprintf("Request failed with status code: %d", resp.StatusCode)), nil
106109 }
107110
108− // maxFetchResponseSizeBytes is the maximum size of response body to read (5MB)
109− const maxFetchResponseSizeBytes = int64(5 * 1024 * 1024)
110−
111− maxSize := maxFetchResponseSizeBytes
112− body, err := io.ReadAll(io.LimitReader(resp.Body, maxSize))
111+ body, err := io.ReadAll(io.LimitReader(resp.Body, MaxFetchSize))
113112 if err != nil {
114113 return fantasy.NewTextErrorResponse("Failed to read response body: " + err.Error()), nil
115114 }
@@ -161,9 +160,9 @@ func NewFetchTool(permissions permission.Service, workingDir string, client *htt
161160 }
162161 }
163162 // truncate content if it exceeds max read size
164− if int64(len(content)) > MaxReadSize {
165− content = content[:MaxReadSize]
166− content += fmt.Sprintf("\n\n[Content truncated to %d bytes]", MaxReadSize)
163+ if int64(len(content)) > MaxFetchSize {
164+ content = content[:MaxFetchSize]
165+ content += fmt.Sprintf("\n\n[Content truncated to %d bytes]", MaxFetchSize)
167166 }
168167
169168 return fantasy.NewTextResponse(content), nil
internal/agent/tools/view.go+3−3
@@ -53,7 +53,7 @@ type ViewResponseMetadata struct {
5353
5454const (
5555 ViewToolName = "view"
56− MaxReadSize = 5 * 1024 * 1024 // 5MB
56+ MaxViewSize = 1 * 1024 * 1024 // 1MB
5757 DefaultReadLimit = 2000
5858 MaxLineLength = 2000
5959)
@@ -155,9 +155,9 @@ func NewViewTool(
155155 }
156156
157157 // Based on the specifications we should not limit the skills read.
158− if !isSkillFile && fileInfo.Size() > MaxReadSize {
158+ if !isSkillFile && fileInfo.Size() > MaxViewSize {
159159 return fantasy.NewTextErrorResponse(fmt.Sprintf("File is too large (%d bytes). Maximum size is %d bytes",
160− fileInfo.Size(), MaxReadSize)), nil
160+ fileInfo.Size(), MaxViewSize)), nil
161161 }
162162
163163 // Set default limit if not provided (no limit for SKILL.md files)