claudescreenfix-hardwicksoftware 2.2.1 → 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 +123 -0
  2. package/package.json +6 -3
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/env node
2
+ /**
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)
6
+ */
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+ const os = require('os');
10
+
11
+ const HOOK_NAME = 'screenfix-loader.js';
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');
15
+
16
+ const HOOK_CONTENT = `#!/usr/bin/env node
17
+ /**
18
+ * CLAUDE SCREENFIX LOADER HOOK
19
+ * ============================
20
+ *
21
+ * SessionStart hook that loads claudescreenfix-hardwicksoftware
22
+ * to fix VTE rendering glitches on headless/VNC displays.
23
+ *
24
+ * Auto-installed by: npm install claudescreenfix-hardwicksoftware
25
+ *
26
+ * Hook Event: SessionStart
27
+ */
28
+
29
+ try {
30
+ const screenfix = require('claudescreenfix-hardwicksoftware');
31
+ screenfix.install();
32
+ } catch (e) {
33
+ // screenfix not installed or failed, continue silently
34
+ }
35
+
36
+ // Hook must output valid JSON for SessionStart
37
+ const input = process.argv[2] || '{}';
38
+ try {
39
+ const hookEvent = JSON.parse(input);
40
+ if (hookEvent.type === 'SessionStart') {
41
+ console.log(JSON.stringify({ result: '' }));
42
+ }
43
+ } catch (e) {
44
+ // Not a valid hook call, ignore
45
+ }
46
+ `;
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
+
57
+ function install() {
58
+ try {
59
+ // Create dirs if needed
60
+ if (!fs.existsSync(CLAUDE_DIR)) {
61
+ fs.mkdirSync(CLAUDE_DIR, { recursive: true });
62
+ }
63
+ if (!fs.existsSync(CLAUDE_HOOKS_DIR)) {
64
+ fs.mkdirSync(CLAUDE_HOOKS_DIR, { recursive: true });
65
+ console.log('[screenfix] Created ' + CLAUDE_HOOKS_DIR);
66
+ }
67
+
68
+ // Write the hook file
69
+ const hookPath = path.join(CLAUDE_HOOKS_DIR, HOOK_NAME);
70
+ fs.writeFileSync(hookPath, HOOK_CONTENT, { mode: 0o755 });
71
+ console.log('[screenfix] Installed hook to ' + hookPath);
72
+
73
+ // Register in settings.json
74
+ registerHook();
75
+
76
+ console.log('[screenfix] Restart Claude Code to activate headless mode fix');
77
+ } catch (e) {
78
+ console.error('[screenfix] Failed to install hook:', e.message);
79
+ }
80
+ }
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
+
122
+ // Run install
123
+ install();
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "claudescreenfix-hardwicksoftware",
3
- "version": "2.2.1",
4
- "description": "fixes scroll glitch + VNC/headless rendering in claude code cli - strips BG colors that break VTE on Xvfb",
3
+ "version": "2.3.1",
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": {
7
7
  "claude-fixed": "./bin/claude-fixed.js"
8
8
  },
9
- "scripts": {},
9
+ "scripts": {
10
+ "postinstall": "node install-hook.cjs"
11
+ },
10
12
  "keywords": [
11
13
  "claude",
12
14
  "terminal",
@@ -32,6 +34,7 @@
32
34
  "files": [
33
35
  "index.cjs",
34
36
  "loader.cjs",
37
+ "install-hook.cjs",
35
38
  "bin/",
36
39
  "README.md",
37
40
  "LICENSE"