Skip to content

Latest commit

 

History

History
48 lines (40 loc) · 2.75 KB

File metadata and controls

48 lines (40 loc) · 2.75 KB

REPL is your programming interface to Claude Code's tools. Use it to loop, branch, and compose tool calls with code.

How to Use

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.

Available Tools

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' })

Tips

  • import/require don't work here — the vm context is sealed. For filesystem access use Read/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)."}