REPL is your programming interface to Claude Code's tools. Use it to loop, branch, and compose tool calls with code.
Write JavaScript that calls tools as async functions:
const { filenames } = await Glob({ pattern: 'src/**/*.ts' })
for (const f of filenames) {
const { file } = await Read({ file_path: f })
if (file.content.includes('oldName')) {
await Edit({ file_path: f, old_string: 'oldName', new_string: 'newName', replace_all: true })
}
}IMPORTANT: Batch ALL operations into ONE REPL call. Don't make multiple separate REPL calls - write a complete script that does everything.
All tools work as async functions: Read, Write, Edit, Glob, Grep, ${SHELL_TOOL_NAME}, etc. MCP tools are callable by their full name (e.g. await mcp__slack__slack_send_message({...})).${IS_MCP_TOOL_ERROR_THROW_ENABLED?" Built-in tools resolve with {error: string} on failure; MCP tool calls THROW on failure — catch only where you can genuinely proceed without the result, and never treat a caught failure as success.":""}
const { filenames } = await Glob({ pattern: '*.ts' })
const { file } = await Read({ file_path: 'config.json' })
await Edit({ file_path: 'foo.ts', old_string: 'old', new_string: 'new' })
const { stdout } = await ${SHELL_TOOL_NAME}({ command: 'git status' })import/requiredon't work here — the vm context is sealed. For filesystem access useRead/Write/Glob; for shell use${SHELL_TOOL_NAME}.- Use
Promise.all()for parallel operations - Variables persist across REPL calls
- Last expression is returned as the result
haiku(prompt, schema?)— one-turn model sampling. Without schema returns text; with a JSON schema returns the parsed object.registerTool(name, desc, schema, handler)defines a new tool;unregisterTool(name),listTools(),getTool(name)manage them- ${IS_BASH_ENV?``shQuote(s)
quotes a string for Bash — use this instead ofJSON.stringify` (double quotes don't protect backticks or `$`) - Don't write a temp file just to feed a shell command — pipe via heredoc:
await ${SHELL_TOOL_NAME}({command: "${TEMP_FILE_HEREDOC_COMMAND_EXAMPLE}"}). Generic temp paths get clobbered by parallel agents.:"shQuote(s)is POSIX-only — for PowerShell, double the single quotes:"'"+s.replaceAll("'", "''")+"'". For multi-line input use a here-string@'\n...\n'@(closing'@` at column 0)."}