Skip to Content
Octapus

Working with AI agents

Octapus assumes an agent writes most of your app. Here is how to set one up so it can build, check and fix its own work.

We recommend building Octapus apps with an AI coding agent (Claude Code, Codex, Cursor and the like) and write these docs on that assumption. You describe the screen, the agent writes .tsrx and CSS, runs the build, reads the result and iterates. Your job is reviewing behavior, not typing components.

Why .tsrx works well for agents

Most of what goes wrong when an agent writes React code is bookkeeping, not intent. .tsrx removes much of that bookkeeping:

  • Markup is the body. A component is @{ … }: statements and JSX-like markup in one block, with loops as @for (… ; key …). There is no return (...) to keep balanced and no map with a forgotten key.
  • No dependency arrays to get wrong. The compiler infers effect dependencies.
  • Hooks are not order-sensitive. Hook slots are assigned by call site, so a hook inside a condition is fine.
  • Styles live with the component. A <style> block in the component is scoped to it, so an agent changing one screen does not break another.
  • It is still web code. The same file builds for the browser, so the agent can check its work in a browser before you ever open a simulator.
import { useState, useEffect } from 'octane';

export function Counter(props) @{
  const [count, setCount] = useState(0);

  if (!props.paused) {
    useEffect(() => {
      console.log('count is now', count);
    }); // dependencies inferred: [count]
  }

  <button onClick={() => setCount(count + 1)}>{'Count: ' + count}</button>
}

Give the agent these docs

The docs site serves every page as Markdown, made for agents:

URLContents
/llms.txtIndex of all pages with one-line descriptions
/llms-full.txtEvery page in one file
/docs/<page>.mdOne page as Markdown, e.g. /docs/guides/writing-apps.md

Point the agent at them from your project's AGENTS.md (or CLAUDE.md):

AGENTS.md
# Octapus app

This app is written in Octane `.tsrx` and built with Octapus for web, macOS and iOS.
Read https://octapusjs.dev/llms.txt before changing code, and
https://octapusjs.dev/docs/guides/writing-apps.md for what works on native.

- Entry: src/App.tsrx (export `App`). Global CSS: src/styles.css.
- Build and check: `pnpm oct build --target web,ios,mac --bake --json`
  Done means `"ok": true` and no diagnostics.
- The first render must be deterministic: no Date, Math.random or
  environment reads before the first commit (it becomes the baked first screen).
- Native has no DOM and no fetch. Branch with `import.meta.env.OCT_TARGET`.
- Native functions: define -> register -> regenerate types, as in
  https://octapusjs.dev/docs/guides/native-modules.md#adding-a-native-function

The build-check loop

oct build --json prints one JSON report instead of human-readable output, so an agent can tell exactly what failed:

pnpm oct build --target web,ios,mac --bake --json
{
  "ok": false,
  "diagnostics": ["App.tsrx:12:5: error: Unexpected token"],
  "targets": {
    "web": { "ok": true, "ms": 410, "dir": "dist/web" },
    "mac": { "ok": false, "diagnostics": ["..."] }
  }
}

The exit code is 0 when every target built, 1 when a target failed, and 2 for a usage error. See the CLI reference for every field.

Checking the result

Building is not the same as looking right. Give the agent ways to see what it made:

  • Web: serve dist/web and let the agent open it with a browser tool. This is the fastest loop and catches most layout and logic mistakes.
  • Native vs web: the dev tool shows the native and web renderings side by side and lists every element whose position or size differs.
  • Launch: log LaunchMetrics from the native view. If phase is remounted, the first render differed between the bake and the device; mismatch says where. Ask the agent to make that first render deterministic (see Troubleshooting).

Native code is agent-friendly too

Adding a Swift function follows a fixed recipe (scaffold with oct native new, register the module, regenerate types with oct native types), and the scaffold comes with a unit test that calls the function without a JS runtime. An agent can add and test a native function end to end. See Native modules.

Prompts that work

  • "Add a settings screen with a dark-mode toggle. Keep it in one .tsrx file with a scoped <style>. Build with --json and fix diagnostics until ok is true."
  • "This screen remounts on launch (mismatch: row 12: text "3" vs "4"). Find what makes the first render non-deterministic and move it into an effect."
  • "Make the list match the web layout on iOS. Compare with the dev tool's Native vs Web table and fix the largest differences first."

On this page