windmill-labs/windmill · error

No script code available to edit. Please ensure you have a s

Error message

No script code available to edit. Please ensure you have a script open in the editor.

What it means

The AI edit-code tool applies LLM-produced diffs to the script currently open in the editor. scriptOptions holds that code; when it is undefined (no script/flow editor context), the tool throws this error and reports 'No script found in current context' in the tool status.

Source

Thrown at frontend/src/lib/components/copilot/chat/script/core.ts:781

			required: []
		}
	}
}

export const editCodeToolWithDiff: Tool<ScriptChatHelpers> = {
	def: EDIT_CODE_TOOL_WITH_DIFF,
	streamArguments: true,
	showDetails: true,
	showFade: true,
	fn: async function ({ args, helpers, toolCallbacks, toolId }) {
		const scriptOptions = helpers.getScriptOptions()

		if (!scriptOptions) {
			toolCallbacks.setToolStatus(toolId, {
				content: 'No script available to edit',
				error: 'No script found in current context'
			})
			throw new Error(
				'No script code available to edit. Please ensure you have a script open in the editor.'
			)
		}

		if (!args.diffs || !Array.isArray(args.diffs)) {
			toolCallbacks.setToolStatus(toolId, {
				content: 'Invalid diffs provided',
				error: 'Diffs parameter is required and must be an array'
			})
			throw new Error('Diffs parameter is required and must be an array')
		}

		toolCallbacks.setToolStatus(toolId, { content: 'Applying code changes...' })

		try {
			// Save old code
			const oldCode = scriptOptions.code

View on GitHub (pinned to e474e8803c)

Solutions

  1. Open the target script in the script editor before asking the AI to edit it
  2. Verify the chat session is the one attached to the open editor (editor-scoped chat)
  3. Reload the editor page if the script is visibly open but context was lost
  4. Copy the code into the prompt or use a flow-scoped chat if editing within a flow step

Example fix

// before (global chat) — 'edit my script' -> throws
// after
// open /scripts/run/my_script, then ask in that page's chat
'fix the error in this script'
Defensive patterns

Strategy: validation

Validate before calling

if (!scriptOptions || typeof scriptOptions.code !== 'string') {
  // no script open: ask the user to open the script editor first
}

Type guard

function hasScriptContext(scriptOptions) {
  return scriptOptions != null && typeof scriptOptions.code === 'string'
}

Prevention

When it happens

Trigger: Calling editCodeTool from a chat with no script open — global chat on the home page, a chat on a non-editor page, or the editor lost its script binding (e.g. after navigation).

Common situations: Asking the copilot to 'fix my script' from the dashboard; script editor still loading when the tool runs; chat session disconnected from the editor context.

Related errors


AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03). Data as JSON: /api/errors/78789936b0b0b53a. Report an issue: GitHub.