claude_hooks 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 518b315ef2a184008b91029cdb9735b77ceee67490618d9581be16ff0c42cdb2
4
- data.tar.gz: c469281a8f36dce611c1aad3f60611d5951219d1718846739d711fc310219c6f
3
+ metadata.gz: '08b8b23bcfdeed5cf98e3477b6339f29488d6e547fd2fb10ef40947bbc3d45dc'
4
+ data.tar.gz: 20d0f599bac9dcde566829dabba1d1f3f13756181ed4ea7bbe4cfa1c0a95838a
5
5
  SHA512:
6
- metadata.gz: c500ced26412c6666d19cbef211afe43b89dcaa1b6282f6fdeb5ec24874981621d3ef7b742a1c3fc45d9f68c91e838d0c16a6e90fb63c81a6f90facfb0f23e11
7
- data.tar.gz: db4d7cc2ca66d8d6cb7c3582cda5433f2b6882998f600a43cda170f58951246fd5394704b4ce6136c461138160c509d0e5bbec3390530329b754b11aa62911dc
6
+ metadata.gz: 7cd6ecea85c72ce39e77613f68c3dc9f689aca7611dd499482e20538bbb456e2c6b4c23bc791372173fd4b955e8d4211c3c8c29e0e97957812916f901327ce22
7
+ data.tar.gz: 93b6032c1c29c11081419d0415dae8ac5cd2494fa558af1637c081ce11d256403c1b26c49740c9aa8294c385aa311b12da2b3e5a6949e88a4a5f892b68abcf54
data/CHANGELOG.md CHANGED
@@ -5,12 +5,17 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.2.1] - 2025-08-21
9
+
10
+ ### Fixed
11
+ - Fixed name of environment variable for the merge strategy
12
+
8
13
  ## [0.2.0] - 2025-08-21
9
14
 
10
15
  ### Added
11
16
  - **Dual Configuration System**: Support for both home-level (`$HOME/.claude`) and project-level (`$CLAUDE_PROJECT_DIR/.claude`) configurations
12
17
  - **Configuration Merging**: Intelligent merging of home and project configs with configurable precedence
13
- - New environment variable `CLAUDE_HOOKS_CONFIG_MERGE_STRATEGY` to control merge behavior ("project" or "home")
18
+ - New environment variable `RUBY_CLAUDE_HOOKS_CONFIG_MERGE_STRATEGY` to control merge behavior ("project" or "home")
14
19
  - New directory access methods: `home_claude_dir`, `project_claude_dir`
15
20
  - New path utility methods: `home_path_for(path)`, `project_path_for(path)`
16
21
  - Enhanced `path_for(path, base_dir=nil)` method with optional base directory parameter
data/README.md CHANGED
@@ -4,7 +4,7 @@ A Ruby DSL (Domain Specific Language) for creating Claude Code hooks. This will
4
4
 
5
5
  [**Why use this instead of writing bash, or simple ruby scripts?**](WHY.md)
6
6
 
7
- > You might also be interested in my other project, a [Claude Code statusline](https://github.com/gabriel-dehan/claude_monitor_statusline) that shows your Claude usage in realtime ✨.
7
+ > You might also be interested in my other project, a [Claude Code statusline](https://github.com/gabriel-dehan/claude_monitor_statusline) that shows your Claude usage in realtime, inside Claude Code ✨.
8
8
 
9
9
  ## 🚀 Quick Start
10
10
 
@@ -121,11 +121,12 @@ You can configure Claude Hooks through environment variables with the `RUBY_CLAU
121
121
 
122
122
  ```bash
123
123
  # Existing configuration options
124
- export RUBY_CLAUDE_HOOKS_LOG_DIR="logs" # Default: logs (relative to HOME/.claude)
125
- export CLAUDE_HOOKS_CONFIG_MERGE_STRATEGY="project" # Config merge strategy: "project" or "home", default: "project"
126
- export RUBY_CLAUDE_HOOKS_BASE_DIR="~/.claude" # Deprecated: fallback base directory
124
+ export RUBY_CLAUDE_HOOKS_LOG_DIR="logs" # Default: logs (relative to HOME/.claude)
125
+ export RUBY_CLAUDE_HOOKS_CONFIG_MERGE_STRATEGY="project" # Config merge strategy: "project" or "home", default: "project"
126
+ export RUBY_CLAUDE_HOOKS_BASE_DIR="~/.claude" # DEPRECATED: fallback base directory
127
127
 
128
- # Any variable prefixed with RUBY_CLAUDE_HOOKS_ will also be available through the config object
128
+ # Any variable prefixed with RUBY_CLAUDE_HOOKS_
129
+ # will also be available through the config object
129
130
  export RUBY_CLAUDE_HOOKS_API_KEY="your-api-key"
130
131
  export RUBY_CLAUDE_HOOKS_DEBUG_MODE="true"
131
132
  export RUBY_CLAUDE_HOOKS_USER_NAME="Gabriel"
@@ -161,7 +162,7 @@ When both config files exist, they will be merged with configurable precedence:
161
162
  - **Default (`project`)**: Project config values override home config values
162
163
  - **Home precedence (`home`)**: Home config values override project config values
163
164
 
164
- Set merge strategy: `export CLAUDE_HOOKS_CONFIG_MERGE_STRATEGY="home" | "project"` (default: "project")
165
+ Set merge strategy: `export RUBY_CLAUDE_HOOKS_CONFIG_MERGE_STRATEGY="home" | "project"` (default: "project")
165
166
 
166
167
  > [!WARNING]
167
168
  > Environment Variables > Merged Config Files
@@ -8,12 +8,12 @@ class AppendRules < ClaudeHooks::UserPromptSubmit
8
8
  def call
9
9
  log "Executing AppendRules hook"
10
10
 
11
- # Read the rule content
12
- rule_content = read_rule_content
11
+ # Read the rules
12
+ rules = read_rules
13
13
 
14
- if rule_content
15
- add_additional_context!(rule_content)
16
- log "Successfully added rule content as additional context (#{rule_content.length} characters)"
14
+ if rules
15
+ add_additional_context!(rules)
16
+ log "Successfully added rules as additional context (#{rules.length} characters)"
17
17
  else
18
18
  log "No rule content found", level: :warn
19
19
  end
@@ -23,8 +23,9 @@ class AppendRules < ClaudeHooks::UserPromptSubmit
23
23
 
24
24
  private
25
25
 
26
- def read_rule_content
27
- rule_file_path = path_for('rules/post-user-prompt.rule.md')
26
+ def read_rules
27
+ # If we were in the project directory, we would use project_path_for instead
28
+ rule_file_path = home_path_for('rules/post-user-prompt.rule.md')
28
29
 
29
30
  if File.exist?(rule_file_path)
30
31
  content = File.read(rule_file_path).strip
@@ -32,7 +33,8 @@ class AppendRules < ClaudeHooks::UserPromptSubmit
32
33
  end
33
34
 
34
35
  log "Rule file not found or empty at: #{rule_file_path}", level: :warn
35
- log "Base directory: #{base_dir}"
36
+ # If we were in the project directory, we would use project_claude_dir instead
37
+ log "Base directory: #{home_claude_dir}"
36
38
  nil
37
39
  end
38
40
  end
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'fileutils'
4
3
  require 'claude_hooks'
5
4
 
6
5
  # Example hook module that logs user prompts to a file
@@ -9,10 +8,6 @@ class LogUserPrompt < ClaudeHooks::UserPromptSubmit
9
8
  def call
10
9
  log "Executing LogUserPrompt hook"
11
10
 
12
- # Log the prompt to a file (just as an example)
13
- log_file_path = path_for('logs/user_prompts.log')
14
- ensure_log_directory_exists
15
-
16
11
  timestamp = Time.now.strftime('%Y-%m-%d %H:%M:%S')
17
12
 
18
13
  log <<~TEXT
@@ -22,13 +17,6 @@ class LogUserPrompt < ClaudeHooks::UserPromptSubmit
22
17
 
23
18
  nil
24
19
  end
25
-
26
- private
27
-
28
- def ensure_log_directory_exists
29
- log_dir = path_for('logs')
30
- FileUtils.mkdir_p(log_dir) unless Dir.exist?(log_dir)
31
- end
32
20
  end
33
21
 
34
22
  # If this file is run directly (for testing), call the hook
@@ -122,7 +122,7 @@ module ClaudeHooks
122
122
  # Check if we have a config value for this method
123
123
  env_key = method_name.to_s.upcase
124
124
  config_key = snake_case_to_camel_case(method_name.to_s)
125
-
125
+
126
126
  !get_config_value(env_key, config_key).nil? || super
127
127
  end
128
128
 
@@ -155,10 +155,10 @@ module ClaudeHooks
155
155
  def load_config
156
156
  # Load and merge config files from both locations
157
157
  merged_file_config = load_and_merge_config_files
158
-
158
+
159
159
  # Merge with ENV variables
160
160
  env_config = load_env_config
161
-
161
+
162
162
  # ENV variables take precedence over file configs
163
163
  merged_file_config.merge(env_config)
164
164
  end
@@ -166,10 +166,10 @@ module ClaudeHooks
166
166
  def load_and_merge_config_files
167
167
  home_config = load_config_file_from_path(home_config_file_path)
168
168
  project_config = load_config_file_from_path(project_config_file_path) if project_config_file_path
169
-
169
+
170
170
  # Determine merge strategy
171
- merge_strategy = ENV['CLAUDE_HOOKS_CONFIG_MERGE_STRATEGY'] || 'project'
172
-
171
+ merge_strategy = ENV['RUBY_CLAUDE_HOOKS_CONFIG_MERGE_STRATEGY'] || 'project'
172
+
173
173
  if project_config && merge_strategy == 'project'
174
174
  # Project config takes precedence
175
175
  home_config.merge(project_config)
@@ -205,15 +205,15 @@ module ClaudeHooks
205
205
 
206
206
  def load_env_config
207
207
  env_config = {}
208
-
208
+
209
209
  ENV.each do |key, value|
210
210
  next unless key.start_with?(ENV_PREFIX)
211
-
211
+
212
212
  # Remove prefix and convert to config key format
213
213
  config_key = env_key_to_config_key(key.sub(ENV_PREFIX, ''))
214
214
  env_config[config_key] = value
215
215
  end
216
-
216
+
217
217
  env_config
218
218
  end
219
219
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ClaudeHooks
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: claude_hooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Dehan