Skip to main content

Module claude_code

Module claude_code 

Source
Expand description

Claude Code hook adapter.

Claude Code (the official Anthropic CLI) invokes hooks with a JSON object on stdin that looks like:

{
  "session_id": "...",
  "cwd": "/abs/path/to/repo",
  "hook_event_name": "PostToolUse",
  "tool_name": "Edit",
  "tool_input": { "file_path": "src/foo.rs", "old_string": "...", "new_string": "..." },
  "tool_response": { ... },
  "transcript_path": "/abs/path/to/session.jsonl"
}

Not every field is present on every event — SessionStart for instance only carries session_id + cwd. The adapter is permissive on absent fields (returns None / falls through) and strict only on the ones it needs for a given event kind.

The output shape Claude Code expects is:

{
  "continue": true,
  "systemMessage": "optional short string",
  "hookSpecificOutput": { "additionalContext": "optional long string" }
}

We camelCase the JSON keys on output (matching Claude Code’s convention) while keeping our internal HookResult snake_case.

Structs§

ClaudeCodeAdapter
Zero-sized marker type. The adapter holds no state — every invocation is a pure stdin-in, stdout-out transformation.