Always up-to-date Nix package for Claude Code - AI coding assistant in your terminal.
🚀 Automatically updated hourly to ensure you always have the latest Claude Code version.
While both this flake and upstream nixpkgs provide Claude Code as a Nix package, this flake focuses on:
- Immediate Updates: New Claude Code versions available within 1 hour of release
- Dedicated Maintenance: Focused repository for quick fixes when Claude Code changes
- Flake-First Design: Direct flake usage with Cachix binary cache
- Custom Wrapper Control: Ready to adapt when Claude Code adds new validations or requirements
- Node.js 22 LTS: Latest long-term support version for better performance and security
While npm install -g @anthropic-ai/claude-code
works, it has critical limitations:
- Disappears on Node.js Switch: When projects use different Node.js versions (via asdf/nvm), Claude Code becomes unavailable
- Must Reinstall Per Version: Need to install Claude Code separately for each Node.js version
- Not Declarative: Can't be managed in your Nix configuration
- Not Reproducible: Different Node.js versions can cause inconsistencies
- Outside Nix: Doesn't integrate with Nix's dependency management
Example Problem: You're working on a legacy project that uses Node.js 16 via asdf. When you switch to that project, your globally installed Claude Code (from Node.js 22) disappears from your PATH. Both this flake and upstream nixpkgs solve this by bundling Node.js with Claude Code.
While nixpkgs provides Claude Code, the update cycle can be slow:
- Pull requests can take days to weeks for review and merge
- Updates depend on maintainer availability
- You're tied to your nixpkgs channel's update schedule
- Emergency fixes for breaking changes can be delayed
This repository provides:
- Hourly Automated Updates: GitHub Actions checks for new versions every hour
- Instant Availability: Updates are automatically built and cached to Cachix
- Quick Fixes: When Claude Code breaks or adds new requirements, we can fix immediately
- Node.js 22 LTS: We control the runtime version (upstream locked to Node.js 20)
- Future Flexibility: Prepared to test alternative runtimes like Bun
While Claude Code exists in nixpkgs, our approach offers specific advantages:
- Always Latest Version: Hourly automated checks vs waiting for nixpkgs PR reviews and merges
- Node.js Version Control: We use Node.js 22 LTS (upstream is locked to Node.js 20 with no override option)
- Flake with Binary Cache: Direct flake usage with Cachix means instant installation
- Custom Package Implementation: Full control over the build process for future enhancements (e.g., Bun runtime)
- Dedicated Repository: Focused maintenance without the complexity of nixpkgs contribution process
Feature | npm global | nixpkgs upstream | This Flake |
---|---|---|---|
Latest Version | ✅ Always | ❌ Delayed | ✅ Hourly checks |
Node.js Version | 🔒 Node.js 20 | ✅ Node.js 22 LTS | |
Survives Node Switch | ❌ Lost on switch | ✅ Always available | ✅ Always available |
Binary Cache | ❌ None | ✅ NixOS cache | ✅ Cachix |
Declarative Config | ❌ None | ✅ Yes | ✅ Yes |
Version Pinning | ✅ Channel-based | ✅ Flake lock | |
Update Frequency | ✅ Immediate | ✅ < 1 hour | |
Reproducible | ❌ No | ✅ Yes | ✅ Yes |
Sandbox Builds | ❌ N/A | ✅ Yes | ✅ Yes |
- Always Up-to-Date: Automated hourly checks and updates via GitHub Actions
- Pre-built Binaries: Cachix provides instant installation without compilation
- Flake-native: Modern Nix flake for composable, reproducible deployments
- Home Manager Example: Sample configuration for permission persistence on macOS
- Custom Build Process: Optimized for Claude Code's specific requirements
# Run Claude Code directly without installing
nix run github:sadjow/claude-code-nix
# Install to your profile (survives reboots)
nix profile install github:sadjow/claude-code-nix
To download pre-built binaries instead of compiling:
# Install cachix if you haven't already
nix-env -iA cachix -f https://cachix.org/api/v1/install
# Configure the claude-code cache
cachix use claude-code
Or add to your Nix configuration:
{
nix.settings = {
substituters = [ "https://claude-code.cachix.org" ];
trusted-public-keys = [ "claude-code.cachix.org-1:YeXf2aNu7UTX8Vwrze0za1WEDS+4DuI2kVeWEE4fsRk=" ];
};
}
Add to your flake.nix
:
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
claude-code.url = "github:sadjow/claude-code-nix";
};
outputs = { self, nixpkgs, claude-code, ... }: {
# Use as an overlay
nixosConfigurations.myhost = nixpkgs.lib.nixosSystem {
modules = [
{
nixpkgs.overlays = [ claude-code.overlays.default ];
environment.systemPackages = [ pkgs.claude-code ];
}
];
};
};
}
With Home Manager, add to your configuration:
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
home-manager.url = "github:nix-community/home-manager";
claude-code.url = "github:sadjow/claude-code-nix";
};
outputs = { self, nixpkgs, home-manager, claude-code, ... }: {
homeConfigurations."username" = home-manager.lib.homeManagerConfiguration {
modules = [
{
nixpkgs.overlays = [ claude-code.overlays.default ];
home.packages = [ pkgs.claude-code ];
}
];
};
};
}
Our custom package.nix
implementation:
- Pre-fetches npm tarball: Uses Nix's Fixed Output Derivation (FOD) for reproducible, offline builds
- Bundles Node.js 22 LTS: Ensures consistent runtime environment across all systems
- Custom wrapper script: Handles PATH, environment variables, and Claude-specific requirements
- Sandbox compatible: All network fetching happens during the FOD phase, not build phase
Currently using Node.js 22 LTS because:
- Long-term stability and support until April 2027
- Better performance than Node.js 20 (upstream nixpkgs version)
- Latest LTS with all security updates
- Full control over version (upstream is hardcoded to Node.js 20)
We're exploring support for alternative JavaScript runtimes:
- Bun: Potential performance improvements and faster startup times
- Deno: Enhanced security model and TypeScript support
- Runtime selection: Allow users to choose their preferred runtime via overlay options
# Clone the repository
git clone https://github.com/sadjow/claude-code-nix
cd claude-code-nix
# Build the package
nix build
# Run tests
nix run . -- --version
# Check for version updates
./scripts/update-version.sh --check
# Enter development shell
nix develop
This repository uses GitHub Actions to automatically check for new Claude Code versions every hour. When a new version is detected:
- A pull request is automatically created with the version update
- The tarball hash is automatically calculated
- Tests run on both Ubuntu and macOS to verify the build
- The PR auto-merges if all checks pass
The automated update workflow runs:
- Every hour (at the top of the hour)
- On manual trigger via GitHub Actions UI
This means new Claude Code versions are typically available in this flake within 30 minutes of being published to npm!
# Check for updates
./scripts/update-version.sh --check
# Update to latest version
./scripts/update-version.sh
# Update to specific version
./scripts/update-version.sh --version 1.0.82
# Show help
./scripts/update-version.sh --help
The script automatically:
- Updates the version in
package.nix
- Fetches and calculates the tarball hash
- Updates
flake.lock
with latest nixpkgs - Verifies the build succeeds
If you prefer to update manually:
- Edit
package.nix
and change theversion
field - Get the new tarball hash:
nix-prefetch-url https://registry.npmjs.org/@anthropic-ai/claude-code/-/claude-code-VERSION.tgz
- Update the
sha256
field inpackage.nix
with the new hash - Build and test locally:
nix build && ./result/bin/claude --version
- Update
flake.lock
:nix flake update
- Submit a pull request
When running claude /status
, you may see a warning: "Claude symlink points to invalid binary: /nix/store/.../bin/claude"
This is a false positive and can be safely ignored. The warning occurs because Claude Code's validation expects a large binary file (>10MB), but Nix packages Claude as a wrapper script that launches Node.js with the actual CLI code. This is standard practice in Nix packaging and everything works correctly despite the warning.
On macOS, Claude Code may ask for permissions after each Nix update because the binary path changes. To fix this:
- Create a stable symlink:
ln -s $(which claude) ~/.local/bin/claude
- Add
~/.local/bin
to your PATH - Always run
claude
from~/.local/bin/claude
- Your
.claude.json
and.claude/
directory will be preserved
If you need to reset Claude's permissions:
rm -rf ~/.claude ~/.claude.json
The Nix packaging is MIT licensed. Claude Code itself is proprietary software by Anthropic.