-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Task: Implement hook-based logging system
Description
Create pre_tool_use.sh hook script that logs all tool usage events to structured NDJSON format for observability without affecting command behavior.
Acceptance Criteria
- Hook script logs to
.claude/logs/hooks.ndjson - NDJSON format with required fields: timestamp, tool_name, command, working_directory
- Hook triggers on PreToolUse events in Claude Code
- Zero impact on command execution time and behavior
- Creates
.claude/logs/directory if it doesn't exist - Handles log file permissions appropriately
- Graceful failure if logging cannot be performed (no command impact)
- Log entries are properly formatted JSON lines
- Timestamps use ISO 8601 UTC format
Technical Details
Implementation approach:
- Create shell script that receives tool usage parameters
- Format data as JSON and append to NDJSON log file
- Use file locking for concurrent write safety
- Minimal processing to ensure zero performance impact
Key considerations:
- Must not fail or slow down any command execution
- Atomic writes to prevent log file corruption
- Proper JSON escaping of command arguments and paths
- Efficient file operations for high-frequency logging
Code locations/files affected:
- Create:
.claude/hooks/pre_tool_use.sh - Create:
.claude/logs/directory structure - Create:
.claude/logs/hooks.ndjson(initially empty) - Make executable:
chmod +x .claude/hooks/pre_tool_use.sh
Dependencies
- Understanding of Claude Code hook system
- NDJSON format specification
- Shell JSON formatting capabilities
- File locking mechanisms for concurrent writes
Effort Estimate
- Size: S
- Hours: 1.5 hours
- Parallel: true (but conflicts with task 005 due to settings.json modification)
Definition of Done
- Hook script implemented with proper NDJSON formatting
- Zero performance impact validated through testing
- Concurrent write safety tested with multiple simultaneous tool calls
- Log entries contain all required fields with proper formatting
- Directory and file creation handled gracefully
- Error scenarios tested (permission issues, disk space)
- JSON formatting validated for special characters and edge cases
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels