One function

extract_files_from_bash in severity1/claude-code-auto-memory

The author described this change as Fix bash command parsing to stop at shell operators. It counts as a record because the check below fails on the code as it stood at 2b76c8e93 and passes on 45ff2fb6d, with nothing else changed between the two runs.

Fix saved2025-11-29
Sharing licenceMIT · LICENSE
Change size+14 2

What the code was meant to do, written into the code itself as a docstring

Extract file paths from Bash commands that modify files. Detects: rm, rm -rf, mv, git rm, git mv, unlink Returns list of file paths that should be tracked.

The change

2424 if command.startswith(skip_prefixes):
2525 return []
2626
27+ # Shell operators that chain commands - stop parsing at these
28+ shell_operators = ("&&", "||", ";", "|", ">", ">>", "<", "2>", "2>&1")
29+
2730 files = []
2831
2932 try:
3639
3740 # Handle: rm, rm -rf, rm -f, etc.
3841 if cmd == "rm":
39- # Skip flags, collect file arguments
42+ # Skip flags, collect file arguments until shell operator
4043 for token in tokens[1:]:
44+ if token in shell_operators:
45+ break # Stop at command chaining operator
4146 if not token.startswith("-"):
4247 files.append(token)
4348
4449 # Handle: git rm
4550 elif cmd == "git" and len(tokens) > 1 and tokens[1] == "rm":
4651 for token in tokens[2:]:
52+ if token in shell_operators:
53+ break
4754 if not token.startswith("-"):
4855 files.append(token)
4956
5158 elif cmd == "mv" and len(tokens) >= 3:
5259 # Skip flags, get first non-flag arg (source)
5360 for token in tokens[1:]:
61+ if token in shell_operators:
62+ break
5463 if not token.startswith("-"):
5564 files.append(token)
5665 break # Only track source, not destination
5867 # Handle: git mv (track source file only)
5968 elif cmd == "git" and len(tokens) > 2 and tokens[1] == "mv":
6069 for token in tokens[2:]:
70+ if token in shell_operators:
71+ break
6172 if not token.startswith("-"):
6273 files.append(token)
6374 break
6475
6576 # Handle: unlink
6677 elif cmd == "unlink" and len(tokens) > 1:
67- files.append(tokens[1])
78+ if tokens[1] not in shell_operators:
79+ files.append(tokens[1])
6880
6981 except ValueError:
7082 # shlex.split failed (unbalanced quotes, etc.) - skip

The check that tells the two apart

failpass·tests/test_hooks.py::TestPostToolUseHook::test_stops_at_shell_operators

Check file tests/test_hooks.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it2b76c8e9306663f3ac1119c1723821d142da7f92
Broken version dated2025-11-29
Modulescripts.post-tool-use
Units changedextract_files_from_bash
Fingerprintc304ae845892b914
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.