nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1# NOTE: Use the following command to update the package
2# ```sh
3# nix-shell maintainers/scripts/update.nix --argstr commit true --arg predicate '(path: pkg: builtins.elem path [["claude-code"] ["claude-code-bin"] ["vscode-extensions" "anthropic" "claude-code"]])'
4# ```
5{
6 lib,
7 stdenv,
8 buildNpmPackage,
9 fetchzip,
10 versionCheckHook,
11 writableTmpDirAsHomeHook,
12 bubblewrap,
13 procps,
14 socat,
15}:
16buildNpmPackage (finalAttrs: {
17 pname = "claude-code";
18 version = "2.1.20";
19
20 src = fetchzip {
21 url = "https://registry.npmjs.org/@anthropic-ai/claude-code/-/claude-code-${finalAttrs.version}.tgz";
22 hash = "sha256-V2BIqUUJnQpjIsCAAk932L8wp5T74s22q3KgFoxfdDg=";
23 };
24
25 npmDepsHash = "sha256-X8j7httM9qMpAPR11oDAWwDpkxZ2bc20y6ruMoStMsQ=";
26
27 strictDeps = true;
28
29 postPatch = ''
30 cp ${./package-lock.json} package-lock.json
31
32 # https://github.com/anthropics/claude-code/issues/15195
33 substituteInPlace cli.js \
34 --replace-fail '#!/bin/sh' '#!/usr/bin/env sh'
35 '';
36
37 dontNpmBuild = true;
38
39 env.AUTHORIZED = "1";
40
41 # `claude-code` tries to auto-update by default, this disables that functionality.
42 # https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview#environment-variables
43 # The DEV=true env var causes claude to crash with `TypeError: window.WebSocket is not a constructor`
44 postInstall = ''
45 wrapProgram $out/bin/claude \
46 --set DISABLE_AUTOUPDATER 1 \
47 --set DISABLE_INSTALLATION_CHECKS 1 \
48 --unset DEV \
49 --prefix PATH : ${
50 lib.makeBinPath (
51 [
52 # claude-code uses [node-tree-kill](https://github.com/pkrumins/node-tree-kill) which requires procps's pgrep(darwin) or ps(linux)
53 procps
54 ]
55 # the following packages are required for the sandbox to work (Linux only)
56 ++ lib.optionals stdenv.hostPlatform.isLinux [
57 bubblewrap
58 socat
59 ]
60 )
61 }
62 '';
63
64 doInstallCheck = true;
65 nativeInstallCheckInputs = [
66 writableTmpDirAsHomeHook
67 versionCheckHook
68 ];
69 versionCheckKeepEnvironment = [ "HOME" ];
70
71 passthru.updateScript = ./update.sh;
72
73 meta = {
74 description = "Agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster";
75 homepage = "https://github.com/anthropics/claude-code";
76 downloadPage = "https://www.npmjs.com/package/@anthropic-ai/claude-code";
77 license = lib.licenses.unfree;
78 maintainers = with lib.maintainers; [
79 adeci
80 malo
81 markus1189
82 omarjatoi
83 xiaoxiangmoe
84 ];
85 mainProgram = "claude";
86 };
87})