Use Python’s argparse to keep a wrapper’s flags separate from the program it starts. Suppose you run a renderer through a Python wrapper with --profile release. The command reports success, but the renderer uses its default profile. Check the arguments the wrapper actually passed before changing the renderer.
parse_known_args() can treat --profile as shorthand for the wrapper’s --profile-dir. Turn off abbreviations when the names are different. If both tools own --profile-dir, put the wrapper’s options before the first -- and the renderer’s options after it.

A successful exit can hide a lost flag. Inspect the argument list at the boundary.
Watch the flag disappear
Save this as probe.py. It doesn't launch a subprocess. It prints what the wrapper would keep and what it would send on.
import argparse
p = argparse.ArgumentParser()
p.add_argument(
"--profile-dir",
default="profiles",
)
incoming = [
"--profile", "release"
]
parse = p.parse_known_args
options, forwarded = parse(
incoming
)
print(
"wrapper profile dir:",
options.profile_dir,
)
print("forwarded:", forwarded)
Running it on Python 3.12 gives:
wrapper profile dir: release
forwarded: []

With abbreviations on, the wrapper claims both tokens.
The wrapper knows exactly one long option beginning with --profile, so it treats the shorter spelling as --profile-dir and consumes the next token as its value. parse_known_args() classifies a flag as known after interpreting it, not by comparing exactly what the caller typed.
A shell log can show the original command perfectly while telling you nothing about what the renderer received. To reproduce the issue, print the wrapper’s parsed value and the child’s argument list with harmless test inputs. Avoid dumping full production arguments, which can contain credentials or private paths.
Turn off abbreviations if the names don't overlap
Change the constructor in probe.py:
p = argparse.ArgumentParser(
allow_abbrev=False,
)
The same input now prints:
wrapper profile dir: profiles
forwarded: ['--profile', 'release']
For a small wrapper with genuinely distinct long flags, that may be all you need. It also means someone who uses an abbreviated wrapper option must now write its full name.
The fix has a limit. Change the probe's input to ["--profile-dir", "templates"] and the wrapper still consumes both tokens. Both programs can have a good reason to use that exact name: the wrapper might read local presets from one directory, while the renderer reads layout templates from another. An abbreviation setting can't tell which one the caller meant.
There's a second trade-off. A typo such as --proflie-dir may go straight into the forwarded list. At that point you are relying on the downstream command to reject a flag that the wrapper was supposed to validate.

Exact matching fixes a prefix collision. It cannot assign an identical option to the right program.
Use the first -- to give each program its own flags
When both tools own the flag, give the wrapper only the tokens on the left. The following commands use POSIX shell line continuations; paste them as shown or put each command on one line.
python wrapper.py \
--profile-dir local -- \
--profile release \
--profile-dir templates
The wrapper gets --profile-dir local. The renderer gets --profile release --profile-dir templates. Those two directory values can now coexist without renaming either option.

The first separator assigns the two values before argparse parses either side.
Save this as wrapper.py:
import argparse
from pathlib import Path
import subprocess
import sys
cli = argparse.ArgumentParser(
allow_abbrev=False,
usage=(
"%(prog)s [wrapper opts]"
" -- [renderer arguments]"
),
)
cli.add_argument(
"--profile-dir",
default="profiles",
)
args = sys.argv[1:]
if args in (["-h"], ["--help"]):
cli.parse_args(args)
if "--" not in args:
cli.error(
"put renderer arguments"
" after --"
)
boundary = args.index("--")
left = args[:boundary]
wrapper = cli.parse_args(left)
forwarded = args[boundary + 1:]
print(
"wrapper profile dir:",
wrapper.profile_dir,
flush=True,
)
here = Path(__file__)
renderer = here.with_name(
"renderer.py"
)
child = [
sys.executable,
str(renderer),
*forwarded,
]
run = subprocess.run(child)
raise SystemExit(run.returncode)
Save this small stand-in beside it as renderer.py:
import argparse
cli = argparse.ArgumentParser(
allow_abbrev=False,
)
cli.add_argument(
"--profile",
default="default",
)
cli.add_argument(
"--profile-dir",
default="built-in",
)
cli.add_argument(
"report", nargs="?"
)
args = cli.parse_args()
print("render profile:",
args.profile)
print("profile dir:",
args.profile_dir)
print(f"report={args.report!r}")
The example command now prints:
wrapper profile dir: local
render profile: release
profile dir: templates
report=None

After splitting, the wrapper and renderer have different values for the same option name.
The split happens before the wrapper parses anything. The wrapper parses the left side with parse_args() so typos there stop at the right program. It sends the right side as a list, not as a new shell command. A quoted filename such as "weekly report.md" stays one argument instead of being broken into two words.
The first -- belongs to the wrapper. In the probe on Python 3.12 and 3.13, parse_known_args() returns both tokens in ["--", "--profile=release"] as extras. Pass them through unchanged and the renderer accepts --profile=release as a filename. It exits 0 with the default profile.
For a render with no options, run python wrapper.py --. For a filename that begins with a dash, use two markers: the first separates the programs; the second tells the renderer to stop parsing options.
python wrapper.py -- \
--profile release -- \
--weekly.md
The renderer prints report='--weekly.md'. If the wrapper removed both markers, the renderer would try to parse that filename as an option.

Consume the first marker and pass the second one to the renderer.
Check what happens when the wrapper grows
There is another way the bug surfaces: a command that quietly did the wrong thing can start failing after a wrapper update.
In the original probe, add p.add_argument("--profile-cache") just before the parse_known_args() call. Run the unchanged example with the default constructor. Python 3.12 prints an ambiguity error: --profile could abbreviate either --profile-dir or --profile-cache. With allow_abbrev=False, the same input still reaches the renderer. No caller or renderer changed; only the wrapper gained a new option.
You may see users write --profile=release instead of two tokens. That spelling won't fix the prefix collision. On this example the permissive wrapper recognizes the same abbreviated option and keeps the attached value. On the explicit interface, python wrapper.py -- --profile=release passes one token, and the renderer parses it as the requested profile. That is another case worth keeping in a test suite if your examples use both spellings.

Adding a second matching option can turn yesterday’s silent loss into today’s error.
Give each program a help route
Try these two commands after you save the example files:
python wrapper.py --help
python wrapper.py -- --help
The first prints the wrapper's usage. The second asks the renderer for its flags. If you put both usages in a README, label which command owns which help screen. A user who copies a renderer option from that screen now knows it goes after the separator.

One help command stops at the wrapper. The other crosses the separator.
The wrapper in this example also prints its chosen directory before launching the renderer. That extra line is useful while debugging. If a real caller reads the renderer's stdout as JSON, move the wrapper's status message to stderr or take it out. Otherwise, fixing argument routing can reveal a second problem: the right renderer now runs, but the caller gets a status line before its JSON.
A short test list for a real release script
Test the argument list the renderer actually receives. The probe exited 0 with an empty forwarded list. In the wrapper test with abbreviations enabled, the renderer ran with its default profile.
-
Same option on both sides: Set
--profile-dir localfor the wrapper and--profile-dir templatesfor the renderer. Assert both values rather than checking only status 0. -
Flag on the wrong side: Put
--profile releasebefore the first--. The wrapper should reject the option without launching the renderer. -
Typo on the renderer side: Run
python wrapper.py -- --profil nightly. The renderer’s error should identify its own command and the wrapper should return status 2. -
One path with a space: Put
"weekly report.md"after the first separator. The renderer should receive one filename. - A filename beginning with a dash: Run the two-marker command above. Both the marker and the filename must reach the renderer intact.

Verify ownership, the child error, and the boundaries around filenames.
An explicit boundary is a change to the public command line. I would not quietly introduce it in a wrapper that already has dozens of callers. If your wrapper owns a handful of names and those names cannot overlap the tool it starts, allow_abbrev=False is the smaller fix. Test both the split and the attached-value spellings. If both programs legitimately own the same option, start with one real invocation in CI, show the separator next to it in the README, and change the rest of the callers together. The success check is what the renderer actually did, not whether the wrapper printed a zero exit status.
AI disclosure: AI drafted this article and produced the diagrams. The terminal excerpts come from the tested Python examples.
Top comments (0)