feat(claude-code): add a Module and enable it on neogaia
Install Claude Code through home-manager's native programs.claude-code module, matching how the tmux and fish Modules use their home-manager options rather than a raw home.packages entry. The feature Module at modules/claude-code/claude-code.nix stays thin — just the enable option and the delegation — and writes no settings, so login and first-run configuration remain interactive and no auth material enters the repo. Signing in without a browser (needed over the console or SSH) is documented in modules/claude-code/authentication.md: the paste-code OAuth flow, where the printed URL is opened on another device and the code pasted back, and the ANTHROPIC_API_KEY path for non-interactive use. The neogaia toplevel builds with claude-code-2.1.209 included.
This commit is contained in:
32
modules/claude-code/authentication.md
Normal file
32
modules/claude-code/authentication.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# Authenticating Claude Code without a browser
|
||||
|
||||
`neogaia` is driven from the console and over SSH, where no local browser can service Claude Code's default OAuth redirect.
|
||||
Either of the two paths below signs the CLI in from a bare terminal.
|
||||
Both are one-time actions per machine; the credentials land under `~/.claude`, which home-manager does not overwrite.
|
||||
|
||||
## Paste-code flow (Claude subscription or Console OAuth)
|
||||
|
||||
Run `claude` and start the login with the `/login` command (the first run offers it automatically).
|
||||
On a machine with no browser it cannot open the authorization page itself, so it prints the authorization URL and waits.
|
||||
|
||||
1. Copy the printed URL to a browser on any other device (phone, another laptop).
|
||||
2. Sign in and approve the request there.
|
||||
3. The page returns a short authorization code; paste it back at the `claude` prompt still waiting in the terminal.
|
||||
|
||||
The session then completes and the token is stored, so later runs need no further login.
|
||||
Because the URL is opened on a *different* device, this works unchanged over SSH.
|
||||
|
||||
## API key
|
||||
|
||||
For non-interactive use, set an Anthropic API key from <https://console.anthropic.com> in the environment before launching `claude`:
|
||||
|
||||
```console
|
||||
$ export ANTHROPIC_API_KEY=sk-ant-...
|
||||
$ claude
|
||||
```
|
||||
|
||||
Claude Code reads `ANTHROPIC_API_KEY` on startup and skips the interactive login entirely, so this path needs neither a browser nor the paste-code exchange.
|
||||
Usage is billed to the Console account that owns the key rather than to a Claude subscription.
|
||||
|
||||
The key is a secret and is deliberately not baked into this configuration.
|
||||
Export it from the shell for a one-off, or source it from a secret store once one exists on the Host.
|
||||
22
modules/claude-code/claude-code.nix
Normal file
22
modules/claude-code/claude-code.nix
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
# Claude Code — Anthropic's CLI — for the primary user, installed declaratively
|
||||
# through home-manager. home-manager ships the package and owns ~/.claude; no
|
||||
# settings are written here, so login and first-run configuration stay
|
||||
# interactive. Signing in without a browser, as needed over the console or SSH,
|
||||
# is covered in ./authentication.md.
|
||||
let
|
||||
cfg = config.modules.claude-code;
|
||||
user = config.user.name;
|
||||
in
|
||||
{
|
||||
options.modules.claude-code.enable =
|
||||
lib.mkEnableOption "Claude Code, Anthropic's CLI, installed via home-manager";
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
home-manager.users.${user}.programs.claude-code.enable = true;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user