{"record":{"id":"62f971d924cdd9e8","repo":"wavetermdev/waveterm","slug":"too-many-files-maximum-d-files-allowed","errorCode":null,"errorMessage":"too many files (maximum %d files allowed)","messagePattern":"too many files \\(maximum (.+?) files allowed\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-ai.go","lineNumber":86,"sourceCode":"\nfunc aiRun(cmd *cobra.Command, args []string) (rtnErr error) {\n\tdefer func() {\n\t\tsendActivity(\"ai\", rtnErr == nil)\n\t}()\n\n\tif len(args) == 0 && aiMessageFlag == \"\" {\n\t\tOutputHelpMessage(cmd)\n\t\treturn fmt.Errorf(\"no files or message provided\")\n\t}\n\n\tconst maxFileCount = 15\n\tconst rpcTimeout = 30000\n\n\tvar allFiles []wshrpc.AIAttachedFile\n\tvar stdinUsed bool\n\n\tif len(args) > maxFileCount {\n\t\treturn fmt.Errorf(\"too many files (maximum %d files allowed)\", maxFileCount)\n\t}\n\n\tfor _, filePath := range args {\n\t\tvar data []byte\n\t\tvar fileName string\n\t\tvar mimeType string\n\t\tvar err error\n\n\t\tif filePath == \"-\" {\n\t\t\tif stdinUsed {\n\t\t\t\treturn fmt.Errorf(\"stdin (-) can only be used once\")\n\t\t\t}\n\t\t\tstdinUsed = true\n\n\t\t\tdata, err = io.ReadAll(os.Stdin)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"reading from stdin: %w\", err)\n\t\t\t}","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-ai.go#L68-L104","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: wsh ai *.log  (expands to 40 files)\n// after\nls *.log | head -15 | xargs wsh ai --message \"summarize these logs\"","handlingStrategy":"validation","validationCode":"files=(\"$@\")\nif [ ${#files[@]} -gt 15 ]; then\n  echo \"wsh ai accepts at most 15 files; got ${#files[@]}\" >&2\n  exit 1\nfi\nwsh ai \"${files[@]}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["cli","argument-limit","wsh"],"backgroundTag":"too-many-files-argument-limit","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}