summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configs/claude.nix23
1 files changed, 19 insertions, 4 deletions
diff --git a/configs/claude.nix b/configs/claude.nix
index 345a70a..b7ebb75 100644
--- a/configs/claude.nix
+++ b/configs/claude.nix
@@ -11,10 +11,10 @@
# for Claude Code (sessions, memory, trust), on the repositories in ~/src,
# which all remotes share. Each runs as claude in a tmux of its own,
# which root opens with claude-remote attach [NAME]. Once, as root:
-# runuser -l claude -c 'claude auth login', then, for each NAME,
-# claude-remote attach NAME and answer Remote Control's questions there
-# (enable it, trust ~/remotes/NAME). The state is in /home/claude, i.e.
-# on the run script's --home drive, which is required.
+# runuser -l claude -c 'claude auth login'. Remote Control's questions
+# (enable it, once per machine; trust ~/remotes/NAME) the unit answers.
+# The state is in /home/claude, i.e. on the run script's --home drive,
+# which is required.
{ config, lib, pkgs, ... }:
let
# The tmux of claude-remote-control@NAME.
@@ -161,6 +161,21 @@ in
esac
mkdir -p /home/claude/remotes/"$1"
''} %i"
+ # Remote Control's questions, answered, rather than asked in the
+ # terminal: enable it (remoteDialogSeen, once per machine; that's
+ # what the units are for), and trust ~/remotes/NAME, the remote's
+ # own directory, just made. In ~/.claude.json (once there is
+ # one, i.e. after the login), atomically; if a remote writes back
+ # what it read before, and an answer gets lost, Remote Control
+ # asks again, as before.
+ "${pkgs.writeShellScript "claude-remote-control-trust" ''
+ f=/home/claude/.claude.json d=/home/claude/remotes/$1
+ test -f "$f" || exit 0
+ if ! ${pkgs.jq}/bin/jq -e --arg d "$d" '.remoteDialogSeen == true and .projects[$d].hasTrustDialogAccepted == true' "$f" >/dev/null; then
+ ${pkgs.jq}/bin/jq --arg d "$d" '.remoteDialogSeen = true | .projects[$d].hasTrustDialogAccepted = true' "$f" > "$f.trust" &&
+ mv "$f.trust" "$f" || rm -f "$f.trust"
+ fi
+ ''} %i"
# As root (+), stateDir being root's.
"+${remember} %i"
];