Skip to content

Instantly share code, notes, and snippets.

@cardboardcode
Last active June 13, 2026 15:17
Show Gist options
  • Select an option

  • Save cardboardcode/3391a501fc9a1066485f61dc6e06d6dc to your computer and use it in GitHub Desktop.

Select an option

Save cardboardcode/3391a501fc9a1066485f61dc6e06d6dc to your computer and use it in GitHub Desktop.
For People In A Hurry: How to Set Ollama with OpenCode for Local & Privacy-Focused Coding Agent
image

Note

This is a quick copy-paste-observe guide for people in a hurry to quickly set up a local coding agent at no additional costs using OpenCode and Ollama.

Instructions 📘

  1. Install Ollama using the command below:
curl -fsSL https://ollama.com/install.sh | sh
  1. Download ollama LLM model by using the command below:
ollama pull <model_name>
#Eg. ollama pull qwen3:8b

Warning

Note that, if you use any models with the cloud tag, it means it would not be fully local as it would be using Ollama's cloud models.

  1. Install OpenCode using the command below:
curl -fsSL https://opencode.ai/install | bash

Run

ollama launch opencode

For ease of use, you can start up opencode with models defined.

ollama launch opencode --model glm-4.7-flash:latest

Warning

To allow full autonomy of coding agent in order to speed up development, use the following bash command at your own risk:

ollama launch opencode --model glm-4.7-flash:latest

References

  1. OpenCode Installation - https://opencode.ai/
  2. Ollama Installation - https://ollama.com/
  3. Open-WebUI Installation - https://github.com/open-webui/open-webui
@cardboardcode

cardboardcode commented May 20, 2026

Copy link
Copy Markdown
Author

Fingers cramping from typing too much? 🫰

Use ollama/opencode-centric command shortcuts below by following the steps below:

  1. Edit ~/.bashrc using command below:
nano ~/.bashrc
  1. Include the following content at the end of your ~/.bashrc:
_ollama_complete() {
    local cur prev words cword
    _init_completion || return

    local models_ps models_list
    models_list=$(ollama list | awk 'NR>1 {print $1}')
    models_ps=$(ollama ps | awk 'NR>1 {print $1}')

    # Step 1: ollama
    if [[ $cword -eq 1 ]]; then
        COMPREPLY=( $(compgen -W "launch stop run" -- "$cur") )
        return
    fi

    # -------------------------
    # NEW: ollama stop <model>
    # -------------------------
    if [[ $cword -eq 2 && $prev == "stop" ]]; then
        COMPREPLY=( $(compgen -W "$models_ps" -- "$cur") )
        return
    fi

    if [[ $cword -eq 2 && $prev == "run" ]]; then
        COMPREPLY=( $(compgen -W "$models_list" -- "$cur") )
        return
    fi

    # Step 2: ollama launch
    if [[ $cword -eq 2 && $prev == "launch" ]]; then
        COMPREPLY=( $(compgen -W "opencode" -- "$cur") )
        return
    fi

    # Step 3: ollama launch <something>
    if [[ $cword -eq 3 && $prev != "--model" ]]; then
        COMPREPLY=( $(compgen -W "--model" -- "$cur") )
        return
    fi

    # Step 4: models for --model
    if [[ $prev == "--model" ]]; then
        COMPREPLY=( $(compgen -W "$models_list" -- "$cur") )
        return
    fi

    # Step 5: suggest `--` separator after model
    if [[ " ${words[*]} " != *" -- "* ]]; then
        COMPREPLY=( $(compgen -W "--" -- "$cur") )
        return
    fi

    # Step 6: AFTER `--` → suggest flags
    for ((i=0; i < ${#words[@]}; i++)); do
        if [[ "${words[i]}" == "--" ]]; then
            COMPREPLY=( $(compgen -W "--dangerously-skip-permissions" -- "$cur") )
            return
        fi
    done
}

_ollama64k_complete() {
    local cur prev words cword
    _init_completion || return

    local models_ps models_list
    models_list=$(ollama list | awk 'NR>1 {print $1}')

    if [[ $cword -eq 1 ]]; then
        COMPREPLY=( $(compgen -W "$models_list" -- "$cur") )
        return
    fi
}

ollama64k() {
    local input_model="$1"

    if [[ -z "$input_model" ]]; then
        echo "Usage: ollama64k <model>"
        return 1
    fi

    # Determine output model name
    local output_model
    if [[ "$input_model" == *":latest" ]]; then
        output_model="${input_model%:latest}:64k"
    else
        output_model="${input_model}-64k"
    fi

    # Create temporary Modelfile
    local modelfile
    modelfile="$(mktemp)"

    cat > "$modelfile" <<EOF
FROM $input_model
PARAMETER num_ctx 65536
EOF

    # Create the new model
    ollama create "$output_model" -f "$modelfile"

    # Echo result if successful
    if [[ $? -eq 0 ]]; then
        echo "Created [ $output_model ]"
    fi

    # Clean up
    rm -f "$modelfile"
}

complete -F _ollama_complete ollama

complete -F _ollama64k_complete ollama64k

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment