#!/usr/bin/env bash # LaRouter setup for the Claude desktop app on macOS. # Lets Claude and Cowork reach the internet and turns off the Code tab's sandbox: # edits the active third-party inference config (from the Developer settings steps) # and ~/.claude/settings.json, keeps every other setting and saves a backup first. # No API key is needed; the gateway key is already in the app's config. # Usage: curl -fsSL https://larouter.lapage.vn/setup/claude-app.sh | bash larouter_setup() { perl -MJSON::PP -e ' my $home = $ENV{HOME}; my @dirs = ("$home/Library/Application Support/Claude-3p/configLibrary", "$home/Library/Application Support/Claude/configLibrary"); my ($dir) = grep { -f "$_/_meta.json" } @dirs; unless ($dir) { print STDERR "Could not find the Claude app settings. Checked:\n", map({ " $_\n" } @dirs); die "Finish the Developer settings steps above and click Apply Changes first. Nothing was changed.\n"; } sub slurp { my $p = shift; open(my $in, "<", $p) or die "Cannot read $p. Nothing was changed.\n"; local $/; my $t = <$in>; close $in; $t =~ s/^\xEF\xBB\xBF//; return $t } sub parse { my ($p, $t) = @_; my $d = eval { JSON::PP->new->utf8->decode($t) }; die "Your $p is not valid JSON. Nothing was changed.\n" unless ref $d eq "HASH"; return $d } my $meta = parse("$dir/_meta.json", slurp("$dir/_meta.json")); my $id = $meta->{appliedId}; die "Could not find the active Claude app settings in $dir. Finish the Developer settings steps above and click Apply Changes first. Nothing was changed.\n" unless defined $id && !ref $id && $id =~ /^[A-Za-z0-9][A-Za-z0-9._-]*$/ && -f "$dir/$id.json"; my $app = "$dir/$id.json"; my $appText = slurp($app); my $cfg = parse($app, $appText); my $sdir = "$home/.claude"; my $settings = "$sdir/settings.json"; my ($sText, $s) = (undef, {}); if (-s $settings) { $sText = slurp($settings); $s = parse($settings, $sText) } my @t = localtime; my $stamp = sprintf("%04d%02d%02d-%02d%02d%02d", $t[5]+1900, $t[4]+1, @t[3,2,1,0]); sub save { my ($p, $text) = @_; open(my $o, ">", $p) or die "Cannot write $p\n"; print $o $text; close $o; } sub write_json { my ($p, $d, $bak) = @_; save("$p.tmp", JSON::PP->new->utf8->pretty->canonical->encode($d)); rename("$p.tmp", $p) or die "Cannot save $p\n"; my $ok = eval { ref JSON::PP->new->utf8->decode(slurp($p)) eq "HASH" }; unless ($ok) { rename($bak, $p) if $bak; die "Could not save $p correctly, so the backup was put back.\n" } } my $appBak = -e "$app.bak" ? "$app.bak-$stamp" : "$app.bak"; save($appBak, $appText); print "Backup saved: $appBak\n"; my %set = ( coworkEgressAllowedHosts => ["*"], skipWebFetchPreflight => JSON::PP::true, builtinBrowserEnabled => JSON::PP::true, builtinBrowserDefaultDomainPolicy => "allow", isClaudeCodeForDesktopEnabled => JSON::PP::true, disableDesktopLocalSessions => JSON::PP::false, disableBypassPermissionsMode => JSON::PP::false, blockReadsOutsideWorkingDirectories => JSON::PP::false, developerModeEnabled => JSON::PP::true, ); $cfg->{$_} = $set{$_} for keys %set; my @removed = grep { exists $cfg->{$_} } qw(allowedWorkspaceFolders requireCoworkFullVmSandbox); delete $cfg->{$_} for @removed; write_json($app, $cfg, $appBak); print "Updated $app\n Set: ", join(", ", sort keys %set), "\n Removed: ", (@removed ? join(", ", @removed) : "nothing"), "\n"; mkdir $sdir unless -d $sdir; my $sBak; if (defined $sText) { $sBak = "$settings.bak-$stamp"; save($sBak, $sText); print "Backup saved: $sBak\n" } $s->{sandbox} = {} unless ref $s->{sandbox} eq "HASH"; $s->{sandbox}{enabled} = JSON::PP::false; write_json($settings, $s, $sBak); print "Updated $settings\n Set: sandbox.enabled = false\n"; print "Done. Quit Claude completely and open it again.\n"; print "To quit on a Mac, press Command + Q (or choose Claude > Quit Claude). Closing the window is not enough.\n"; print "Cowork always runs commands in its own virtual machine. For tasks on your real computer, such as browsers or signing in to websites, use the Code tab.\n"; ' } larouter_setup