README.md

  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| `AWS_PROFILE`               | Custom AWS Profile                                 |
192| `AWS_REGION`                | AWS Region                                         |
193| `AZURE_OPENAI_API_ENDPOINT` | Azure OpenAI models                                |
194| `AZURE_OPENAI_API_KEY`      | Azure OpenAI models (optional when using Entra ID) |
195| `AZURE_OPENAI_API_VERSION`  | Azure OpenAI models                                |
196
197### By the Way
198
199Is there a provider you’d like to see in Crush? Is there an existing model that needs an update?
200
201Crush’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.
202
203<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>
204
205## Configuration
206
207Crush runs great with no configuration. That said, if you do need or want to
208customize Crush, configuration can be added either local to the project itself,
209or globally, with the following priority:
210
2111. `.crush.json`
2122. `crush.json`
2133. `$HOME/.config/crush/crush.json` (Windows: `%USERPROFILE%\AppData\Local\crush\crush.json`)
214
215Configuration itself is stored as a JSON object:
216
217```json
218{
219  "this-setting": { "this": "that" },
220  "that-setting": ["ceci", "cela"]
221}
222```
223
224As an additional note, Crush also stores ephemeral data, such as application state, in one additional location:
225
226```bash
227# Unix
228$HOME/.local/share/crush/crush.json
229
230# Windows
231%LOCALAPPDATA%\crush\crush.json
232```
233
234### LSPs
235
236Crush can use LSPs for additional context to help inform its decisions, just
237like you would. LSPs can be added manually like so:
238
239```json
240{
241  "$schema": "https://charm.land/crush.json",
242  "lsp": {
243    "go": {
244      "command": "gopls",
245      "env": {
246        "GOTOOLCHAIN": "go1.24.5"
247      }
248    },
249    "typescript": {
250      "command": "typescript-language-server",
251      "args": ["--stdio"]
252    },
253    "nix": {
254      "command": "nil"
255    }
256  }
257}
258```
259
260### MCPs
261
262Crush also supports Model Context Protocol (MCP) servers through three
263transport types: `stdio` for command-line servers, `http` for HTTP endpoints,
264and `sse` for Server-Sent Events. Environment variable expansion is supported
265using `$(echo $VAR)` syntax.
266
267```json
268{
269  "$schema": "https://charm.land/crush.json",
270  "mcp": {
271    "filesystem": {
272      "type": "stdio",
273      "command": "node",
274      "args": ["/path/to/mcp-server.js"],
275      "env": {
276        "NODE_ENV": "production"
277      }
278    },
279    "github": {
280      "type": "http",
281      "url": "https://example.com/mcp/",
282      "headers": {
283        "Authorization": "$(echo Bearer $EXAMPLE_MCP_TOKEN)"
284      }
285    },
286    "streaming-service": {
287      "type": "sse",
288      "url": "https://example.com/mcp/sse",
289      "headers": {
290        "API-Key": "$(echo $API_KEY)"
291      }
292    }
293  }
294}
295```
296
297### Ignoring Files
298
299Crush respects `.gitignore` files by default, but you can also create a
300`.crushignore` file to specify additional files and directories that Crush
301should ignore. This is useful for excluding files that you want in version
302control but don't want Crush to consider when providing context.
303
304The `.crushignore` file uses the same syntax as `.gitignore` and can be placed
305in the root of your project or in subdirectories.
306
307### Allowing Tools
308
309By default, Crush will ask you for permission before running tool calls. If
310you'd like, you can allow tools to be executed without prompting you for
311permissions. Use this with care.
312
313```json
314{
315  "$schema": "https://charm.land/crush.json",
316  "permissions": {
317    "allowed_tools": [
318      "view",
319      "ls",
320      "grep",
321      "edit",
322      "mcp_context7_get-library-doc"
323    ]
324  }
325}
326```
327
328You can also skip all permission prompts entirely by running Crush with the
329`--yolo` flag. Be very, very careful with this feature.
330
331### Attribution Settings
332
333By default, Crush adds attribution information to Git commits and pull requests
334it creates. You can customize this behavior with the `attribution` option:
335
336```json
337{
338  "$schema": "https://charm.land/crush.json",
339  "options": {
340    "attribution": {
341      "co_authored_by": true,
342      "generated_with": true
343    }
344  }
345}
346```
347
348- `co_authored_by`: When true (default), adds `Co-Authored-By: Crush <crush@charm.land>` to commit messages
349- `generated_with`: When true (default), adds `💘 Generated with Crush` line to commit messages and PR descriptions
350
351### Local Models
352
353Local models can also be configured via OpenAI-compatible API. Here are two common examples:
354
355#### Ollama
356
357```json
358{
359  "providers": {
360    "ollama": {
361      "name": "Ollama",
362      "base_url": "http://localhost:11434/v1/",
363      "type": "openai",
364      "models": [
365        {
366          "name": "Qwen 3 30B",
367          "id": "qwen3:30b",
368          "context_window": 256000,
369          "default_max_tokens": 20000
370        }
371      ]
372    }
373  }
374}
375```
376
377#### LM Studio
378
379```json
380{
381  "providers": {
382    "lmstudio": {
383      "name": "LM Studio",
384      "base_url": "http://localhost:1234/v1/",
385      "type": "openai",
386      "models": [
387        {
388          "name": "Qwen 3 30B",
389          "id": "qwen/qwen3-30b-a3b-2507",
390          "context_window": 256000,
391          "default_max_tokens": 20000
392        }
393      ]
394    }
395  }
396}
397```
398
399### Custom Providers
400
401Crush supports custom provider configurations for both OpenAI-compatible and
402Anthropic-compatible APIs.
403
404#### OpenAI-Compatible APIs
405
406Here’s an example configuration for Deepseek, which uses an OpenAI-compatible
407API. Don't forget to set `DEEPSEEK_API_KEY` in your environment.
408
409```json
410{
411  "$schema": "https://charm.land/crush.json",
412  "providers": {
413    "deepseek": {
414      "type": "openai",
415      "base_url": "https://api.deepseek.com/v1",
416      "api_key": "$DEEPSEEK_API_KEY",
417      "models": [
418        {
419          "id": "deepseek-chat",
420          "name": "Deepseek V3",
421          "cost_per_1m_in": 0.27,
422          "cost_per_1m_out": 1.1,
423          "cost_per_1m_in_cached": 0.07,
424          "cost_per_1m_out_cached": 1.1,
425          "context_window": 64000,
426          "default_max_tokens": 5000
427        }
428      ]
429    }
430  }
431}
432```
433
434#### Anthropic-Compatible APIs
435
436Custom Anthropic-compatible providers follow this format:
437
438```json
439{
440  "$schema": "https://charm.land/crush.json",
441  "providers": {
442    "custom-anthropic": {
443      "type": "anthropic",
444      "base_url": "https://api.anthropic.com/v1",
445      "api_key": "$ANTHROPIC_API_KEY",
446      "extra_headers": {
447        "anthropic-version": "2023-06-01"
448      },
449      "models": [
450        {
451          "id": "claude-sonnet-4-20250514",
452          "name": "Claude Sonnet 4",
453          "cost_per_1m_in": 3,
454          "cost_per_1m_out": 15,
455          "cost_per_1m_in_cached": 3.75,
456          "cost_per_1m_out_cached": 0.3,
457          "context_window": 200000,
458          "default_max_tokens": 50000,
459          "can_reason": true,
460          "supports_attachments": true
461        }
462      ]
463    }
464  }
465}
466```
467
468### Amazon Bedrock
469
470Crush currently supports running Anthropic models through Bedrock, with caching disabled.
471
472- A Bedrock provider will appear once you have AWS configured, i.e. `aws configure`
473- Crush also expects the `AWS_REGION` or `AWS_DEFAULT_REGION` to be set
474- To use a specific AWS profile set `AWS_PROFILE` in your environment, i.e. `AWS_PROFILE=myprofile crush`
475
476### Vertex AI Platform
477
478Vertex AI will appear in the list of available providers when `VERTEXAI_PROJECT` and `VERTEXAI_LOCATION` are set. You will also need to be authenticated:
479
480```bash
481gcloud auth application-default login
482```
483
484To add specific models to the configuration, configure as such:
485
486```json
487{
488  "$schema": "https://charm.land/crush.json",
489  "providers": {
490    "vertexai": {
491      "models": [
492        {
493          "id": "claude-sonnet-4@20250514",
494          "name": "VertexAI Sonnet 4",
495          "cost_per_1m_in": 3,
496          "cost_per_1m_out": 15,
497          "cost_per_1m_in_cached": 3.75,
498          "cost_per_1m_out_cached": 0.3,
499          "context_window": 200000,
500          "default_max_tokens": 50000,
501          "can_reason": true,
502          "supports_attachments": true
503        }
504      ]
505    }
506  }
507}
508```
509
510## Logging
511
512Sometimes you need to look at logs. Luckily, Crush logs all sorts of
513stuff. Logs are stored in `./.crush/logs/crush.log` relative to the project.
514
515The CLI also contains some helper commands to make perusing recent logs easier:
516
517```bash
518# Print the last 1000 lines
519crush logs
520
521# Print the last 500 lines
522crush logs --tail 500
523
524# Follow logs in real time
525crush logs --follow
526```
527
528Want more logging? Run `crush` with the `--debug` flag, or enable it in the
529config:
530
531```json
532{
533  "$schema": "https://charm.land/crush.json",
534  "options": {
535    "debug": true,
536    "debug_lsp": true
537  }
538}
539```
540
541## Disabling Provider Auto-Updates
542
543By default, Crush automatically checks for the latest and greatest list of
544providers and models from [Catwalk](https://github.com/charmbracelet/catwalk),
545the open source Crush provider database. This means that when new providers and
546models are available, or when model metadata changes, Crush automatically
547updates your local configuration.
548
549For those with restricted internet access, or those who prefer to work in
550air-gapped environments, this might not be want you want, and this feature can
551be disabled.
552
553To disable automatic provider updates, set `disable_provider_auto_update` into
554your `crush.json` config:
555
556```json
557{
558  "$schema": "https://charm.land/crush.json",
559  "options": {
560    "disable_provider_auto_update": true
561  }
562}
563```
564
565Or set the `CRUSH_DISABLE_PROVIDER_AUTO_UPDATE` environment variable:
566
567```bash
568export CRUSH_DISABLE_PROVIDER_AUTO_UPDATE=1
569```
570
571### Manually updating providers
572
573Manually updating providers is possible with the `crush update-providers`
574command:
575
576```bash
577# Update providers remotely from Catwalk.
578crush update-providers
579
580# Update providers from a custom Catwalk base URL.
581crush update-providers https://example.com/
582
583# Update providers from a local file.
584crush update-providers /path/to/local-providers.json
585
586# Reset providers to the embedded version, embedded at crush at build time.
587crush update-providers embedded
588
589# For more info:
590crush update-providers --help
591```
592
593## A Note on Claude Max and GitHub Copilot
594
595Crush only supports model providers through official, compliant APIs. We do not
596support or endorse any methods that rely on personal Claude Max and GitHub
597Copilot accounts or OAuth workarounds, which violate Anthropic and
598Microsoft’s Terms of Service.
599
600We’re committed to building sustainable, trusted integrations with model
601providers. If you’re a provider interested in working with us,
602[reach out](mailto:vt100@charm.sh).
603
604## Contributing
605
606See the [contributing guide](https://github.com/charmbracelet/crush?tab=contributing-ov-file#contributing).
607
608## Whatcha think?
609
610We’d love to hear your thoughts on this project. Need help? We gotchu. You can find us on:
611
612- [Twitter](https://twitter.com/charmcli)
613- [Discord][discord]
614- [Slack](https://charm.land/slack)
615- [The Fediverse](https://mastodon.social/@charmcli)
616- [Bluesky](https://bsky.app/profile/charm.land)
617
618[discord]: https://charm.land/discord
619
620## License
621
622[FSL-1.1-MIT](https://github.com/charmbracelet/crush/raw/main/LICENSE.md)
623
624---
625
626Part of [Charm](https://charm.land).
627
628<a href="https://charm.land/"><img alt="The Charm logo" width="400" src="https://stuff.charm.sh/charm-banner-next.jpg" /></a>
629
630<!--prettier-ignore-->
631Charm热爱开源 • Charm loves open source