wavetermdev/waveterm · error
too many files (maximum %d files allowed)
Error message
too many files (maximum %d files allowed)
What it means
The `wsh ai` command accepts at most 15 file arguments (maxFileCount). Before reading any file, aiRun checks len(args) and returns this error immediately if the count exceeds the limit, because every file is read fully and base64-encoded into a single RPC payload. The %d verb is filled with 15. It is a client-side guard, not a server error.
Source
Thrown at cmd/wsh/cmd/wshcmd-ai.go:86
func aiRun(cmd *cobra.Command, args []string) (rtnErr error) {
defer func() {
sendActivity("ai", rtnErr == nil)
}()
if len(args) == 0 && aiMessageFlag == "" {
OutputHelpMessage(cmd)
return fmt.Errorf("no files or message provided")
}
const maxFileCount = 15
const rpcTimeout = 30000
var allFiles []wshrpc.AIAttachedFile
var stdinUsed bool
if len(args) > maxFileCount {
return fmt.Errorf("too many files (maximum %d files allowed)", maxFileCount)
}
for _, filePath := range args {
var data []byte
var fileName string
var mimeType string
var err error
if filePath == "-" {
if stdinUsed {
return fmt.Errorf("stdin (-) can only be used once")
}
stdinUsed = true
data, err = io.ReadAll(os.Stdin)
if err != nil {
return fmt.Errorf("reading from stdin: %w", err)
}View on GitHub (pinned to a4447c1563)
Solutions
- Reduce the number of file arguments to 15 or fewer (most important files only).
- Zip/tar the files and attach the archive as a single binary/PDF-style input, or paste relevant excerpts via --message.
- If a glob expanded unexpectedly, quote it or use a narrower pattern, e.g. `wsh ai "src/**/*.ts"` won't help; instead list explicit paths or use `xargs -n15` batches.
- Attach a directory argument instead — a directory is summarized as a JSON listing, not read as a file, and counts as only one argument.
Example fix
// before: wsh ai *.log (expands to 40 files) // after ls *.log | head -15 | xargs wsh ai --message "summarize these logs"
Defensive patterns
Strategy: validation
Validate before calling
files=("$@")
if [ ${#files[@]} -gt 15 ]; then
echo "wsh ai accepts at most 15 files; got ${#files[@]}" >&2
exit 1
fi
wsh ai "${files[@]}" Prevention
- Quote globs or test their expansion count (`set -- *.go; echo $#`) before invoking wsh ai.
- Prefer attaching one directory argument (JSON listing) over many individual files.
- Cap batch scripts with `xargs -n15` when looping wsh ai invocations.
When it happens
Trigger: Running `wsh ai` (or `wsh ai --message ...`) with more than 15 path arguments, e.g. glob expansion like `wsh ai *.go` in a directory containing 16+ Go files, or a script that passes a whole directory's contents as arguments.
Common situations: Shell globs expanding to many files (`wsh ai src/**/*.ts`), batch scripts looping over file lists, users trying to attach an entire project at once.
Related errors
- no files or message provided
- stdin (-) can only be used once
- WAVETERM_TABID environment variable not set
- resolving block: %v
- watching pid: %v
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/62f971d924cdd9e8.
Report an issue: GitHub.