From e5440e31af136e958ba685fe54da5cb5f0d75f29 Mon Sep 17 00:00:00 2001 From: Luna Mira Date: Thu, 9 Apr 2026 13:33:45 +0100 Subject: [PATCH] fix: count Codex user_message turns in _count_human_messages (#347) The _count_human_messages() function previously only handled Claude Code transcript format: {"message": {"role": "user", "content": "..."}} Codex CLI transcripts use a different schema: {"type": "event_msg", "payload": {"type": "user_message", "message": "..."}} This meant the stop-hook auto-save threshold never triggered for Codex sessions because the count always returned 0. Added detection for the Codex format so both Claude Code and Codex CLI transcripts are counted correctly. --- mempalace/hooks_cli.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mempalace/hooks_cli.py b/mempalace/hooks_cli.py index fe6e4eb..d9408ac 100644 --- a/mempalace/hooks_cli.py +++ b/mempalace/hooks_cli.py @@ -63,6 +63,14 @@ def _count_human_messages(transcript_path: str) -> int: if "" in text: continue count += 1 + # Also handle Codex CLI transcript format + # {"type": "event_msg", "payload": {"type": "user_message", "message": "..."}} + elif entry.get("type") == "event_msg": + payload = entry.get("payload", {}) + if isinstance(payload, dict) and payload.get("type") == "user_message": + msg_text = payload.get("message", "") + if isinstance(msg_text, str) and "" not in msg_text: + count += 1 except (json.JSONDecodeError, AttributeError): pass except OSError: