Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions home-manager/modules/npm-globals/install-npm-globals.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,43 @@ repair_sqlite3_native_binding() {
echo "sqlite3 native binding rebuilt"
}

repair_claude_code_native_binary() {
# @anthropic-ai/claude-code ships only a wrapper in bin/claude.exe; the real
# binary comes from a platform-native optionalDependency installed by its
# postinstall. The version-only skip above leaves a broken install in place
# when that optional dep is missing (e.g. after an `omit=optional` install),
# so reinstall to fetch the native binary.
local claude_dir="${GLOBAL_MODULES}/@anthropic-ai/claude-code"
local wanted

if [ ! -d "$claude_dir" ]; then
return 0
fi

if command -v claude &>/dev/null && claude --version >/dev/null 2>&1; then
Comment thread
This conversation was marked as resolved.
Resolved
echo "claude native binary already loadable"
return 0
fi

wanted=$(jq -r '.dependencies["@anthropic-ai/claude-code"] // empty' "$PACKAGE_JSON" 2>/dev/null || true)
[ -z "$wanted" ] && wanted="latest"

echo "Reinstalling @anthropic-ai/claude-code to fetch native binary..."
bun pm -g trust @anthropic-ai/claude-code 2>/dev/null || true
bun remove --global @anthropic-ai/claude-code 2>/dev/null || true
if ! timeout 600 bun add --global "@anthropic-ai/claude-code@${wanted}"; then
echo "claude-code reinstall failed" >&2
return 1
fi

if ! (command -v claude &>/dev/null && claude --version >/dev/null 2>&1); then
echo "claude native binary still not loadable after reinstall" >&2
return 1
fi

echo "claude native binary repaired"
}

echo "Installing npm global packages from package.json using bun..."
cd "${HOME}/dotfiles"

Expand Down Expand Up @@ -196,4 +233,8 @@ if ! repair_sqlite3_native_binding; then
echo "Warning: sqlite3 native binding repair failed" >&2
fi

if ! repair_claude_code_native_binary; then
echo "Warning: claude-code native binary repair failed" >&2
fi

echo "npm globals installation complete"
6 changes: 5 additions & 1 deletion home-manager/programs/tmux/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
{
plugin = continuum;
extraConfig = ''
set -g @continuum-restore 'on'
# Auto-restore is intentionally off: it fires on every cold tmux
# server start, racing __tmux_bootstrap_default_session and freezing
# the freshly-attached client (e.g. on `tpo`). Restore is driven
# manually by `two`/_two_function for the `work` session only.
set -g @continuum-restore 'off'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium

This change disables auto-restore globally for all sessions, not just for tpo/tdo/tmo. While this fixes the race condition, it creates a single point of failure: restore now only works if users enter the work session via the two command.

Consider:

  1. Verify that ALL entrypoints to the work session route through two/_two_function - if users can attach to work via tmux attach -t work or other means, restore won't trigger.
  2. Document this behavioral change in user-facing documentation (README, shell function comments) since the Nix config comment won't be visible to users of the shell commands.
  3. Confirm that the manual restore in _two_function (mentioned as lines 33-34) is robust and handles failure cases appropriately.

If auto-restore for other sessions was previously relied upon, this is a functional regression. The test plan should verify behavior after server crash/reboot, not just clean shutdown scenarios.

Fix in Cursor • Fix in Claude

Prompt for Agent
Task: Address review feedback left on GitHub.
Repository: shunkakinoki/dotfiles#1893
File: home-manager/programs/tmux/default.nix#L32
Action: Open this file location in your editor, inspect the highlighted code, and resolve the issue described below.

Feedback:
This change disables auto-restore globally for all sessions, not just for `tpo`/`tdo`/`tmo`. While this fixes the race condition, it creates a single point of failure: restore now only works if users enter the `work` session via the `two` command.

Consider:
1. Verify that ALL entrypoints to the `work` session route through `two`/`_two_function` - if users can attach to `work` via `tmux attach -t work` or other means, restore won't trigger.
2. Document this behavioral change in user-facing documentation (README, shell function comments) since the Nix config comment won't be visible to users of the shell commands.
3. Confirm that the manual restore in `_two_function` (mentioned as lines 33-34) is robust and handles failure cases appropriately.

If auto-restore for other sessions was previously relied upon, this is a functional regression. The test plan should verify behavior after server crash/reboot, not just clean shutdown scenarios.

set -g @continuum-save-interval '3'
set -g status-right "#[fg=colour250]#{?#{pane_current_command},#{pane_current_command},} #[fg=colour28]| #[fg=colour255]%Y/%m/%d %H:%M:%S #{continuum_status}"
set -g status-right-length 60
Expand Down
15 changes: 15 additions & 0 deletions spec/npm_globals_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,21 @@ It 'verifies sqlite3 can be loaded by node'
When run bash -c "grep 'const sqlite3 = require' '$SCRIPT'"
The output should include 'const sqlite3 = require'
End

It 'has a claude-code native binary repair step'
When run bash -c "grep 'repair_claude_code_native_binary' '$SCRIPT'"
The output should include 'repair_claude_code_native_binary'
End

It 'reinstalls claude-code when its native binary is missing'
When run bash -c "grep -A 30 'repair_claude_code_native_binary()' '$SCRIPT'"
The output should include 'bun add --global'
End

It 'verifies the claude binary is runnable after repair'
When run bash -c "grep 'claude --version' '$SCRIPT'"
The output should include 'claude --version'
End
End

Describe 'stale global package pruning'
Expand Down
Loading