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