1# Crush
  2
  3<p align="center">
  4    <a href="https://stuff.charm.sh/crush/charm-crush.png"><img width="450" alt="Charm Crush Logo" src="https://github.com/user-attachments/assets/adc1a6f4-b284-4603-836c-59038caa2e8b" /></a><br />
  5    <a href="https://github.com/charmbracelet/crush/releases"><img src="https://img.shields.io/github/release/charmbracelet/crush" alt="Latest Release"></a>
  6    <a href="https://github.com/charmbracelet/crush/actions"><img src="https://github.com/charmbracelet/crush/actions/workflows/build.yml/badge.svg" alt="Build Status"></a>
  7</p>
  8
  9<p align="center">Your new coding bestie, now available in your favourite terminal.<br />Your tools, your code, and your workflows, wired into your LLM of choice.</p>
 10<p align="center">你的新编程伙伴,现在就在你最爱的终端中。<br />你的工具、代码和工作流,都与您选择的 LLM 模型紧密相连。</p>
 11
 12<p align="center"><img width="800" alt="Crush Demo" src="https://github.com/user-attachments/assets/58280caf-851b-470a-b6f7-d5c4ea8a1968" /></p>
 13
 14## Features
 15
 16- **Multi-Model:** choose from a wide range of LLMs or add your own via OpenAI- or Anthropic-compatible APIs
 17- **Flexible:** switch LLMs mid-session while preserving context
 18- **Session-Based:** maintain multiple work sessions and contexts per project
 19- **LSP-Enhanced:** Crush uses LSPs for additional context, just like you do
 20- **Extensible:** add capabilities via MCPs (`http`, `stdio`, and `sse`)
 21- **Works Everywhere:** first-class support in every terminal on macOS, Linux, Windows (PowerShell and WSL), FreeBSD, OpenBSD, and NetBSD
 22
 23## Installation
 24
 25Use a package manager:
 26
 27```bash
 28# Homebrew
 29brew install charmbracelet/tap/crush
 30
 31# NPM
 32npm install -g @charmland/crush
 33
 34# Arch Linux (btw)
 35yay -S crush-bin
 36
 37# Nix
 38nix run github:numtide/nix-ai-tools#crush
 39```
 40
 41Windows users:
 42
 43```bash
 44# Winget
 45winget install charmbracelet.crush
 46
 47# Scoop
 48scoop bucket add charm https://github.com/charmbracelet/scoop-bucket.git
 49scoop install crush
 50```
 51
 52<details>
 53<summary><strong>Nix (NUR)</strong></summary>
 54
 55Crush is available via [NUR](https://github.com/nix-community/NUR) in `nur.repos.charmbracelet.crush`.
 56
 57You can also try out Crush via `nix-shell`:
 58
 59```bash
 60# Add the NUR channel.
 61nix-channel --add https://github.com/nix-community/NUR/archive/main.tar.gz nur
 62nix-channel --update
 63
 64# Get Crush in a Nix shell.
 65nix-shell -p '(import <nur> { pkgs = import <nixpkgs> {}; }).repos.charmbracelet.crush'
 66```
 67
 68### NixOS & Home Manager Module Usage via NUR
 69
 70Crush provides NixOS and Home Manager modules via NUR.
 71You can use these modules directly in your flake by importing them from NUR. Since it auto detects whether its a home manager or nixos context you can use the import the exact same way :)
 72
 73```nix
 74{
 75  inputs = {
 76    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
 77    nur.url = "github:nix-community/NUR";
 78  };
 79
 80  outputs = { self, nixpkgs, nur, ... }: {
 81    nixosConfigurations.your-hostname = nixpkgs.lib.nixosSystem {
 82      system = "x86_64-linux";
 83      modules = [
 84        nur.modules.nixos.default
 85        nur.repos.charmbracelet.modules.crush
 86        {
 87          programs.crush = {
 88            enable = true;
 89            settings = {
 90              providers = {
 91                openai = {
 92                  id = "openai";
 93                  name = "OpenAI";
 94                  base_url = "https://api.openai.com/v1";
 95                  type = "openai";
 96                  api_key = "sk-fake123456789abcdef...";
 97                  models = [
 98                    {
 99                      id = "gpt-4";
100                      name = "GPT-4";
101                    }
102                  ];
103                };
104              };
105              lsp = {
106                go = { command = "gopls"; enabled = true; };
107                nix = { command = "nil"; enabled = true; };
108              };
109              options = {
110                context_paths = [ "/etc/nixos/configuration.nix" ];
111                tui = { compact_mode = true; };
112                debug = false;
113              };
114            };
115          };
116        }
117      ];
118    };
119  };
120}
121```
122
123</details>
124
125<details>
126<summary><strong>Debian/Ubuntu</strong></summary>
127
128```bash
129sudo mkdir -p /etc/apt/keyrings
130curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
131echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list
132sudo apt update && sudo apt install crush
133```
134
135</details>
136
137<details>
138<summary><strong>Fedora/RHEL</strong></summary>
139
140```bash
141echo '[charm]
142name=Charm
143baseurl=https://repo.charm.sh/yum/
144enabled=1
145gpgcheck=1
146gpgkey=https://repo.charm.sh/yum/gpg.key' | sudo tee /etc/yum.repos.d/charm.repo
147sudo yum install crush
148```
149
150</details>
151
152Or, download it:
153
154- [Packages][releases] are available in Debian and RPM formats
155- [Binaries][releases] are available for Linux, macOS, Windows, FreeBSD, OpenBSD, and NetBSD
156
157[releases]: https://github.com/charmbracelet/crush/releases
158
159Or just install it with Go:
160
161```
162go install github.com/charmbracelet/crush@latest
163```
164
165> [!WARNING]
166> Productivity may increase when using Crush and you may find yourself nerd
167> sniped when first using the application. If the symptoms persist, join the
168> [Discord][discord] and nerd snipe the rest of us.
169
170## Getting Started
171
172The quickest way to get started is to grab an API key for your preferred
173provider such as Anthropic, OpenAI, Groq, or OpenRouter and just start
174Crush. You'll be prompted to enter your API key.
175
176That said, you can also set environment variables for preferred providers.
177
178| Environment Variable        | Provider                                           |
179| --------------------------- | -------------------------------------------------- |
180| `ANTHROPIC_API_KEY`         | Anthropic                                          |
181| `OPENAI_API_KEY`            | OpenAI                                             |
182| `OPENROUTER_API_KEY`        | OpenRouter                                         |
183| `CEREBRAS_API_KEY`          | Cerebras                                           |
184| `GEMINI_API_KEY`            | Google Gemini                                      |
185| `VERTEXAI_PROJECT`          | Google Cloud VertexAI (Gemini)                     |
186| `VERTEXAI_LOCATION`         | Google Cloud VertexAI (Gemini)                     |
187| `GROQ_API_KEY`              | Groq                                               |
188| `AWS_ACCESS_KEY_ID`         | AWS Bedrock (Claude)                               |
189| `AWS_SECRET_ACCESS_KEY`     | AWS Bedrock (Claude)                               |
190| `AWS_REGION`                | AWS Bedrock (Claude)                               |
191| `AZURE_OPENAI_API_ENDPOINT` | Azure OpenAI models                                |
192| `AZURE_OPENAI_API_KEY`      | Azure OpenAI models (optional when using Entra ID) |
193| `AZURE_OPENAI_API_VERSION`  | Azure OpenAI models                                |
194
195### By the Way
196
197Is there a provider you’d like to see in Crush? Is there an existing model that needs an update?
198
199Crush’s default model listing is managed in [Catwalk](https://github.com/charmbracelet/catwalk), a community-supported, open source repository of Crush-compatible models, and you’re welcome to contribute.
200
201<a href="https://github.com/charmbracelet/catwalk"><img width="174" height="174" alt="Catwalk Badge" src="https://github.com/user-attachments/assets/95b49515-fe82-4409-b10d-5beb0873787d" /></a>
202
203## Configuration
204
205Crush runs great with no configuration. That said, if you do need or want to
206customize Crush, configuration can be added either local to the project itself,
207or globally, with the following priority:
208
2091. `.crush.json`
2102. `crush.json`
2113. `$HOME/.config/crush/crush.json` (Windows: `%USERPROFILE%\AppData\Local\crush\crush.json`)
212
213Configuration itself is stored as a JSON object:
214
215```json
216{
217  "this-setting": { "this": "that" },
218  "that-setting": ["ceci", "cela"]
219}
220```
221
222As an additional note, Crush also stores ephemeral data, such as application state, in one additional location:
223
224```bash
225# Unix
226$HOME/.local/share/crush/crush.json
227
228# Windows
229%LOCALAPPDATA%\crush\crush.json
230```
231
232### LSPs
233
234Crush can use LSPs for additional context to help inform its decisions, just
235like you would. LSPs can be added manually like so:
236
237```json
238{
239  "$schema": "https://charm.land/crush.json",
240  "lsp": {
241    "go": {
242      "command": "gopls",
243      "env": {
244        "GOTOOLCHAIN": "go1.24.5"
245      }
246    },
247    "typescript": {
248      "command": "typescript-language-server",
249      "args": ["--stdio"]
250    },
251    "nix": {
252      "command": "nil"
253    }
254  }
255}
256```
257
258### MCPs
259
260Crush also supports Model Context Protocol (MCP) servers through three
261transport types: `stdio` for command-line servers, `http` for HTTP endpoints,
262and `sse` for Server-Sent Events. Environment variable expansion is supported
263using `$(echo $VAR)` syntax.
264
265```json
266{
267  "$schema": "https://charm.land/crush.json",
268  "mcp": {
269    "filesystem": {
270      "type": "stdio",
271      "command": "node",
272      "args": ["/path/to/mcp-server.js"],
273      "env": {
274        "NODE_ENV": "production"
275      }
276    },
277    "github": {
278      "type": "http",
279      "url": "https://example.com/mcp/",
280      "headers": {
281        "Authorization": "$(echo Bearer $EXAMPLE_MCP_TOKEN)"
282      }
283    },
284    "streaming-service": {
285      "type": "sse",
286      "url": "https://example.com/mcp/sse",
287      "headers": {
288        "API-Key": "$(echo $API_KEY)"
289      }
290    }
291  }
292}
293```
294
295### Ignoring Files
296
297Crush respects `.gitignore` files by default, but you can also create a
298`.crushignore` file to specify additional files and directories that Crush
299should ignore. This is useful for excluding files that you want in version
300control but don't want Crush to consider when providing context.
301
302The `.crushignore` file uses the same syntax as `.gitignore` and can be placed
303in the root of your project or in subdirectories.
304
305### Allowing Tools
306
307By default, Crush will ask you for permission before running tool calls. If
308you'd like, you can allow tools to be executed without prompting you for
309permissions. Use this with care.
310
311```json
312{
313  "$schema": "https://charm.land/crush.json",
314  "permissions": {
315    "allowed_tools": [
316      "view",
317      "ls",
318      "grep",
319      "edit",
320      "mcp_context7_get-library-doc"
321    ]
322  }
323}
324```
325
326You can also skip all permission prompts entirely by running Crush with the
327`--yolo` flag. Be very, very careful with this feature.
328
329### Attribution Settings
330
331By default, Crush adds attribution information to Git commits and pull requests
332it creates. You can customize this behavior with the `attribution` option:
333
334```json
335{
336  "$schema": "https://charm.land/crush.json",
337  "options": {
338    "attribution": {
339      "co_authored_by": true,
340      "generated_with": true
341    }
342  }
343}
344```
345
346- `co_authored_by`: When true (default), adds `Co-Authored-By: Crush <crush@charm.land>` to commit messages
347- `generated_with`: When true (default), adds `💘 Generated with Crush` line to commit messages and PR descriptions
348
349### Local Models
350
351Local models can also be configured via OpenAI-compatible API. Here are two common examples:
352
353#### Ollama
354
355```json
356{
357  "providers": {
358    "ollama": {
359      "name": "Ollama",
360      "base_url": "http://localhost:11434/v1/",
361      "type": "openai",
362      "models": [
363        {
364          "name": "Qwen 3 30B",
365          "id": "qwen3:30b",
366          "context_window": 256000,
367          "default_max_tokens": 20000
368        }
369      ]
370    }
371  }
372}
373```
374
375#### LM Studio
376
377```json
378{
379  "providers": {
380    "lmstudio": {
381      "name": "LM Studio",
382      "base_url": "http://localhost:1234/v1/",
383      "type": "openai",
384      "models": [
385        {
386          "name": "Qwen 3 30B",
387          "id": "qwen/qwen3-30b-a3b-2507",
388          "context_window": 256000,
389          "default_max_tokens": 20000
390        }
391      ]
392    }
393  }
394}
395```
396
397### Custom Providers
398
399Crush supports custom provider configurations for both OpenAI-compatible and
400Anthropic-compatible APIs.
401
402#### OpenAI-Compatible APIs
403
404Here’s an example configuration for Deepseek, which uses an OpenAI-compatible
405API. Don't forget to set `DEEPSEEK_API_KEY` in your environment.
406
407```json
408{
409  "$schema": "https://charm.land/crush.json",
410  "providers": {
411    "deepseek": {
412      "type": "openai",
413      "base_url": "https://api.deepseek.com/v1",
414      "api_key": "$DEEPSEEK_API_KEY",
415      "models": [
416        {
417          "id": "deepseek-chat",
418          "name": "Deepseek V3",
419          "cost_per_1m_in": 0.27,
420          "cost_per_1m_out": 1.1,
421          "cost_per_1m_in_cached": 0.07,
422          "cost_per_1m_out_cached": 1.1,
423          "context_window": 64000,
424          "default_max_tokens": 5000
425        }
426      ]
427    }
428  }
429}
430```
431
432#### Anthropic-Compatible APIs
433
434Custom Anthropic-compatible providers follow this format:
435
436```json
437{
438  "$schema": "https://charm.land/crush.json",
439  "providers": {
440    "custom-anthropic": {
441      "type": "anthropic",
442      "base_url": "https://api.anthropic.com/v1",
443      "api_key": "$ANTHROPIC_API_KEY",
444      "extra_headers": {
445        "anthropic-version": "2023-06-01"
446      },
447      "models": [
448        {
449          "id": "claude-sonnet-4-20250514",
450          "name": "Claude Sonnet 4",
451          "cost_per_1m_in": 3,
452          "cost_per_1m_out": 15,
453          "cost_per_1m_in_cached": 3.75,
454          "cost_per_1m_out_cached": 0.3,
455          "context_window": 200000,
456          "default_max_tokens": 50000,
457          "can_reason": true,
458          "supports_attachments": true
459        }
460      ]
461    }
462  }
463}
464```
465
466### Amazon Bedrock
467
468Crush currently supports running Anthropic models through Bedrock, with caching disabled.
469
470- A Bedrock provider will appear once you have AWS configured, i.e. `aws configure`
471- Crush also expects the `AWS_REGION` or `AWS_DEFAULT_REGION` to be set
472- To use a specific AWS profile set `AWS_PROFILE` in your environment, i.e. `AWS_PROFILE=myprofile crush`
473
474### Vertex AI Platform
475
476Vertex AI will appear in the list of available providers when `VERTEXAI_PROJECT` and `VERTEXAI_LOCATION` are set. You will also need to be authenticated:
477
478```bash
479gcloud auth application-default login
480```
481
482To add specific models to the configuration, configure as such:
483
484```json
485{
486  "$schema": "https://charm.land/crush.json",
487  "providers": {
488    "vertexai": {
489      "models": [
490        {
491          "id": "claude-sonnet-4@20250514",
492          "name": "VertexAI Sonnet 4",
493          "cost_per_1m_in": 3,
494          "cost_per_1m_out": 15,
495          "cost_per_1m_in_cached": 3.75,
496          "cost_per_1m_out_cached": 0.3,
497          "context_window": 200000,
498          "default_max_tokens": 50000,
499          "can_reason": true,
500          "supports_attachments": true
501        }
502      ]
503    }
504  }
505}
506```
507
508## Logging
509
510Sometimes you need to look at logs. Luckily, Crush logs all sorts of
511stuff. Logs are stored in `./.crush/logs/crush.log` relative to the project.
512
513The CLI also contains some helper commands to make perusing recent logs easier:
514
515```bash
516# Print the last 1000 lines
517crush logs
518
519# Print the last 500 lines
520crush logs --tail 500
521
522# Follow logs in real time
523crush logs --follow
524```
525
526Want more logging? Run `crush` with the `--debug` flag, or enable it in the
527config:
528
529```json
530{
531  "$schema": "https://charm.land/crush.json",
532  "options": {
533    "debug": true,
534    "debug_lsp": true
535  }
536}
537```
538
539## Disabling Provider Auto-Updates
540
541By default, Crush automatically checks for the latest and greatest list of
542providers and models from [Catwalk](https://github.com/charmbracelet/catwalk),
543the open source Crush provider database. This means that when new providers and
544models are available, or when model metadata changes, Crush automatically
545updates your local configuration.
546
547For those with restricted internet access, or those who prefer to work in
548air-gapped environments, this might not be want you want, and this feature can
549be disabled.
550
551To disable automatic provider updates, set `disable_provider_auto_update` into
552your `crush.json` config:
553
554```json
555{
556  "$schema": "https://charm.land/crush.json",
557  "options": {
558    "disable_provider_auto_update": true
559  }
560}
561```
562
563Or set the `CRUSH_DISABLE_PROVIDER_AUTO_UPDATE` environment variable:
564
565```bash
566export CRUSH_DISABLE_PROVIDER_AUTO_UPDATE=1
567```
568
569### Manually updating providers
570
571Manually updating providers is possible with the `crush update-providers`
572command:
573
574```bash
575# Update providers remotely from Catwalk.
576crush update-providers
577
578# Update providers from a custom Catwalk base URL.
579crush update-providers https://example.com/
580
581# Update providers from a local file.
582crush update-providers /path/to/local-providers.json
583
584# Reset providers to the embedded version, embedded at crush at build time.
585crush update-providers embedded
586
587# For more info:
588crush update-providers --help
589```
590
591## A Note on Claude Max and GitHub Copilot
592
593Crush only supports model providers through official, compliant APIs. We do not
594support or endorse any methods that rely on personal Claude Max and GitHub
595Copilot accounts or OAuth workarounds, which violate Anthropic and
596Microsoft’s Terms of Service.
597
598We’re committed to building sustainable, trusted integrations with model
599providers. If you’re a provider interested in working with us,
600[reach out](mailto:vt100@charm.sh).
601
602## Contributing
603
604See the [contributing guide](https://github.com/charmbracelet/crush?tab=contributing-ov-file#contributing).
605
606## Whatcha think?
607
608We’d love to hear your thoughts on this project. Need help? We gotchu. You can find us on:
609
610- [Twitter](https://twitter.com/charmcli)
611- [Discord][discord]
612- [Slack](https://charm.land/slack)
613- [The Fediverse](https://mastodon.social/@charmcli)
614- [Bluesky](https://bsky.app/profile/charm.land)
615
616[discord]: https://charm.land/discord
617
618## License
619
620[FSL-1.1-MIT](https://github.com/charmbracelet/crush/raw/main/LICENSE.md)
621
622---
623
624Part of [Charm](https://charm.land).
625
626<a href="https://charm.land/"><img alt="The Charm logo" width="400" src="https://stuff.charm.sh/charm-banner-next.jpg" /></a>
627
628<!--prettier-ignore-->
629Charm热爱开源 • Charm loves open source