wavetermdev/waveterm · error

stdin (-) can only be used once

Error message

stdin (-) can only be used once

What it means

The `wsh ai` command allows the special `-` argument (stdin) at most once. A stdinUsed flag guards this; passing a second `-` returns this error before reading anything, because each `-` would require a second sequential read of os.Stdin which the command does not support.

Source

Thrown at cmd/wsh/cmd/wshcmd-ai.go:97

	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)
			}
			fileName = "stdin"
			mimeType = "text/plain"
		} else {
			fileInfo, err := os.Stat(filePath)
			if err != nil {
				return fmt.Errorf("accessing file %s: %w", filePath, err)
			}
			absPath, err := filepath.Abs(filePath)
			if err != nil {
				return fmt.Errorf("getting absolute path for %s: %w", filePath, err)
			}

View on GitHub (pinned to a4447c1563)

Solutions

  1. Remove duplicate `-` arguments; keep exactly one `-`.
  2. Concatenate multiple stdin sources first: `cat a b | wsh ai -`.
  3. If second input is a file, pass its path instead of `-`.
  4. For scripting, deduplicate the args list before invoking wsh ai.

Example fix

// before
$ echo x | wsh ai - - notes.txt
// after
$ echo x | wsh ai - notes.txt
Defensive patterns

Strategy: validation

Validate before calling

count=$(printf '%s\n' "$@" | grep -cx -- '-' || true)
if [ "$count" -gt 1 ]; then
  echo "wsh ai accepts at most one '-' (stdin) argument" >&2
  exit 1
fi

Prevention

When it happens

Trigger: Running e.g. `wsh ai - - file.txt` or `cat a | wsh ai - -`, i.e. two or more literal `-` arguments in the same invocation.

Common situations: Users assuming `-` behaves like `cat` (repeatable), templated commands that inject `-` per input stream, copy-pasted command lines with duplicated placeholders.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/16cfd223092f7084. Report an issue: GitHub.