Skip to main content

Search file names

matches = machine.files.search_files("/workspace", "*.py")
for path in matches:
    print(path)

Search file contents

for match in machine.files.find_files("/workspace", "TODO"):
    print(match.file, match.line, match.content)

Replace text

paths = machine.files.search_files("/workspace", "*.py")
replacements = machine.files.replace_in_files(
    paths,
    "old_function",
    "new_function",
)
print(replacements)

Watch a directory

def on_event(event) -> None:
    print(event.type, event.event_type, event.path)

with machine.files.watch_dir("/workspace", on_event=on_event, recursive=True):
    machine.files.write("/workspace/changed.txt", "changed\n")
Directory watch is not a plain REST call: it streams change events over the machine control WebSocket rather than a single request/response endpoint, so there is no curl equivalent. watch_dir calls on_event for file changes and returns a handle with stop(). recursive=True watches nested directories, and timeout= can bound how long the watch stays open. The CLI streams watch events as JSON lines.