HookStackGitHub
Back to catalogue
WorkflowInstructionsLoaded

Audit log for CLAUDE.md file loads

Records every CLAUDE.md and .claude/rules/*.md file loaded into context to a timestamped audit log. Captures the file path, memory scope (User/Project/Local/Managed) and load reason, providing full traceability of which instructions governed each session.

Use cases

  • Audit which CLAUDE.md files were active during a session for compliance reviews
  • Debug unexpected model behaviour by reviewing which instruction files were loaded
  • Track lazy-loaded nested CLAUDE.md files in monorepos for instruction coverage

Providers & tags

Claude Code
#audit#claude-md#instructions#compliance#traceability

settings.json fragment

{
  "hooks": {
    "InstructionsLoaded": [
      {
        "hooks": [
          {
            "command": "node $CLAUDE_PROJECT_DIR/.claude/hooks/instructions-loaded-audit-log.mjs",
            "type": "command"
          }
        ]
      }
    ]
  }
}

Script · .claude/hooks/instructions-loaded-audit-log.mjs

#!/usr/bin/env node
// Journalise le chargement d'instructions / mémoire (InstructionsLoaded)
import { readFileSync, appendFileSync, mkdirSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';

export function run(
  input,
  {
    append = appendFileSync,
    mkdir = mkdirSync,
    projectDir = process.env.CLAUDE_PROJECT_DIR ?? '.',
    now = () => new Date().toISOString(),
  } = {},
) {
  const logPath = join(projectDir, '.claude', 'instructions-audit.log');
  try { mkdir(dirname(logPath), { recursive: true }); } catch { /* exists */ }

  const line = `${now()} | ${input.memory_type} | ${input.load_reason} | ${input.file_path}\n`;
  append(logPath, line);
  return line;
}

/* v8 ignore next 4 */
if (process.argv[1] === fileURLToPath(import.meta.url)) {
  const input = JSON.parse(readFileSync(0, 'utf8'));
  run(input);
}