{
  "kind": "recipe",
  "id": "code",
  "title": "A coding helper",
  "what": "An assistant that reads and edits your code.",
  "html": "https://insidethemachine.ai/do/code",
  "md": "https://insidethemachine.ai/do/code.md",
  "json": "https://insidethemachine.ai/do/code.json",
  "memory": {
    "min_gb": 16,
    "good_gb": 32
  },
  "minutes": 15,
  "platform_priority": [
    "macos-apple-silicon",
    "linux",
    "windows"
  ],
  "tools": [
    {
      "slug": "ollama",
      "name": "Ollama",
      "md": "https://insidethemachine.ai/setups/ollama.md"
    },
    {
      "slug": "opencode",
      "name": "OpenCode",
      "md": "https://insidethemachine.ai/setups/opencode.md"
    },
    {
      "slug": "aider",
      "name": "Aider",
      "md": "https://insidethemachine.ai/setups/aider.md"
    }
  ],
  "placeholders": {
    "{MODEL}": "ollama tag from model_by_memory_gb for the machine's RAM",
    "{WHISPER}": null
  },
  "model_by_memory_gb": {
    "8": {
      "name": "Qwen3.5 4B",
      "tag": "qwen3.5:4b",
      "gb": 5.8,
      "aa": 13.1,
      "maker": "Alibaba Qwen"
    },
    "16": {
      "name": "Ornith 1.5 9B",
      "tag": "ornith-1.5:9b",
      "gb": 8.8,
      "aa": null,
      "maker": "Ornith AI"
    },
    "24": {
      "name": "Gemma 4 12B",
      "tag": "gemma4:12b",
      "gb": 11.2,
      "aa": 14.2,
      "maker": "Google"
    },
    "32": {
      "name": "Qwen3.8 27B",
      "tag": "qwen3.8:27b",
      "gb": 22.7,
      "aa": 33.7,
      "maker": "Alibaba Qwen"
    },
    "48": {
      "name": "Qwen3.8 27B",
      "tag": "qwen3.8:27b",
      "gb": 22.7,
      "aa": 33.7,
      "maker": "Alibaba Qwen"
    },
    "64": {
      "name": "Qwen3.8 27B",
      "tag": "qwen3.8:27b",
      "gb": 22.7,
      "aa": 33.7,
      "maker": "Alibaba Qwen"
    },
    "96": {
      "name": "Qwen3.8 27B",
      "tag": "qwen3.8:27b",
      "gb": 22.7,
      "aa": 33.7,
      "maker": "Alibaba Qwen"
    },
    "128": {
      "name": "Qwen3.8 27B",
      "tag": "qwen3.8:27b",
      "gb": 22.7,
      "aa": 33.7,
      "maker": "Alibaba Qwen"
    },
    "192": {
      "name": "Qwen3.8-Flash-Next (125B-A6B)",
      "tag": "qwen3.8-flash-next:125b-a6b",
      "gb": 140,
      "aa": 39.8,
      "maker": "Alibaba Qwen"
    },
    "256": {
      "name": "Qwen3.8-Flash-Next (125B-A6B)",
      "tag": "qwen3.8-flash-next:125b-a6b",
      "gb": 140,
      "aa": 39.8,
      "maker": "Alibaba Qwen"
    },
    "512": {
      "name": "Qwen3.8-Flash-Next (125B-A6B)",
      "tag": "qwen3.8-flash-next:125b-a6b",
      "gb": 140,
      "aa": 39.8,
      "maker": "Alibaba Qwen"
    }
  },
  "frontier": {
    "name": "Claude Opus 5.5",
    "aa": 57.6
  },
  "tested": "The under-32 GB path (Aider) was run end to end on an Apple M4 Mac with 16 GB on 2026-10-15. The OpenCode path is checked against the docs only.",
  "recipe": {
    "id": "code",
    "get": "An AI coding agent in your Terminal that reads your project, edits files and runs commands, with changes you can undo.",
    "model": "code",
    "steps": [
      {
        "title": "Install Ollama",
        "body": "Ollama downloads AI models and runs them on your computer. Open the Terminal app and paste this. It may ask for your Mac password.",
        "cmds": [
          {
            "run": "curl -fsSL https://ollama.com/install.sh | sh",
            "note": "Or download the app from ollama.com/download"
          }
        ],
        "expect": "Run `ollama --version`. It prints a version number. If it also says “could not connect”, open Ollama from your Applications folder, wait a few seconds, then go on."
      },
      {
        "title": "Download a coding model",
        "body": "This is the AI itself. It is one big file, so it takes a few minutes.",
        "cmds": [
          {
            "run": "ollama pull {MODEL}"
          }
        ],
        "expect": "The download finishes with “success”."
      },
      {
        "title": "Give the model a long memory",
        "body": "OpenCode needs at least 64k of context (how much text the model reads at once). Quit the Ollama menu-bar app, then start Ollama like this. Leave this window open.",
        "cmds": [
          {
            "run": "OLLAMA_CONTEXT_LENGTH=64000 ollama serve"
          }
        ]
      },
      {
        "title": "Install OpenCode",
        "body": "OpenCode is the coding agent. Open a second Terminal window.",
        "cmds": [
          {
            "run": "curl -fsSL https://opencode.ai/install | bash",
            "note": "Or with Homebrew: brew install anomalyco/tap/opencode"
          }
        ],
        "expect": "Run `opencode --version`. It prints a version."
      },
      {
        "title": "Start it in your project",
        "body": "Go to your project folder, then let Ollama start OpenCode. When it asks for a model, pick {MODEL}.",
        "cmds": [
          {
            "run": "cd /path/to/your/project"
          },
          {
            "run": "ollama launch opencode"
          }
        ],
        "expect": "Ask “explain this project”. It answers about your files."
      }
    ],
    "alt": {
      "slug": "aider",
      "title": "Prefer a simpler helper? Use Aider.",
      "body": "Aider edits files and commits each change to git. It works with smaller models that cannot use tools. It has had no new release since August 2025.",
      "href": "/setups/aider"
    },
    "lowRam": {
      "under": 32,
      "why": "Under 32 GB, the models that fit cannot use tools well, and OpenCode needs tools. So this path uses Aider, which does not need them.",
      "steps": [
        {
          "title": "Install Ollama",
          "body": "Ollama downloads AI models and runs them on your computer. Open the Terminal app and paste this. It may ask for your Mac password.",
          "cmds": [
            {
              "run": "curl -fsSL https://ollama.com/install.sh | sh",
              "note": "Or download the app from ollama.com/download"
            }
          ],
          "expect": "Run `ollama --version`. It prints a version number. If it also says “could not connect”, open Ollama from your Applications folder, wait a few seconds, then go on."
        },
        {
          "title": "Download a coding model",
          "body": "This is the AI itself. It is one big file, so it takes a few minutes.",
          "cmds": [
            {
              "run": "ollama pull {MODEL}"
            }
          ],
          "expect": "The download finishes with “success”."
        },
        {
          "title": "Give the model more room",
          "body": "Code needs a longer memory than chat. Quit the Ollama menu-bar app, then start Ollama like this. Leave this window open.",
          "cmds": [
            {
              "run": "OLLAMA_CONTEXT_LENGTH=8192 ollama serve"
            }
          ]
        },
        {
          "title": "Install Aider",
          "body": "Aider is the coding helper. Open a second Terminal window. It installs with uv, a Python tool manager. Skip the first line if you already have uv.",
          "cmds": [
            {
              "run": "brew install uv",
              "note": "Needs Homebrew (brew.sh)"
            },
            {
              "run": "uv tool install --force --python python3.12 --with pip aider-chat@latest"
            }
          ],
          "expect": "Run `aider --version`. It prints a version."
        },
        {
          "title": "Start it in your project",
          "body": "Go to a project folder that uses git, then start Aider with your model.",
          "cmds": [
            {
              "run": "export OLLAMA_API_BASE=http://127.0.0.1:11434"
            },
            {
              "run": "cd /path/to/your/project"
            },
            {
              "run": "aider --model ollama_chat/{MODEL}"
            }
          ],
          "expect": "Ask “explain this project”. It answers about your files."
        }
      ],
      "alt": {
        "slug": "opencode",
        "title": "Have 32 GB or more? Use OpenCode.",
        "body": "OpenCode is the most popular open-source coding agent. It needs a model that can use tools and 64k of context, so it needs more memory.",
        "href": "/setups/opencode"
      },
      "undo": [
        {
          "run": "uv tool uninstall aider-chat",
          "note": "Removes Aider"
        },
        {
          "run": "ollama rm {MODEL}"
        }
      ],
      "win": {
        "body": "Install Ollama with this PowerShell command, or the installer from ollama.com/download. On Linux, the install command above works as it is. After that, every `ollama` command on this page is the same. In PowerShell, start Ollama with more room like this. Aider's page has its Windows steps.",
        "cmds": [
          {
            "run": "irm https://ollama.com/install.ps1 | iex",
            "note": "Windows: paste in PowerShell. Or get the installer from ollama.com/download"
          },
          {
            "run": "$env:OLLAMA_CONTEXT_LENGTH=8192; ollama serve",
            "note": "PowerShell version of step 3"
          }
        ]
      },
      "fix": [
        {
          "q": "“could not connect to ollama app, is it running?”",
          "a": "Ollama is not running. Open Ollama from your Applications folder, or run `ollama serve` in a new Terminal window and leave it open."
        },
        {
          "q": "“command not found: ollama”",
          "a": "Close the Terminal window and open a new one. If it still fails, run the install command again."
        },
        {
          "q": "“model requires more system memory”",
          "a": "The model is too big for your memory. Pick a smaller memory size at the top of this page and use that model. Close other big apps too."
        },
        {
          "q": "“file does not exist” when you download",
          "a": "The model name is wrong, or Ollama is too old. Copy the command again from this page. Then update Ollama: run the install command again."
        },
        {
          "q": "It is very slow",
          "a": "Run `ollama ps`. PROCESSOR should say 100% GPU. If it shows CPU, the model does not fit in memory. Pick a smaller model."
        },
        {
          "q": "The computer freezes, or the fan is loud",
          "a": "The model uses all your memory. Stop it with `ollama stop {MODEL}`. Then use a smaller one."
        },
        {
          "q": "A warning about “unknown context window size”",
          "a": "You can ignore it. Aider still works with your model."
        },
        {
          "q": "“aider: command not found”",
          "a": "Close the Terminal window and open a new one. If it still fails, run `uv tool update-shell` and open a new window."
        }
      ],
      "know": [
        "Check your free disk space first. You need room for the model plus about 1 GB for Aider.",
        "Local models handle small, clear tasks best. Ask for one change at a time. On a 16 GB Mac an answer took about 1 minute.",
        "Aider commits each change to git, so `/undo` takes it back.",
        "Aider has had no new release since August 2025. It still works with Ollama."
      ]
    },
    "undo": [
      {
        "run": "rm -rf ~/.opencode",
        "note": "Removes OpenCode from the install script. Also delete the line with .opencode/bin in ~/.zshrc. With Homebrew: brew uninstall opencode"
      },
      {
        "run": "ollama rm {MODEL}"
      }
    ],
    "know": [
      "Check your free disk space first. You need room for the model plus about 1 GB for OpenCode.",
      "Local models handle small, clear tasks best. Ask for one change at a time.",
      "Type `/undo` in OpenCode to take back its last change. `/redo` brings it back.",
      "If it is slow, run `ollama ps`. PROCESSOR should say 100% GPU. If not, the model and its 64k memory do not fit."
    ],
    "fix": [
      {
        "q": "“could not connect to ollama app, is it running?”",
        "a": "Ollama is not running. Open Ollama from your Applications folder, or run `ollama serve` in a new Terminal window and leave it open."
      },
      {
        "q": "“command not found: ollama”",
        "a": "Close the Terminal window and open a new one. If it still fails, run the install command again."
      },
      {
        "q": "“model requires more system memory”",
        "a": "The model is too big for your memory. Pick a smaller memory size at the top of this page and use that model. Close other big apps too."
      },
      {
        "q": "“file does not exist” when you download",
        "a": "The model name is wrong, or Ollama is too old. Copy the command again from this page. Then update Ollama: run the install command again."
      },
      {
        "q": "It is very slow",
        "a": "Run `ollama ps`. PROCESSOR should say 100% GPU. If it shows CPU, the model does not fit in memory. Pick a smaller model."
      },
      {
        "q": "The computer freezes, or the fan is loud",
        "a": "The model uses all your memory. Stop it with `ollama stop {MODEL}`. Then use a smaller one."
      },
      {
        "q": "It talks, but it does not change any files",
        "a": "The model is too small to use tools. Use a bigger model, or Aider (the box above), which does not need tools."
      },
      {
        "q": "It forgets the start of the job",
        "a": "Ollama was started without the long memory. Quit Ollama and run step 3 again."
      }
    ],
    "after": [
      "Try it: ask “explain this project”, then “add a comment to the main function”. Small, clear jobs work best.",
      "Before a big change, commit your work in git. Then you can always go back.",
      "See every model you have: `ollama list`.",
      "Try a different model: copy any `ollama run` name from the Models page.",
      "Update your model: run `ollama pull {MODEL}` again. It only downloads what changed.",
      "Free disk space: `ollama rm {MODEL}` deletes a model you no longer use."
    ],
    "win": {
      "body": "Install Ollama with this PowerShell command, or the installer from ollama.com/download. On Linux, the install command above works as it is. After that, every `ollama` command on this page is the same. In PowerShell, start Ollama with a long memory like this. OpenCode runs on Windows too; see opencode.ai/docs. Aider's page has its Windows steps.",
      "cmds": [
        {
          "run": "irm https://ollama.com/install.ps1 | iex",
          "note": "Windows: paste in PowerShell. Or get the installer from ollama.com/download"
        },
        {
          "run": "$env:OLLAMA_CONTEXT_LENGTH=64000; ollama serve",
          "note": "PowerShell version of step 3"
        }
      ]
    },
    "tested": "The under-32 GB path (Aider) was run end to end on an Apple M4 Mac with 16 GB on 2026-10-15. The OpenCode path is checked against the docs only."
  }
}