Product case study · November 26, 2026
Ask Claude Code why every checklist gets the same item
Diagnose Python dict.fromkeys sharing one list across several keys. Give Claude Code a bounded repair task and verify independent checklists with fixed tests.

An empty list under every key can hide one shared object. Test a mutation before trusting the initializer.
You add “check captions” to the video checklist. The article and newsletter checklists acquire it too. Nothing crashed, and the initial dictionary looked correct: three names, three empty lists.
Use this small failure to practice giving Claude Code a repair it can prove. The important question is whether changing one checklist changes another, so the acceptance tests must actually add an item.
You need Bash, Python 3, and installed, signed-in Claude Code. The Python baseline and reference repair below were tested locally. The agent prompt is an authored exercise, not a recorded Claude session. Official sources were checked November 26, 2026.
Reproduce the shared checklist
Create a disposable folder and a deliberately broken helper:
checklist_lab=$(mktemp -d /tmp/claude-checklists.XXXXXX)
cd "$checklist_lab"
cat > checklists.py <<'PY'
def make_checklists(names):
return dict.fromkeys(names, [])
if __name__ == "__main__":
tasks = make_checklists(["video", "article", "newsletter"])
tasks["video"].append("check captions")
print(tasks)
PY
python3 checklists.py
The broken demo prints:
{'video': ['check captions'], 'article': ['check captions'], 'newsletter': ['check captions']}
The [] argument creates one list. fromkeys assigns that same object to every key; it does not call a list factory for each name. Python’s dictionary reference explicitly documents this behavior and recommends a dictionary comprehension when the values need to be distinct.
This happens inside a single call. The existing nested configuration copy exercise starts with an existing object and copies too little; here the initializer creates the sharing in the first place.
Specify what the initializer must return
Save this as SPEC.md:
make_checklists(names) receives a list of distinct string names.
Return a plain dictionary with exactly those keys, in input order.
Each key starts with an empty, independently mutable list.
Appending or clearing one checklist must not change another.
Separate calls must also produce independent checklists.
Do not modify the input names. An empty input returns {}.
Duplicate names and non-string names are outside this exercise.
Only checklists.py may change; preserve its demo.
Do not add dependencies, storage, a UI, or external services.
Save these four tests as test_checklists.py:
import unittest
from checklists import make_checklists
class ChecklistTests(unittest.TestCase):
def test_initial_shape_and_input(self):
names = ["video", "article", "newsletter"]
result = make_checklists(names)
self.assertIs(type(result), dict)
self.assertEqual(list(result), names)
self.assertEqual(result, {"video": [], "article": [], "newsletter": []})
self.assertEqual(names, ["video", "article", "newsletter"])
def test_edits_stay_with_their_owner(self):
result = make_checklists(["video", "article", "newsletter"])
result["video"].append("check captions")
self.assertEqual(result["article"], [])
self.assertEqual(result["newsletter"], [])
result["article"].append("verify sources")
result["video"].clear()
self.assertEqual(result["article"], ["verify sources"])
self.assertEqual(result["newsletter"], [])
def test_separate_calls_are_independent(self):
first = make_checklists(["video"])
second = make_checklists(["video"])
first["video"].append("first only")
self.assertEqual(second["video"], [])
def test_empty_input(self):
self.assertEqual(make_checklists([]), {})
Run:
python3 -m unittest -v test_checklists
In the local baseline, three tests passed and test_edits_stay_with_their_owner failed. Even the separate-calls test passed: the broken helper creates a fresh list on each call, then shares it among that call’s keys. Testing only two separate calls misses the actual failure.
The unittest documentation describes this command and verbose test reporting. Keep the tests unchanged while the agent repairs the helper.
Ask Claude Code for the smallest repair
Start claude in the practice folder and paste:
Read SPEC.md, checklists.py and test_checklists.py.
Run python3 -m unittest -v test_checklists and report the baseline.
Explain why one append appears under multiple keys, while the
separate-calls test still passes.
Change only checklists.py to satisfy SPEC.md and the unchanged tests.
Preserve the demo. Do not edit tests, install packages, delegate,
commit, or access other folders.
Run the same tests and python3 checklists.py after the repair.
Report the actual command results and explain where each list is created.
This uses Anthropic’s debugging workflow: provide reproduction steps, narrow the change, and run checks. The file boundary in a prompt is an instruction, not a filesystem sandbox; review the session’s active permissions and proposed commands.
If Claude changes a test to accept shared contents, put the original test back. If it replaces lists with tuples, it has removed the required ability to append. If it adds a class or persistent task store, bring it back to the small function contract.
Inspect where the new lists are created
This reference repair passed all four tests locally:
def make_checklists(names):
return {name: [] for name in names}
Replace only the function, leaving the demo below it. The list expression now runs for each name. Python’s data structures tutorial describes dictionary comprehensions as a way to build a dictionary from key and value expressions.
A loop assigning a new [] inside each iteration also meets this contract. A loop assigning the same list created before the loop does not. Review object creation, not just whether the syntax looks different.
After leaving Claude, run both commands yourself:
python3 -m unittest -v test_checklists
python3 checklists.py
The repaired demo should print:
{'video': ['check captions'], 'article': [], 'newsletter': []}
If importing checklists fails, run from the folder containing both Python files. If the runner reports zero tests, check the filename and test_ method names. If the output still repeats the item, inspect whether the initializer reuses one list across iterations.
This lab establishes independent empty checklists for distinct names. It does not decide what duplicate names should mean or make concurrent updates safe. Before adapting the helper to a real task system, specify those requirements separately. For this repair, the useful evidence is simple: one checklist changes, and the others stay empty.
Sources
Checked November 26, 2026:
- Python dictionary methods — shared values in
fromkeys. - Python data structures tutorial — dictionary comprehensions.
- Python unittest — command-line test execution.
- Claude Code common workflows — reproducing bugs and verifying focused repairs.
Put this to work
Why dict.fromkeys with a list creates shared mutable state.
Try
Repair a checklist initializer in a disposable Python practice folder.
Prove it worked
Run four unchanged tests before and after the repair.
Keep in view
- Reproduce one append appearing under three dictionary keys.
- Give Claude Code a precise independence contract and fixed tests.
- Verify edits within one result as well as across separate calls.