# Proposal: change \`mojo run\` argument handling

**URL:** <https://forum.modular.com/t/proposal-change-mojo-run-argument-handling/2639>\
**Category:** Mojo\
**Tags:** discussion, mojo-compiler\
**Created:** [January 26, 2026, 4:27pm UTC](https://forum.modular.com/t/proposal-change-mojo-run-argument-handling/2639 "2026-01-26T16:27:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![fcormack](https://avatars.discourse-cdn.com/v4/letter/f/d78d45/32.png) [@fcormack](https://forum.modular.com/u/fcormack)\
**Post date:** [January 26, 2026, 4:27pm UTC](https://forum.modular.com/t/proposal-change-mojo-run-argument-handling/2639/1 "2026-01-26T16:27:14Z")

</div>

Hi, I’m Fraser and I work on the compiler team.

I’d like to propose a small change to how `mojo run` (and `mojo debug`) handle the split between compiler and program arguments. I’m looking for community feedback and whether people would find it valuable.

As you probably know, `mojo run` has the following form:

```bash
mojo [compiler-options] input.mojo [program-args]

```

That is, everything before the input filename is treated as a compiler option, and everything after the filename is passed on to the program when it’s run.

I and others have in the past found this behaviour unintuitive. My primary concern is a user thinking they are passing a compiler option when in fact it’s silently being passed to a program that ignores it. For example: wondering why a compiled program doesn’t set the right define; why it doesn’t enable an optimization you’re asking for; why it doesn’t compile for the right CPU:

```bash
mojo input.mojo --mcpu=haswell -Dfoo=42 --make-it-fast

```

These scenarios could all do the wrong thing quite silently.

I therefore propose that we split compiler and program arguments with a double-dash `--`.

```bash
mojo [compiler-options-or-input-file] [-- [program-args]]

```

This form would make clear the distinction between the two options categories. This could be useful, e.g., if the compiler and program accept similar-looking options (e.g., `--help`). It also allows compiler options to be interleaved with the input file.

For example:

```bash
mojo run --A --B input.mojo --C -- --D E F

```

With this form, options `--A`, `--B`, and `--C` are passed to the compiler, and arguments `--D`, `E`, and `F` are passed to the program.

There is precedent for this sort of argument handling, including [in POSIX](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02) guidelines and amongst some other common developer tools.

This would be a breaking change, as any scripts or workflows currently passing arguments to the program (after the input file) would suddenly start passing them to the compiler. This would more likely than not result in a compiler error (as it will error on any unrecognized arguments) but that’s not universally true.

I look forward to your feedback!

---

<div class="post-metadata">

**Author:** ![owenhilyard](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.modular.com/owenhilyard/32/41_2.png) [@owenhilyard](https://forum.modular.com/u/owenhilyard)\
**Post date:** [January 26, 2026, 5:10pm UTC](https://forum.modular.com/t/proposal-change-mojo-run-argument-handling/2639/2 "2026-01-26T17:10:27Z")

</div>

I agree, moving to follow POSIX would be good here.

While you’re at it, is making `-Dfoo=42` work possible? Right now it gives an error unless you do `-D foo=42`. In general, I’d love of all single-character compiler flags followed standard convention and you could have arguments to them with no spaces (ex: `-I`, `-j`). `-O` appears to be special cased to work as one would expect. This shouldn’t be a breaking change but would be a nice “while you’re there” change.

---

<div class="post-metadata">

**Author:** ![samufi](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@samufi](https://forum.modular.com/u/samufi)\
**Post date:** [January 27, 2026, 9:24am UTC](https://forum.modular.com/t/proposal-change-mojo-run-argument-handling/2639/3 "2026-01-27T09:24:26Z")

</div>

Just to get this right, if I do not care about compiler args and simply want to run my program with cli args, I would have to do

```auto
mojo run myprogram -- -myarg

```

and

```auto
mojo run myprogram -myarg

```

would run into a compiler error unless the argument is recognized?

For this simple use case, I do not find this ideal.

I do see your point, though, and I may have been running into the issue myself.

Would it be an option to check all arguments whether they match compiler args and raise a warning if they do? And maybe suppress the warning with --?

---

<div class="post-metadata">

**Author:** ![fcormack](https://avatars.discourse-cdn.com/v4/letter/f/d78d45/32.png) [@fcormack](https://forum.modular.com/u/fcormack)\
**Post date:** [January 27, 2026, 10:11am UTC](https://forum.modular.com/t/proposal-change-mojo-run-argument-handling/2639/4 "2026-01-27T10:11:03Z")

</div>

Oh, thanks for bringing that up! I agree that if we offer options that mirror standard conventions (like `-D`) then they should behave as such. I’ll make a note.

---

<div class="post-metadata">

**Author:** ![fcormack](https://avatars.discourse-cdn.com/v4/letter/f/d78d45/32.png) [@fcormack](https://forum.modular.com/u/fcormack)\
**Post date:** [January 27, 2026, 10:21am UTC](https://forum.modular.com/t/proposal-change-mojo-run-argument-handling/2639/5 "2026-01-27T10:21:01Z")

</div>

That’s right - going by my proposal, you’d have to specify the `--` regardless. It is unfortunately more characters.

I’m not sure how I feel about checking all arguments. It’s ultimately ambiguous whether or not an option is a compiler or program argument (`--help` could be both) and I personally like keeping tools simple and consistent.

---

<div class="post-metadata">

**Author:** ![fcormack](https://avatars.discourse-cdn.com/v4/letter/f/d78d45/32.png) [@fcormack](https://forum.modular.com/u/fcormack)\
**Post date:** [February 6, 2026, 11:03am UTC](https://forum.modular.com/t/proposal-change-mojo-run-argument-handling/2639/6 "2026-02-06T11:03:01Z")

</div>

I should say, I fixed the issue with conjoined `-D` a week or two back so -`Dfoo=42` should work for you now. I couldn’t see a problem with `-I` and `-j`. Please file a ticket if you see anything else that needs fixing up!

---

<div class="post-metadata">

**Author:** ![owenhilyard](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.modular.com/owenhilyard/32/41_2.png) [@owenhilyard](https://forum.modular.com/u/owenhilyard)\
**Post date:** [February 6, 2026, 2:49pm UTC](https://forum.modular.com/t/proposal-change-mojo-run-argument-handling/2639/7 "2026-02-06T14:49:37Z")

</div>

Sorry if I sent you on a wild goose chase, I meant to use `-I` and -j`as examples of how it should work.`-D` now works as expected and my habits from C are no longer fighting me. Thank you!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex001/uploads/modular/original/1X/2751e0fbdc595a99718b216730957e9db4448cfd.jpeg) [@system](https://forum.modular.com/u/system)\
**Post date:** [August 5, 2026, 2:49pm UTC](https://forum.modular.com/t/proposal-change-mojo-run-argument-handling/2639/8 "2026-08-05T14:49:56Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
