Skip to content

Glob search uses 100% of CPU #5220

Closed as not planned
Closed as not planned

Description

@ArmoredBear

Description

Everytime i use opencode to do something on my system, regarless of what it is, if it needs to search for a file it uses glob, or the RG process. This uses 100% of my CPU, i dont know why.

OpenCode version

OpenCode 1.0.134

Steps to reproduce

1-Open opencode.
2-Ask to search and open or edit a file
3-It uses Glob for the task
4-Using btop as a task manager a RG process appears and uses 100% of CPU.

Screenshot and/or share link

No response

Operating System

Im using Garuda Linux

Terminal

Cool Retro Term or Kitty Terminal

Activity

  1. added
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Dec 8, 2025
  2. github-actions commented on Dec 8, 2025

    @github-actions
    Contributor

    This issue might be a duplicate of existing performance-related issues. Please check:

    These issues describe similar symptoms of excessive CPU usage in OpenCode. Feel free to check if any of these address your specific case or if yours is a distinct issue with the glob/RG process specifically.

  3. removed
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Dec 8, 2025
  4. added
    perfIndicates a performance issue or need for optimization
    on Dec 8, 2025
  5. ry2009 commented on Dec 9, 2025

    @ry2009
    Contributor

    @ArmoredBear @rekram1-node a couple questions on the topic:

    • Does CPU stay at 100% for several seconds, or is it just a brief spike? Rough duration?
    • What are the biggest directories in the repo (e.g., node_modules, .cache, vendor, build/output dirs)?
    • Please run from project root and share outputs:
      • time rg --files --hidden --glob '!.git/*'
      • find . -maxdepth 3 | wc -l
    • Which task triggered it (/read, /open, /edit, etc.), and the exact prompt if possible?

    I also have an open PR if you have time you can checkout into it and see if it solves (its a mitigation rn instead of perf fix bc there could be many ways to take this deep dive): #5266

  6. ArmoredBear commented on Dec 9, 2025

    @ArmoredBear
    Author

    Its not a spike, or for several seconds, when i tell opencode using grok code fast to search for a file it does recursively and keeps my CPU at 100% until either a ask it to stop, kill opencode or restart my computer! Most of the time i need to restart my computer!

    There is no exact prompt, when i simply tell opencode to edit a file and add some text or search for something and open this happens! And its random! sometime s it happens and when it does opencode hangs, as like its thinking and nothing happens for a long time and then CPU its a 100%. then i kill it or restar my computer and then it does not happen again for some time, but its very frequent. Like for 5 prompts 3 of them happen.

  7. ry2009 commented on Dec 9, 2025

    @ry2009
    Contributor

    @ArmoredBear
    I am taking a deep dive into the CPU/glob I might have found the issue but I cannot reproduce this on my side for some reason so I am wondering if you can checkout into my open PR and still see if you reproduce the errors from your side.

    Please at your earliest chance try and checkout into branch feat/glob-cpu-cap and run your normal ‘search/open/edit’ flow. Do you still get sustained 100% CPU? If yes, did you enable follow?If so disable it and try again. If it only happens with follow, I’ll ship a safe follow implementation next. How big of a codebase are you searching / any patterns like "" / "/*" in parallel?

    Where I think error is in --follow tag(symlink looping):
    https://unix.stackexchange.com/questions/99159/is-there-an-algorithm-to-decide-if-a-symlink-loops
    https://stackoverflow.com/questions/14569390/why-do-i-have-an-infinite-recursion-loop-happening-with-these-symlinks
    nextcloud/desktop#6711

    If this is true I will not rely on rg --follow and create a walk with lstat to keep track of symlink inodes visited to not continuously loop/chase forever... however if it is not pls let me know any more info you can on this issue, ty!

  8. ArmoredBear commented on Dec 16, 2025

    @ArmoredBear
    Author

    Look, im really a beginner on this stuff, so i dont know how to do what you asking. Sorry. Im just using the tool to help me with developing a game with C#, but when i ask to search for a script or file the problem keeps happening, ill tell you that it only happens when Glob, RipGrep or Grep are used, in which checking for usage of CPU using btop on my terminal it shows RG process consuming 100% of CPU and does not stop until i kill the process, basically every time i need to use the tool i need to specify for it to not use anything that uses rg process. Now, the commands "list" and "find" when not using rg process get a bit slow on the search itself which is fine by me, but it does not lag anything and does not use 100% of CPU. Also, when rg is used the tool hangs and does nothing for a long period of time, then stops, does not find what i want and CPU keeps at 100%. Sorry i will not be able to do what you want, so i hope this information will help you

  9. jchan1e commented on Dec 19, 2025

    @jchan1e

    I'm having the same issue. I don't think it's finding a symlink loop, because there are no symlinks in the project directory I was testing in. I asked it to search for any documentation in a folder with only a couple of python files in it and no subdirectories. It executed *Glob "path/to/project/**/*.md" and then hung there indefinitely while fully utilizing 12 threads. When I killed the rg process, OpenCode immediately re-executed the tool with the same wildcards in the path and the result was the same 1200% process utilization hanging indefinitely. I'm not able to reproduce this behavior using the ripgrep tool itself from the terminal, but I haven't tried exhausting all possible permutations of options and conditions.

  10. rekram1-node commented on Dec 19, 2025

    @rekram1-node
    Contributor

    what os?

  11. jchan1e commented on Dec 19, 2025

    @jchan1e

    I'm on Ubuntu Studio 25.10. I installed OpenCode via the bash script. It reports itself as version 1.0.170. I haven't changed the config files from the default except to add a self-hosted model endpoint.

  12. 3 remaining items

  13. PhilippPolterauer commented on Jan 8, 2026

    @PhilippPolterauer

    same on my machine
    Windows 11, wsl ubuntu 24.04
    Image
    some AIs call a very generic blob, and i have a node_modules folder with many files. which i think is the reason it is so slow.

    Image

    maybe the harness could put a reasonable (configurable) timeout on the glob command, e.g. 1 sec or similar

  14. Material-Scientist commented on Jan 9, 2026

    @Material-Scientist

    Same here. I even tried restricting its permissions, but it ignores those:

      "permission": {
        "glob": {
          "*": "deny",
          "pattern=/root/.local/share/opencode/storage/projects/*": "allow"
        }
      }

    It always tries to do pattern=**/* and CPU use goes to 100% and hangs.

    This is really annoying...

    Nomad job:

    job "opencode" {
      group "opencode" {
        network {
          mode = "bridge"
          port "envoy-metrics" {}
          port "plannotator" {
            static = 9999
            to = 9999
          }
        }
        volume "opencode" {
          type            = "csi"
          read_only       = false
          source          = "opencode"
          access_mode     = "single-node-writer"
          attachment_mode = "file-system"
        }    
        constraint {
          attribute = "${attr.unique.hostname}"
          operator  = "regexp"
          value     = "SMTRL-P05"
        }
        service {
          name     = "opencode"
          port     = "3000"
          meta {
            envoy_metrics_port = "${NOMAD_HOST_PORT_envoy_metrics}" # make envoy metrics port available in Consul
          }
          tags = [
    				"traefik.http.routers.opencode.middlewares=https-headers@file",
          ]
          connect {
            sidecar_service {
              proxy {
                transparent_proxy {
                  exclude_outbound_ports = [53,8600,443]
                  exclude_outbound_cidrs = ["172.26.64.0/20","127.0.0.0/8"]
                }
                expose {
                  path {
                    path = "/metrics"
                    protocol = "http"
                    local_path_port = 9102
                    listener_port = "envoy-metrics"
                  }
                }
              }
            }
          }
          check {
            expose = true
            type     = "http"
            path     = "/global/health"
            interval = "15s"
            timeout  = "1s"
          }
        }
        task "opencode" {
          driver = "docker"
          config {
            image = "ghcr.io/anomalyco/opencode" # latest
            command = "web"
            args = [
              "--port=3000",
              "--hostname=0.0.0.0",
              "--print-logs",
              "--log-level=DEBUG"
              #"--mdns=true"
            ]
            volumes = [
              "local/custom-config.json:/root/.config/opencode/opencode.json",
              "local/AGENTS.md:/root/.config/opencode/AGENTS.md",
            ]
            work_dir = "/root/.local/share/opencode/storage/projects"
          }
          volume_mount {
            volume      = "opencode"
            destination = "/root/.local/share/opencode/storage"
            read_only = false
          }      
          resources {
            cpu = 1024
            memory = 1024
            memory_max = 4096
          }
          template {
            destination = "local/custom-config.json"
            data = <<EOH
    {
      "$schema": "https://opencode.ai/config.json",
      "plugin": ["@plannotator/opencode@latest"],
    	"mcp": {
        "web": {
          "type": "remote",
          "url": "http://n8n.virtual.consul/mcp/8cc2af19-111a-45a5-a282-1548f1ea2892",
          "enabled": true
        }
      },
      "permission": {
        "edit": {
          "*": "deny",
          "/root/.local/share/opencode/storage/projects/*": "allow"
        },
        "glob": {
          "*": "deny",
          "pattern=/root/.local/share/opencode/storage/projects/*": "allow"
        },
        "list": {
          "*": "deny",
          "/root/.local/share/opencode/storage/projects/*": "allow"
        },
        "write": {
          "*": "deny",
          "/root/.local/share/opencode/storage/projects/*": "allow"
        }
      },
      "provider": {
        "llama.cpp": {
          "npm": "@ai-sdk/openai-compatible",
          "name": "llama-server (local)",
          "options": {
            "baseURL": "http://local-ai.virtual.consul/v1"
          },
          "models": {
            "gpt-oss-120b-GGUF": {
              "id": "gpt-oss-120b-GGUF",
              "name": "gpt-oss-120b-GGUF",
              "tool_call": true,
              "reasoning": true,
              "limit": {
                "context": 128000,
                "output": 128000
              }
            },
    				"Qwen3-8B-128k-GGUF": {
              "id": "Qwen3-8B-128k-GGUF",
              "name": "Qwen3-8B-128k-GGUF",
              "tool_call": true,
              "reasoning": false,
              "limit": {
                "context": 128000,
                "output": 128000
              }
            },
          }
        }
      },
      "model": "llama-server/gpt-oss-120b-GGUF",
      "agent": {
        "build": {
          "description": "Default coding mode with only Opencode tools.",
          "tools": {
            "read": true,
            "write": true,
            "edit": true,
            "bash": true,
            "grep": true,
            "glob": false,
            "list": true,
            "webfetch": false,
            "patch": true,
            "todoread": true,
            "todowrite": true,
            "submit_plan": true
          },
          "prompt": "{file:./AGENTS.md}"
        }
      },
      "instructions": ["AGENTS.md"]
    }        
    EOH        
          }
          template {
            destination = "local/AGENTS.md"
            data = <<EOH
    # Tooling rules for Opencode
    - Use Opencode tools only: read, write, edit, list, glob, grep, webfetch, bash, task, todowrite, todoread, submit_plan.
    - Do NOT call non-existent tools like Repo_browser.*.
    - Prefer `edit` for modifying existing files; use `read` to inspect before editing.
    - For any search engine queries, and extracting specific info from pages, utilize the web MCP server.
    EOH        
          }
          template {
            destination = "secrets/.env"
            env = true
            data = <<EOH
    PLANNOTATOR_PORT=9999
    PLANNOTATOR_REMOTE=1
    #OPENCODE_CONFIG=/path/to/my/custom-config.json
    #HTTPS_PROXY=http://username:{{ key "secrets/firecrawl/proxy.pw" }}@192.168.178.87:3128
    #https_proxy=http://username:{{ key "secrets/firecrawl/proxy.pw" }}@192.168.178.87:3128        
    EOH
          }
        }
      }
    }
  15. 7ac9d42 commented on Jan 10, 2026

    @7ac9d42

    I also encountered this issue, where the rg process completely saturated the CPU for up to 20 minutes, forcing me to manually kill the process.
    rg is invoked using the command:
    /usr/bin/rg --files --glob=!.git/* --follow --hidden --glob=**/*hypr*log*.
    The call chain is:
    systemd (pid 1) → bash (pid 6127) → kitty (pid 6128) → fish (pid 83468) → opencode (pid 83603) → rg (pid 96123).
    Can I mitigate this issue through some configuration?
    Using archlinux opencode 1.1.12

  16. Cynary commented on Jan 13, 2026

    @Cynary

    I've been hitting this frequently - the agent completely hangs waiting for rg while rg takes up 1000% CPU :/ I feel like it's looking for patterns in places with a lot of files (for example, latest one hit while it was looking in .cache) - maybe just having a limit on how many files it can search, or a timeout would be enough of a fix?

    ...

    and 1 minute after I posted this it did it again :/
    globbing in .local/share , .cache, and .local/state

  17. troychn commented on Jan 18, 2026

    @troychn

    Title
    High CPU usage caused by stuck rg processes when performing search-related operations

    Description
    I'm experiencing a similar issue. When I ask OpenCode to perform any search-related task, multiple rg (ripgrep) processes spawn and consume extremely high CPU resources. These processes run indefinitely without completing, and OpenCode becomes completely unresponsive.
    The only way to recover is to manually force-kill the rg processes.
    Environment

    • OS: macOS
    • OpenCode version: v1.1.25
      Steps to Reproduce
    1. Start OpenCode
    2. Ask the assistant to perform any search-related operation (e.g., searching for files, finding code patterns, exploring the codebase)
    3. Observe system processes
      Expected Behavior
      The rg processes should complete in a reasonable time and return results to OpenCode.
      Actual Behavior
    • Multiple rg processes appear in the process list
    • CPU usage spikes to very high levels
    • The rg processes run indefinitely and never terminate
    • OpenCode UI becomes unresponsive
    • Manual termination of the rg processes is required to regain control
      Additional Context
      This issue seems to be related to the ripgrep subprocess not properly terminating or hitting some edge case that causes it to hang.
  18. alexeydubinin commented on Jan 18, 2026

    @alexeydubinin

    Same on macOS. killall rg works as a quick fix. Unfortunately, OpenCode has become unusable for me.

  19. ry2009 commented on Jan 18, 2026

    @ry2009
    Contributor

    @alexeydubinin @troychn and anyone else that can and is willing to test it out, this perf issue is very hard to replicate/see but I have once again tried to resolve it... if you can see if you can replicate it on my PR/branch (or hopefully not) that would be wonderful my version should be up to date with most recent OC commit -- check it out here: #9220

  20. alexeydubinin commented on Jan 18, 2026

    @alexeydubinin

    @ry2009 I checked the same prompt with Codex, and all rg calls were performed without the --hidden and --follow flags.

  21. Newbbsss commented on Jan 28, 2026

    @Newbbsss

    @ArmoredBear I am taking a deep dive into the CPU/glob I might have found the issue but I cannot reproduce this on my side for some reason so I am wondering if you can checkout into my open PR and still see if you reproduce the errors from your side.

    Please at your earliest chance try and checkout into branch feat/glob-cpu-cap and run your normal ‘search/open/edit’ flow. Do you still get sustained 100% CPU? If yes, did you enable follow?If so disable it and try again. If it only happens with follow, I’ll ship a safe follow implementation next. How big of a codebase are you searching / any patterns like "" / "/*" in parallel?

    Where I think error is in --follow tag(symlink looping): https://unix.stackexchange.com/questions/99159/is-there-an-algorithm-to-decide-if-a-symlink-loops https://stackoverflow.com/questions/14569390/why-do-i-have-an-infinite-recursion-loop-happening-with-these-symlinks nextcloud/desktop#6711

    If this is true I will not rely on rg --follow and create a walk with lstat to keep track of symlink inodes visited to not continuously loop/chase forever... however if it is not pls let me know any more info you can on this issue, ty!

    Use kimi k2 and ask it to glob something on your machine even after session closes the cpu usage is still high

  22. konovalov-nk commented on Jan 31, 2026

    @konovalov-nk

    Please read this comment

  23. ArmoredBear commented on Mar 18, 2026

    @ArmoredBear
    Author

    I think i found a fix, i dont know if this will interfere with the OpenCode functionality but it seems to be a bash-language-server issue

    This seems fo fixt it, i dont know if its temporary or not

    `

    OpenCode CPU Issue - Bash LSP Server Fix

    Problem

    When using opencode, CPU would spike to 100% due to the bash-language-server process getting stuck in a runaway loop (reaching 388% CPU).

    Root Cause

    OpenCode automatically enables the bash LSP server for bash scripts. The bash-language-server was getting stuck in an infinite loop, causing excessive CPU usage.

    Solution

    Disabled the bash LSP server in the opencode configuration.

    Files Modified

    1. /home/arthurgf/.config/opencode/opencode.json

    Created new config file with:

    {
      "$schema": "https://opencode.ai/config.json",
      "lsp": {
        "bash": {
          "disabled": true
        }
      }
    }

    2. /home/arthurgf/UserScripts/opencode.config.json

    Added LSP config to existing config:

    {
      "disable_glob_search": true,
      "disable_ripgrep": true,
      "lsp": {
        "bash": {
          "disabled": true
        }
      }
    }

    Verification

    • Before fix: bash-language-server using 388% CPU
    • After fix: CPU usage normal (~10% from opencode process itself)

    Date

    2026-03-18
    `

    Hope it helps though

    EDIT: I also dont know if will work on every system.

    My way to try to fix it was opening a new session and telling OpenCode i had an issue with my CPU, it used glob to try to verify files, errors and problems. I stoped it with Esc and told CPU usage was high, then it found the issue with bash-langauge-server and made config files edits and now the problem seems fixed, im still testing it though.

  24. removed
    bugSomething isn't working
    perfIndicates a performance issue or need for optimization
    on May 3, 2026
  25. rekram1-node commented on May 22, 2026

    @rekram1-node
    Contributor

    LSPs are also disabled by default now

    closing since this is stale

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions