Add comprehensive documentation for Claude Code hooks and streaming input modes

- Introduced a detailed reference for implementing hooks in Claude Code, covering configuration, project-specific scripts, plugin hooks, and various hook events.
- Explained the input modes available in the Claude Agent SDK, emphasizing the benefits of streaming input mode and providing implementation examples for both streaming and single message input.
- Highlighted security considerations and best practices for writing hooks, along with debugging tips and execution details.
This commit is contained in:
Alex Newman
2025-10-15 15:51:25 -04:00
parent 2663121d9f
commit 7fac3e3bb6
9 changed files with 2487 additions and 16 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
#!/usr/bin/env node
#!/usr/bin/env bun
/**
* Post Tool Use Hook - Streaming SDK Version
+5 -7
View File
@@ -1,4 +1,4 @@
#!/usr/bin/env node
#!/usr/bin/env bun
/**
* Session Start Hook (SDK Version)
@@ -36,14 +36,12 @@ process.stdin.on('end', async () => {
const result = await executeCliCommand('claude-mem', ['load-context', '--format', 'session-start']);
if (result.success && result.stdout) {
// Use the CLI output directly as context (it's already formatted)
const response = createHookResponse('SessionStart', true, {
context: result.stdout
});
console.log(JSON.stringify(response));
// Per Claude Code docs: for SessionStart, stdout with exit code 0 is added to context
// Use plain stdout instead of JSON to ensure it appears in Claude's context
console.log(result.stdout);
process.exit(0);
} else {
// Return without context
// Return without context - use JSON with suppressOutput to avoid empty context
const response = createHookResponse('SessionStart', true);
console.log(JSON.stringify(response));
process.exit(0);
+1 -1
View File
@@ -1,4 +1,4 @@
#!/usr/bin/env node
#!/usr/bin/env bun
/**
* Hook Helper Functions
+1 -1
View File
@@ -1,4 +1,4 @@
#!/usr/bin/env node
#!/usr/bin/env bun
/**
* Stop Hook - Simple Orchestrator
+1 -1
View File
@@ -1,4 +1,4 @@
#!/usr/bin/env node
#!/usr/bin/env bun
/**
* User Prompt Submit Hook - Streaming SDK Version