Skip to content

AI

SANS adds two forensic scripts to trace AI coding assistant activity

The Python scripts opencode-chat-replay.py and hermes_forensic_extract.py require Python 3.10+, use only the standard library, and support time‑range filtering.

https://breach-signal.com/artificial-intelligence/sans-adds-forensic-scripts-ai-coding-assistants/

Share

Key facts

  • The opencode-chat-replay.py script reconstructs session transcripts from OpenCode's SQLite database by default located at ~/.local/share/opencode/opencode.db.
  • The hermes_forensic_extract.py script collects evidence from ~/.hermes/state.db, ~/.hermes/sessions/request_dump_*.json, and ~/.hermes/logs/*.log.
  • Both scripts support time range filtering with –start and –end (in YYYY-mm-dd [HH[:MM[:SS]]] format) and can target a specific file or directory for analysis.
  • The Hermes script outputs newline-delimited JSON (JSONL) where each record includes an _extraction_type field indicating its source (session, message, model_usage, request_dump, or log_entry).

On October 8, 2026, the SANS Internet Storm Center updated the FOR577 course to add day-5 material that focuses on investigating AI usage during incident response. As part of that update, the SANS Internet Storm Center placed two new Python scripts—opencode-chat-replay.py and hermes_forensic_extract.py— in a public GitHub repository for examining records from the OpenCode and Hermes agents.

Both scripts require Python version 3.10 or later to run. They rely exclusively on the Python standard library, so no third‑party packages need to be installed. Users can limit analysis to a specific period with the –start and –end options, which accept timestamps in YYYY-mm-dd [HH[:MM[:SS]]] format. The scripts can also be directed at a single file or an entire directory for examination.

The tools are forensic review utilities; they do not execute or replay any actions performed by the AI coding assistants. Instead, they make the recorded interactions readable for investigators by showing what the user asked, what the assistant returned, and any captured tool activity.

The opencode-chat-replay.py script reconstructs session transcripts from OpenCode’s SQLite database. By default, it looks for the database at ~/.local/share/opencode/opencode.db. It can work with both the older separate message/part tables and the newer consolidated session_message storage, preferring the consolidated format when it exists. When run without extra arguments the script outputs a Markdown transcript that is straightforward to read, but analysts can also request JSON or JSONL output for structured analysis, with each turn embedding session metadata.

The hermes_forensic_extract.py script gathers evidence from three locations within the Hermes artifact set. It reads the state database at ~/.hermes/state.db. It also processes JSON request dump files found under ~/.hermes/sessions/request_dump_*.json. Finally, it scans log files stored in ~/.hermes/logs/*.log.

The output of the Hermes script is newline‑delimited JSON (JSONL). Each JSONL record contains an _extraction_type field that identifies its source as session, message, model_usage, request_dump or log_entry.

To protect the integrity of the original evidence, the opencode script copies the SQLite database together with its -wal and -shm journal files to a temporary directory before querying. The Hermes script, by contrast, opens its state.db file in read‑only mode, ensuring that no one modifies the file.

Because the scripts reside in a public GitHub repository, investigators can get them by cloning that repository. The ability to filter by time range and to target specific files or directories makes the scripts adaptable to different logging layouts and retention policies. Output in Markdown provides a quick narrative view, while JSON or JSONL enables further processing with tools such as jq or integration into SIEM pipelines.

The FOR577 update discusses eight popular AI coding assistants and agents that analysts may encounter in enterprise environments. Those assistants are Claude Code, Codex, Gemini CLI, Cursor, Copilot, Warp, Windsurf and Qwen Code.

Was this helpful?

Join the discussion

Please read our Comment Policy before commenting. First-time comments are held for moderation. By posting a comment you agree to our Terms of Use and Privacy Policy, which explain how your name, email address and comment are used.

Your email address will not be published. Required fields are marked *