Tech

Claude Made Expo Understand Our Dynamic Routes

I've been using AI to do more than just autocomplete: stitching together build tools, scripting, and navigating complex codebases. Here's how Claude Code CLI helped solve a tricky routing problem during our React Native to Expo migration — without touching a single screen manually.

Mihir Karandikar·June 10, 2025·7 min read

At udaan, we're knee-deep in migrating our React Native app to Expo. And one feature we were genuinely excited about was Expo Router. A clean, file-based routing system with built-in deep linking? Sign me up!

But there was a catch. Our app doesn't use static routes at all.

All screens live in a separate package called ui-screens, shared between our native and web apps. They're loaded dynamically using a central workflows registry. There's no predictable folder structure. Screens can live anywhere. Navigation is dynamic, driven by code, not file structure.

That's the opposite of what Expo Router expects. It relies on folders and filenames to figure out your routes. And refactoring 200+ screens just to make it happy? ABSOLUTELY NOT HAPPENING.

I've been using AI tooling for a while now — not just for autocomplete, but for stitching systems together, prototyping quickly, and skipping the yak-shaving.

So instead of brute-forcing a migration, I came up with a plan 🙃

The Plan

  • Write an rspack plugin to extract import paths to each screen
  • Run the app in a headless Node.js environment and access workflows registry
  • Publish the metadata inside the ui-screens npm package
  • Generate route files using an Expo plugin that mimics the expected folder structure

That's where Claude Code CLI came in. I had no idea how to get ui-screens to run headlessly in node, no experience writing Rspack plugins, and zero interest in manually wrangling metadata inside the Expo plugin. So I just told Claude what I needed and it figured out the messy parts.

The words CLAUDE CODE in orange pixel lettering on black.

This was my first time using Claude Code CLI for a real task. And it turned out to be the most suitable tool for the job. It runs locally, plays nicely with the file system, and relies on fast bash commands instead of UI gimmicks. For scanning repos, generating files, and wiring up build scripts, it just made sense.

Step 1: Rspack plugin to map modules and import paths

The first hurdle: getting ui-screens to run outside its natural habitat — no browser, no mobile runtime, just Node.js. Since the screens are powered by react-native-web and bundled with Rspack, the idea was to reuse our Rspack config, run it in node mode, and tap into the internals to get what we need.

Claude started by generating a new Rspack config with a custom entry file: scripts/metadata-extractor.tsx. It compiles everything into a node-compatible bundle.

JS
{    entry: './scripts/metadata-extractor.tsx',    mode: 'development',    target: 'node',    output: {        filename: 'metadata-extractor.js',        path: path.resolve(__dirname, 'dist/metadata/intermediate'),        library: {            type: 'commonjs2',        },    },}

But the real trick was the custom Rspack plugin.

Claude scaffolded a minimal plugin, hooked it into the compiler, and iterated from there. Compiling, breaking, fixing, repeating until we landed on something solid.

What it does: Walks the module graph, finds all .ts and .tsx files inside workflows/ (skipping test files), extracts the screen name, and maps it to the file's absolute path. The result is a dead-simple import-mapping.json where each screen name points to the file it came from.

This is a simplified version of what the plugin does:

JS
class ImportMappingPlugin {    apply(compiler) {        compiler.hooks.compilation.tap('ImportMappingPlugin', (compilation) => {            compilation.hooks.seal.tap('ImportMappingPlugin', () => {                const modules = compilation.modules                const importMapping = new Map()
                for (const module of modules) {                    if (!module.resource) continue
                    if (isWorkflowFile(module.resource)) {                        const moduleName = path.basename(module.resource, path.extname(module.resource))                        importMapping.set(moduleName, module.resource)                    }                }
                // Write the import mapping data                const importMappingData = Object.fromEntries(importMapping)                fs.writeFileSync('import-mapping.json', JSON.stringify(importMappingData, null, 2))
                console.log(`Done mapping for ${importMapping.size} workflows!`)            })        })    }}

The output is written to import-mapping.json, and looks something like this:

JSON
{  ...  "EwalletPaymentScreen": "ui-screens/dist/workflows/payment/EwalletPaymentScreen.tsx",  "ReviewReturnScreen": "ui-screens/dist/workflows/returns_v2/ReviewReturnScreen.tsx",  "PrepaymentScreen": "ui-screens/dist/workflows/payment/PrepaymentScreen.tsx",  "AboutUsScreen": "ui-screens/dist/workflows/about-us/AboutUsScreen.tsx",  ...}

Rspack also outputs metadata-extractor.js — a fully bundled, node-friendly version of the ui-screens app. Run it with node, and it boots up the workflows registry just like it would inside the app.

No Metro. No React Native runtime. No browser. Just data ❤️

Step 2: Metadata extraction in headless mode

Mapping file paths was just the start. What we really needed was routing metadata — the stuff defined inside each screen's navigationOptions. That's what drives navigation in both our web and native apps.

TS
export const navigationOptions = {    screenName: 'YourOrderDetails',    path: '/your-orders/order-details/:orderId',    defaultParams: {},}

To extract this, we needed to actually run the app.

So we executed the compiled metadata-extractor.js in a headless Node.js environment. It bootstraps the ui-screens package, loads all the screens to populate the workflows registry, and then walks through each workflow to collect relevant metadata.

Here's a stripped-down version of what it does:

TS
import { workflows } from './registry/Workflows'import importMapping from './import-mapping.json'
const all = workflows.getAll()
const screens = all.filter(hasNavigationOptions).map((wf) => ({    screenName: wf.screenName,    path: wf.screen.navigationOptions.path,    importPath: transformToPackagePath(importMapping[wf.name]),}))
fs.writeFileSync('screens.json', JSON.stringify({ screens }))

This generates the final screens.json file — a fully resolved list of all screens, the routes they expose, and the import paths they came from. No guesswork. No manual wiring. Just data, extracted from the same code that powers our app. Ready to be consumed by Expo Router.

JSON
{  "screens": [    {      "screenName": "AboutUs",      "path": "/about-us",      "importPath": "ui-screens/dist/workflows/about-us/AboutUsScreen",      "allowLoggedOut": true,      "defaultParams": {}    },    {      "screenName": "AccountSetup",      "path": "/your-account/setup",      "importPath": "ui-screens/dist/workflows/account/AccountSetupScreen"    }    ...    ...  ]}

Step 3: Auto-generating routes for Expo Router

Now that we had screens.json — a complete list of screens, paths, and import locations — it was time to turn that metadata into real files that Expo Router could understand. Claude generated an Expo config plugin. Here's what it does:

  • Converts the route path into a valid file path.
    • Eg. /about-us -> src/app/__generated__/about-us.tsx
  • Handles dynamic and optional route params.
    • Eg. :userId becomes [userId] and :tab? becomes [tab]
  • Writes it to disk, so Expo Router treats them like any regular static routes
A file tree showing src/app/__generated__ with route folders and files such as boltCart/[cartId].tsx and brand/[brandId].tsx.

The result is a fully functional routing setup — with deep linking, navigation, and screen-level config — all driven from our existing workflows registry, with zero manual wiring.

And the best part? No need to refactor hundreds of screens or restructure folders. It just works.

About Claude Code CLI

Claude Code CLI is fast and unnervingly so. It handles large, cross-repo setups with ease and holds a surprisingly generous context window. But speed isn't free. This session cost over $16, and while I'm not sure every dollar was justified, it was a good reminder: cost control matters.

Claude Code's /cost output: total cost $16.98, 1 hour 22 minutes of API time, 1,802 lines added and 812 removed.

What stood out is the design. It pauses before major steps, lets you review, and avoids waste. The Context left until auto-compact: 19% tracker is a thoughtful touch. When it did compact, it dropped a bit of context — but nothing broke.

When it fires up, it is not "calm." It's frantic, in a good way. Once you describe a task, it builds, breaks, tests, and retries until something usable lands. Like a junior dev on Red Bull, but productive.

It's also pricier than tools like Cursor, Windsurf, or ChatGPT. For smaller tasks, those are enough. Use Claude for repo-wide, multi-step work where structure matters.

At this point, I think of it like a subcontractor: You bring the plan. It ships the solution. And the meter's always running. It makes you wonder — should engineering orgs start allocating daily AI budgets per developer?

Food for thought: Maybe it's time we stop treating these tools like magic and start treating them like headcount.

Closing Thoughts

This entire flow from dynamic workflows to static Expo routes could've easily been a months-long refactor. Instead, it took a few hours, some curiosity, and the right AI tooling.

Claude Code CLI wasn't just a fancy autocomplete here. It helped stitch together Rspack internals, runtime behavior, and Expo plugin logic, across packages and build systems, without me getting lost in the weeds.

That might just be what modern engineering looks like. The job isn't about writing every line of code anymore. It's about knowing what the system needs, sketching the blueprint, and letting AI handle the boilerplate, the syntax, and the exploration.

It's a shift from "code author" to "solution architect". And once that shift clicks, you stop asking "Can I build this?". You start asking, "How fast can I ship it?"