A file has a header and a body.
import { RECEIPT } from 'crw:lib/schemas' // header: zero or more static imports ...
import { greeting } from './hello-lib.js'
export const meta = { name: 'hello', phases: ['greet'] } // ... then exactly one meta
phase('greet') // body: everything after the meta statement
const hi = await agent(greeting('crw')) // top-level await
return { hi } // top-level return: the run's result- The header is zero or more static
importstatements followed by exactly oneexport const meta = <object literal>. An import has one of the formsimport 'm',import d from 'm',import {a, b as c} from 'm',import * as ns from 'm'andimport d, {a} from 'm'. metamust evaluate to a JSON-serialisable object. It is evaluated as an expression in a fresh runtime with no host globals, so it cannot callagentor readargs, and under the same determinism stubs as the body (below), soDate.now(),Math.random(),new Date()andDate()in ametaare load errors. It is recorded in the run record.- The body may use top-level
awaitand top-levelreturn. These are a CRW extension and the script is not standard ESM: the body runs as the body of an async function, and the value it returns is the run's result. A script in the shape Claude Workflow accepts (ametaand a body with top-level await and return, no imports) is a subset of this format. - An
importorexportafter the header, a dynamicimport(),import.meta, and any export other thanmetaare load errors. The body is checked with a lexer that tracks strings, template literals (including their substitutions), comments and regular expression literals, so the words inside them are not taken for statements. A property call (o.import(x), also with whitespace or a comment between the dot and the name) and a method namedimportorexport({ import(x) { ... } }) are not imports; a method declaration is told from a call by the{that follows its parameter list on the same line. - Script errors keep the body's line numbers: the header is replaced by blank lines in the executed text and the transform's source map is given to the runtime.