n8n-io/n8n · error · MultipleMatchesError

Found matches. Please provide more context to make the…

Error message

Found ${count} matches. Please provide more context to make the replacement unique.

What it means

Edit failure (MultipleMatchesError) from the text editor's handleStrReplace. It fires when old_str occurs more than once in the file, making the replacement ambiguous; the tool only replaces unique matches. The caller must add surrounding context to disambiguate.

Solutions

  1. Extend old_str with surrounding lines so it matches exactly one place in the file.
  2. Include unique identifiers (function names, variable names) in old_str.
  3. Replace occurrences one at a time, re-reading the file between edits.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/@n8n/ai-utilities/src/utils/text-editor.ts:381 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/2628c6637cf85b1d. Report an issue: GitHub.

Appendix: source

Thrown at packages/@n8n/ai-utilities/src/utils/text-editor.ts:381

		}

		const { old_str, new_str } = command;
		const count = this.countOccurrences(this.text, old_str);

		if (count === 0) {
			const normalized = old_str.endsWith('\n') ? old_str.slice(0, -1) : old_str + '\n';
			const normalizedCount = this.countOccurrences(this.text, normalized);
			if (normalizedCount === 1) {
				this.text = this.text.replace(normalized, this.escapeReplacement(new_str));
				return 'Edit applied successfully.';
			}

			const context = findDivergenceContext(this.text, old_str);
			throw new NoMatchFoundError(old_str, context);
		}

		if (count > 1) {
			throw new MultipleMatchesError(count);
		}

		this.text = this.text.replace(old_str, this.escapeReplacement(new_str));
		return 'Edit applied successfully.';
	}

	private handleInsert(command: InsertCommand): string {
		if (this.text === null) {
			throw this.createFileNotFoundError();
		}

		const { insert_line, insert_text } = command;
		const lines = this.text.split('\n');

		if (insert_line < 0 || insert_line > lines.length) {
			throw new InvalidLineNumberError(insert_line, lines.length);
		}

View on GitHub (pinned to 5ac6606e81)