{"record":{"id":"3197dc2bd66d5bd1","repo":"air-verse/air","slug":"refusing-to-run-in-s-this-would-watch-too-many","errorCode":null,"errorMessage":"refusing to run in %s - this would watch too many files. Please run air in a project directory","messagePattern":"refusing to run in (.+?) - this would watch too many files\\. Please run air in a project directory","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"runner/config.go","lineNumber":654,"sourceCode":"\tif args != nil {\n\t\tc.withArgs(args)\n\t}\n\tcwd := os.Getenv(airWd)\n\tif cwd != \"\" {\n\t\tif err = os.Chdir(cwd); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tc.Root = cwd\n\t}\n\tc.Root, err = expandPath(c.Root)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// Check for dangerous root directories that could cause excessive file watching\n\tif isDangerous, dirName := isDangerousRoot(c.Root); isDangerous {\n\t\tif !c.Build.IgnoreDangerousRootDir {\n\t\t\treturn fmt.Errorf(\"refusing to run in %s - this would watch too many files. Please run air in a project directory\", dirName)\n\t\t}\n\t\twarnf(\"[warning] ignoring root directory protections. This could cause excessive file watching. It is recommended to run air in a project directory\")\n\t}\n\n\tif c.TmpDir == \"\" {\n\t\tc.TmpDir = \"tmp\"\n\t}\n\tif c.TestDataDir == \"\" {\n\t\tc.TestDataDir = \"testdata\"\n\t}\n\tc.adjustDefaultsForTmpDir()\n\ted := c.Build.ExcludeDir\n\tfor i := range ed {\n\t\ted[i] = cleanPath(ed[i])\n\t}\n\n\tif len(c.Build.Entrypoint) > 0 {\n\t\tentry := c.Build.Entrypoint.binary()","sourceCodeStart":636,"sourceCodeEnd":672,"githubUrl":"https://github.com/air-verse/air/blob/71ea1dee05248122ed22b5870c7fb20a90d80ddd/runner/config.go#L636-L672","documentation":"Air refuses to start when the project root is a dangerous directory (like / or $HOME) where recursive file watching would be prohibitively expensive. The isDangerousRoot check detects these, and this error aborts startup unless Build.IgnoreDangerousRootDir is explicitly true.","triggerScenarios":"Running `air` with its working directory (c.Root) at /, the user home directory, or similar; the config validation in config.go hits this before the watcher starts, unless `ignore_dangerous_root_dir = true` is set in [build].","commonSituations":"Launching air from a shell whose cwd is $HOME or / (forgot to cd into the project); Docker/CI setups mounting the repo at the container root; running air without a config in a too-broad directory.","solutions":["cd into your actual project directory before running air","Set `ignore_dangerous_root_dir = true` under [build] in .air.toml if you really intend this (with tighter exclude rules)","Restrict `include_dir`/`include_ext` in the config to narrow what gets watched","Run air inside the mounted project path in containers instead of the mount root"],"exampleFix":"// before (.air.toml, run in /home/user)\n// air exits with this error\n// after\n[build]\nignore_dangerous_root_dir = true\nexclude_dir = [\"Documents\", \".cache\"]","handlingStrategy":"validation","validationCode":"// before running air\ndir, _ := os.Getwd()\nfor _, bad := range []string{\"/\", os.Getenv(\"HOME\")} {\n\tif dir == bad {\n\t\treturn fmt.Errorf(\"refusing to run air in %s; cd into your project\", dir)\n\t}\n}","typeGuard":null,"tryCatchPattern":"if err := air.Run(); err != nil && strings.Contains(err.Error(), \"refusing to run in\") {\n\tlog.Fatalf(\"cd into a project directory first: %v\", err)\n}","preventionTips":["Always launch air from the project root, never from $HOME or /","Set a working_dir in CI/containers explicitly","If you must run at a broad root, add exclude_dir rules and ignore_dangerous_root_dir knowingly","Wrap air in a launcher script that verifies the cwd"],"tags":["config","watcher","safety"],"backgroundTag":"dangerous-root-directory","analyzedSha":"71ea1dee05248122ed22b5870c7fb20a90d80ddd","analyzedAt":"2026-08-31T20:27:54.676Z","schemaVersion":2},"datasetVersion":"2026-09-01T03:17:15.561Z"}