Answer the principles audit: keep every session file under session/, and stop on a folder the archive cannot read

This commit is contained in:
2026-10-02 17:10:03 +02:00
parent 6ccd5b190f
commit 4620d2e29b
8 changed files with 76 additions and 28 deletions
+6 -2
View File
@@ -35,14 +35,18 @@ def session_open(session: Session) -> bool:
return transcript_file(session) is not None
# <session id>.jsonl, <session id>/subagents/, and from older Claude Code versions <session id>.superseded-1789290815002/ and <session id>.orphaned-*.jsonl
def session_files(transcript: str) -> list[str]:
return sorted(glob.glob(glob.escape(transcript.removesuffix(".jsonl")) + "*"))
def delete_session(session: Session) -> Failure | None:
path = transcript_file(session)
if path is None:
return None
stem = path.removesuffix(".jsonl")
# <session id>.jsonl, <session id>/subagents/, and from older versions <session id>.superseded-1789290815002/ and <session id>.orphaned-*.jsonl
# The transcript goes last: a failed delete leaves a session that session_open still sees, never a new session with this id beside the old one's files.
for sibling in sorted(glob.glob(glob.escape(stem) + "*"), key=lambda sibling: sibling == path):
for sibling in sorted(session_files(path), key=lambda sibling: sibling == path):
try:
shutil.rmtree(sibling) if os.path.isdir(sibling) else os.remove(sibling)
except OSError as failure: