Product case study · November 18, 2026

Ask Claude Code why --dry-run False still means true

Reproduce a misleading Python boolean option, give Claude Code an explicit CLI contract, and verify accepted and rejected arguments with local tests.

Reading time
6 min
Checked
Nov 18, 2026
A paper toggle routes a blank evidence card toward a preview tray beside a closed output box.
A flag needs a clear contract for both its presence and its absence.
Bottom line

Decide which command spellings your interface accepts before asking an agent to repair its boolean parser.

You pass --dry-run False and the program prints True. The spelling looks unambiguous to a person. To Python’s bool(), it is just a nonempty string.

This lab gives Claude Code a small but consequential interface decision: repair the parser to accept a flag with no value, while rejecting the old misleading spelling. You will check both what the program accepts and what it refuses. The demo only prints a boolean; it never writes application data, sends requests or performs a deployment.

Bring Bash on macOS, Linux or WSL, Python 3, and an installed, signed-in Claude Code. The Python reproduction and reference repair below were tested locally. The Claude prompt is an authored exercise, not a recorded agent run. Official sources were checked November 18, 2026.

Reproduce the misleading option

Create an isolated practice folder:

flag_lab=$(mktemp -d /tmp/claude-boolean-flag.XXXXXX)
cd "$flag_lab"
cat > preview.py <<'PY'
import argparse


def parse_args(argv=None):
    parser = argparse.ArgumentParser(allow_abbrev=False)
    parser.add_argument("--dry-run", type=bool, default=False)
    return parser.parse_args(argv)


if __name__ == "__main__":
    print(parse_args().dry_run)
PY
python3 preview.py --dry-run False

The local result was True. Try the conversion without any command-line parser:

python3 - <<'PY'
print(bool("False"))
print(bool("0"))
print(bool(""))
PY

This prints True, True, then False. Python’s truth-value rules distinguish empty strings from nonempty strings. They do not interpret English boolean words. The argparse type reference specifically warns against using bool as a converter.

A prompt saying only “make False work” leaves an important question unanswered: should this CLI accept a value at all?

Choose the command spellings first

For this exercise, save the following as SPEC.md:

preview.py is a demonstration parser with no external effects.
Keep parse_args(argv=None) and return a Namespace with dry_run.
No arguments: dry_run is the boolean False.
--dry-run alone: dry_run is the boolean True.
Reject --dry-run False, --dry-run true and --dry-run=0 with exit code 2.
Do not accept positional arguments or abbreviated options.
Keep the standard --help option.
Use only the Python standard library.
Only preview.py may change; tests and this specification must stay fixed.

This deliberately changes the interface from an option taking a value to a presence-only flag. In a real project, search scripts, documentation and scheduled jobs for callers before making that change. A caller using the old spelling will need an update. Do not silently impose this exercise’s contract on an existing tool.

The contract is small enough to inspect as a table:

ArgumentsRequired result
No argumentsFalse
--dry-runTrue
--dry-run FalseReject, code 2
--dry-run trueReject, code 2
--dry-run=0Reject, code 2

The absence case is a parser exercise, not a recommendation that real publishing or deletion tools should execute by default. Those tools need their own execution and approval contract.

Lock the acceptance table into tests

Save this as test_preview.py:

import contextlib
import io
import unittest
from preview import parse_args


class FlagTests(unittest.TestCase):
    def test_absent_is_false(self):
        self.assertIs(parse_args([]).dry_run, False)

    def test_present_is_true(self):
        self.assertIs(parse_args(["--dry-run"]).dry_run, True)

    def assert_rejected(self, argv):
        with contextlib.redirect_stderr(io.StringIO()):
            with self.assertRaises(SystemExit) as caught:
                parse_args(argv)
        self.assertEqual(caught.exception.code, 2)

    def test_reject_false_value(self):
        self.assert_rejected(["--dry-run", "False"])

    def test_reject_true_value(self):
        self.assert_rejected(["--dry-run", "true"])

    def test_reject_equals_zero(self):
        self.assert_rejected(["--dry-run=0"])

    def test_reject_abbreviation(self):
        self.assert_rejected(["--dry"])

    def test_help_still_works(self):
        output = io.StringIO()
        with contextlib.redirect_stdout(output):
            with self.assertRaises(SystemExit) as caught:
                parse_args(["--help"])
        self.assertEqual(caught.exception.code, 0)
        self.assertIn("--dry-run", output.getvalue())

Run the baseline:

python3 -m unittest -v test_preview

Locally, seven tests ran: three failed and one errored. The broken parser accepts the three forbidden value spellings, while the bare flag raises an error because it expects a value. The absent, abbreviation and help checks pass. The unittest documentation explains named-module runs, assertions and exception checks.

Checking exit codes rather than exact error wording keeps the exercise independent of cosmetic changes to Python’s diagnostics. The tests also distinguish real booleans from strings that merely look like booleans.

Ask Claude to repair only the parser

Start claude inside the practice folder and paste:

Read SPEC.md, preview.py and test_preview.py.
Run python3 -m unittest -v test_preview and report the actual baseline.
Explain why the string False becomes True in the current parser.
Change only preview.py to satisfy the contract.
Do not edit the tests, install packages, commit or delegate.
Run the same tests after the change and report their result.
Explain whether this changes the accepted command-line syntax.
Do not claim a real dry-run execution path was tested: this program only parses.

Anthropic’s common workflows recommends supplying a reproduction when debugging and verifying the repair. Review tool permissions for the practice folder; a prompt’s scope is not a filesystem sandbox.

If the agent proposes a custom converter that recognizes "false", point it back to the table. Such a converter might suit a different interface, but this one must reject value arguments. Accepting more spellings is not automatically a better repair.

Inspect the small change and rerun independently

The reference repair replaces one argument definition:

parser.add_argument("--dry-run", action="store_true")

Keep the rest of preview.py unchanged. store_true makes presence set the boolean to true and defaults to false when omitted; see the argparse actions reference. The repaired version passed all seven tests locally.

Exit Claude, inspect the file and run:

python3 -m unittest -v test_preview
python3 preview.py
python3 preview.py --dry-run
python3 preview.py --help

The first two direct invocations should print False and True. Inspect help to confirm the option no longer advertises a value placeholder. Run the misleading spelling separately and inspect its status:

python3 preview.py --dry-run False
printf 'exit=%s\n' "$?"

Expect a diagnostic and exit=2. If the tests pass but this command succeeds, check that you ran the same file in the same directory. If the agent edited expected values, restore the published tests in the practice folder and reassess its patch.

You now have evidence that the parser follows the contract. You do not yet have evidence that a real application’s dry-run path avoids writes. When integrating the flag into an application, add a separate test around its write or send boundary. A correct boolean is only the input to that behavior.

Sources

Checked November 18, 2026:

Put this to work

How to turn a confusing command-line option into an explicit interface contract.

Try

Ask Claude Code to repair one parser using a five-case acceptance table.

Prove it worked

Run the same tests before and after the edit, including invalid command spellings.

Keep in view

  • Reproduce a boolean conversion that treats the word False as true.
  • Specify a presence-only flag and reject misleading value arguments.
  • Keep CLI acceptance tests fixed while Claude Code repairs the parser.
Learn the workflow: Set up a scoped Claude Code project session