claudescreenfix-hardwicksoftware 2.3.0 → 2.3.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.
Files changed (2) hide show
  1. package/install-hook.cjs +66 -13
  2. package/package.json +1 -1
package/install-hook.cjs CHANGED
@@ -1,24 +1,28 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
3
  * Auto-install Claude hook on npm install
4
+ * - Creates hook file in ~/.claude/hooks/
5
+ * - Registers hook in ~/.claude/settings.json (without clobbering existing settings)
4
6
  */
5
7
  const fs = require('fs');
6
8
  const path = require('path');
7
9
  const os = require('os');
8
10
 
9
11
  const HOOK_NAME = 'screenfix-loader.js';
10
- const CLAUDE_HOOKS_DIR = path.join(os.homedir(), '.claude', 'hooks');
12
+ const CLAUDE_DIR = path.join(os.homedir(), '.claude');
13
+ const CLAUDE_HOOKS_DIR = path.join(CLAUDE_DIR, 'hooks');
14
+ const SETTINGS_FILE = path.join(CLAUDE_DIR, 'settings.json');
11
15
 
12
16
  const HOOK_CONTENT = `#!/usr/bin/env node
13
17
  /**
14
18
  * CLAUDE SCREENFIX LOADER HOOK
15
19
  * ============================
16
- *
20
+ *
17
21
  * SessionStart hook that loads claudescreenfix-hardwicksoftware
18
22
  * to fix VTE rendering glitches on headless/VNC displays.
19
- *
23
+ *
20
24
  * Auto-installed by: npm install claudescreenfix-hardwicksoftware
21
- *
25
+ *
22
26
  * Hook Event: SessionStart
23
27
  */
24
28
 
@@ -41,30 +45,79 @@ try {
41
45
  }
42
46
  `;
43
47
 
48
+ // The hook config to add to settings.json
49
+ const HOOK_CONFIG = {
50
+ hooks: [{
51
+ type: 'command',
52
+ command: 'node ' + path.join(CLAUDE_HOOKS_DIR, HOOK_NAME),
53
+ timeout: 5
54
+ }]
55
+ };
56
+
44
57
  function install() {
45
58
  try {
46
- // Create hooks dir if needed
59
+ // Create dirs if needed
60
+ if (!fs.existsSync(CLAUDE_DIR)) {
61
+ fs.mkdirSync(CLAUDE_DIR, { recursive: true });
62
+ }
47
63
  if (!fs.existsSync(CLAUDE_HOOKS_DIR)) {
48
64
  fs.mkdirSync(CLAUDE_HOOKS_DIR, { recursive: true });
49
65
  console.log('[screenfix] Created ' + CLAUDE_HOOKS_DIR);
50
66
  }
51
67
 
68
+ // Write the hook file
52
69
  const hookPath = path.join(CLAUDE_HOOKS_DIR, HOOK_NAME);
53
-
54
- // Check if hook already exists
55
- if (fs.existsSync(hookPath)) {
56
- console.log('[screenfix] Hook already exists at ' + hookPath);
57
- return;
58
- }
59
-
60
- // Write the hook
61
70
  fs.writeFileSync(hookPath, HOOK_CONTENT, { mode: 0o755 });
62
71
  console.log('[screenfix] Installed hook to ' + hookPath);
72
+
73
+ // Register in settings.json
74
+ registerHook();
75
+
63
76
  console.log('[screenfix] Restart Claude Code to activate headless mode fix');
64
77
  } catch (e) {
65
78
  console.error('[screenfix] Failed to install hook:', e.message);
66
79
  }
67
80
  }
68
81
 
82
+ function registerHook() {
83
+ let settings = {};
84
+
85
+ // Read existing settings
86
+ if (fs.existsSync(SETTINGS_FILE)) {
87
+ try {
88
+ settings = JSON.parse(fs.readFileSync(SETTINGS_FILE, 'utf8'));
89
+ } catch (e) {
90
+ console.log('[screenfix] Could not parse settings.json, creating new');
91
+ }
92
+ }
93
+
94
+ // Ensure hooks object exists
95
+ if (!settings.hooks) {
96
+ settings.hooks = {};
97
+ }
98
+
99
+ // Ensure SessionStart array exists
100
+ if (!settings.hooks.SessionStart) {
101
+ settings.hooks.SessionStart = [];
102
+ }
103
+
104
+ // Check if our hook is already registered
105
+ const alreadyRegistered = settings.hooks.SessionStart.some(h =>
106
+ h.hooks && h.hooks.some(hh => hh.command && hh.command.includes('screenfix-loader'))
107
+ );
108
+
109
+ if (alreadyRegistered) {
110
+ console.log('[screenfix] Hook already registered in settings.json');
111
+ return;
112
+ }
113
+
114
+ // Add our hook to the BEGINNING so it loads first
115
+ settings.hooks.SessionStart.unshift(HOOK_CONFIG);
116
+
117
+ // Write back settings
118
+ fs.writeFileSync(SETTINGS_FILE, JSON.stringify(settings, null, 2));
119
+ console.log('[screenfix] Registered hook in settings.json');
120
+ }
121
+
69
122
  // Run install
70
123
  install();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claudescreenfix-hardwicksoftware",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "description": "fixes scroll glitch + VNC/headless rendering in claude code cli - auto-installs hook, strips BG colors on Xvfb",
5
5
  "main": "index.cjs",
6
6
  "bin": {