Product case study · December 1, 2026

Ask Claude Code to stop an INI importer changing key names

Reproduce Python ConfigParser lowercasing INI keys, give Claude Code a bounded repair task, and verify exact spelling with six regression tests.

Reading time
6 min
Checked
Dec 1, 2026
Two distinct paper keys pass through a charcoal frame toward matching slots on evidence cards.
Keep each key's identity through the import.
Bottom line

Decide whether key spelling is part of the contract before asking an agent to normalize configuration.

Your settings file says BuildTarget. The imported dictionary says buildtarget. A downstream template asks for the original name and cannot find it, even though the value survived.

This is a useful small repair to give Claude Code: preserve the names at the boundary where they enter your application. First make the contract explicit. In this exercise, BuildTarget and buildtarget are different keys. That is a choice for this adapter, not a rule every INI application should adopt.

Verification scope: the Python baseline and reference repair below were run locally. The Claude Code prompt is a suggested workflow; we did not run an agent session or measure its success rate. You need Python 3 and an installed, authenticated Claude Code CLI for the agent step. The Python lab uses only the standard library.

Reproduce the changed name

In a Bash-compatible terminal, create a fresh practice directory:

ini_lab=$(mktemp -d /tmp/claude-ini-case.XXXXXX)
cd "$ini_lab"
cat > settings_reader.py <<'PY'
import configparser


def read_settings(text):
    parser = configparser.ConfigParser(interpolation=None)
    parser.read_string(text)
    return dict(parser["settings"])
PY
python3 - <<'PY'
from settings_reader import read_settings
print(read_settings("[settings]\nBuildTarget = preview\n"))
PY

The baseline prints {'buildtarget': 'preview'}. Our adapter needs {'BuildTarget': 'preview'}.

Python documents that ConfigParser’s option-name transformation lowercases names by default. Setting optionxform to str preserves their case. Set it before reading; changing it after parsing cannot recover spelling already lost.

The lab already disables interpolation because its values are literal strings. Leave that behavior in place. Use only the fictional inputs below, not production settings or credentials.

Freeze the contract in six tests

Save this as test_settings_reader.py beside the importer:

import configparser
import unittest
from settings_reader import read_settings


class SettingsTests(unittest.TestCase):
    def test_preserves_mixed_case(self):
        self.assertEqual(
            read_settings("[settings]\nBuildTarget = preview\n"),
            {"BuildTarget": "preview"},
        )

    def test_case_distinct_names_are_distinct(self):
        self.assertEqual(
            read_settings("[settings]\nMode = blue\nmode = green\n"),
            {"Mode": "blue", "mode": "green"},
        )

    def test_exact_duplicate_is_rejected(self):
        with self.assertRaises(configparser.DuplicateOptionError):
            read_settings("[settings]\nMode = blue\nMode = green\n")

    def test_literal_percent_value(self):
        self.assertEqual(
            read_settings("[settings]\nprogress = 75%\n"),
            {"progress": "75%"},
        )

    def test_empty_section(self):
        self.assertEqual(read_settings("[settings]\n"), {})

    def test_missing_section_is_rejected(self):
        with self.assertRaises(KeyError):
            read_settings("[other]\nmode = preview\n")

Run:

python3 -m unittest -v test_settings_reader

The baseline produces one failure, one error and four passes. The mixed-case test fails on dictionary equality. The case-distinct test errors while parsing because the two names collapse to the same normalized key. Keep that distinction in your notes: one input returns the wrong output; another never returns a dictionary.

The unittest documentation explains the runner. Here, assertEqual checks the full returned mapping, and assertRaises checks the intended exception type. These tests describe our adapter’s obligations, including behavior that the repair must preserve.

Give Claude Code a narrow repair task

Start claude from the practice directory. If setup is unfamiliar, use the Claude Code project lesson first. Check the displayed working directory and active permissions before submitting this prompt:

Read settings_reader.py and test_settings_reader.py in this practice folder.
Run python3 -m unittest -v test_settings_reader and report the baseline.

Fix only settings_reader.py. Preserve exact option-name case in the returned
settings dictionary. Mode and mode must remain separate keys. Keep rejection
of exact duplicate keys, literal percent values, empty-section behavior,
and the missing-section error.

Do not edit the tests, add dependencies, access other directories, or change
external services. Explain where the name transformation happens and why
your change belongs before parsing. Then run the unchanged tests again.
Report the command, actual results, and the exact code change. If a command
cannot run, report that limitation instead of calling the repair verified.

This follows Anthropic’s advice to give Claude a check to run. The fixed tests let you review its output against your requirements. A prompt expresses scope; it does not replace the CLI’s permission controls.

Watch for a repair that uppercases every key or changes the expected dictionaries. Either would make a different contract easier to satisfy. Reject that change and repeat the requirement to preserve the input spelling.

Compare the repair with a reference

After trying the agent task, compare its change with this reference implementation:

import configparser


def read_settings(text):
    parser = configparser.ConfigParser(interpolation=None)
    parser.optionxform = str
    parser.read_string(text)
    return dict(parser["settings"])

The assignment uses the callable str, not str(). With the reference repair, the same command passes all six tests. Run it yourself even if the agent already reports success.

The default strict parser still rejects an exact duplicate within this single input. Case-distinct names now remain distinct. Python documents strict parsing and duplicate options separately from name transformation; disabling strict mode is not the repair this lab asks for.

For a handoff, keep the failing baseline, passing output, Python version from python3 --version, and the one-line change together. The evidence should make it possible for someone else to repeat the check without trusting the conversation summary.

Recover when the result is wrong

ObservationNext check
Keys are still lowercaseConfirm the assignment is before read_string, then restart the test command.
A callable error appearsCheck for str() instead of str in the assignment.
Duplicate input is silently acceptedLook for an added strict=False; restore duplicate rejection.
The percent-value test errorsCheck whether the repair removed interpolation=None.
Tests cannot import the moduleRun from the practice directory and check the two filenames.

Keep the scope of the conclusion small. This fixture has no DEFAULT entries, includes one named section, and returns a dictionary. It does not test file writing, comment preservation, layered configuration, or whether another application treats names case-insensitively. Before applying the repair to a real importer, decide its key-name contract with the consuming application and add a representative fixture.

Sources and checked date

Official documentation checked December 1, 2026:

  • Python ConfigParser: option-name transformation, case sensitivity, strict duplicate handling and interpolation controls.
  • Python unittest: command-line execution, equality checks and exception assertions.
  • Claude Code best practices: giving the agent concrete verification criteria and reviewing against a specification.

The sample configuration, acceptance tests and reference implementation are this tutorial’s lab material. Local test results establish the Python behavior shown here; they do not promise that an agent will produce the same repair on its first attempt.

Put this to work

Where ConfigParser transforms option names and why the timing of the fix matters.

Try

Repair a small INI-to-dictionary adapter using fictional settings.

Prove it worked

Run the same six tests before and after the change and inspect exact output keys.

Keep in view

  • Reproduce an importer that changes mixed-case keys without warning.
  • Give Claude Code six fixed checks and a one-file repair boundary.
  • Keep case-distinct names while rejecting exact duplicate keys.
Learn the workflow: Start a scoped Claude Code session