{"record":{"id":"5f5bcdb0236f8db3","repo":"composer/composer","slug":"file-file-cannot-be-found-in-the-current-direc","errorCode":null,"errorMessage":"File \"{file}\" cannot be found in the current directory","messagePattern":"File \"(.+?)\" cannot be found in the current directory","errorType":"console","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Composer/Command/BaseConfigCommand.php","lineNumber":79,"sourceCode":"            ($configFile === 'composer.json' || $configFile === './composer.json')\n            && !file_exists($configFile)\n            && realpath(Platform::getCwd()) === realpath($this->config->get('home'))\n        ) {\n            file_put_contents($configFile, \"{\\n}\\n\");\n        }\n\n        $this->configFile = new JsonFile($configFile, null, $io);\n        $this->configSource = new JsonConfigSource($this->configFile);\n\n        // Initialize the global file if it's not there, ignoring any warnings or notices\n        if ($input->getOption('global') && !$this->configFile->exists()) {\n            touch($this->configFile->getPath());\n            $this->configFile->write(['config' => new \\ArrayObject]);\n            Silencer::call('chmod', $this->configFile->getPath(), 0600);\n        }\n\n        if (!$this->configFile->exists()) {\n            throw new \\RuntimeException(sprintf('File \"%s\" cannot be found in the current directory', $configFile));\n        }\n    }\n\n    /**\n     * Get the local composer.json, global config.json, or the file passed by the user\n     */\n    protected function getComposerConfigFile(InputInterface $input, Config $config): string\n    {\n        return $input->getOption('global')\n            ? ($config->get('home') . '/config.json')\n            : ($input->getOption('file') ?? Factory::getComposerFile())\n        ;\n    }\n\n    /**\n     * Get the local auth.json or global auth.json, or if the user passed in a file to use,\n     * the corresponding auth.json\n     */","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/composer/composer/blob/c435d285c9120efdca35696769c72ea9fdcc0466/src/Composer/Command/BaseConfigCommand.php#L61-L97","documentation":"Thrown by BaseConfigCommand::initialize() after it resolves the config file path and finds the file does not exist (and --global was not set, which would auto-create it). It indicates the composer.json (or the --file target) is missing from the current working directory. This prevents writing config to a nonexistent file.","triggerScenarios":"Running `composer config foo bar` in a directory with no composer.json, running config with --file=missing.json, or running config from the wrong working directory (e.g. a parent folder).","commonSituations":"Wrong cwd (running from repo root when composer.json is in a subdirectory), deleted or never-created composer.json, or a typo in the --file path.","solutions":["Ensure you are in the directory containing composer.json (check with ls).","If no composer.json exists, run `composer init` first.","Correct the --file path or remove it to target the default composer.json.","If targeting the global config, use --global instead of --file."],"exampleFix":"// before (run from wrong dir)\ncomposer config minimum-stability dev\n// after\ncd /path/to/project && composer config minimum-stability dev","handlingStrategy":"validation","validationCode":"$file = $optFile ?? 'composer.json';\nif (!is_file(getcwd() . '/' . $file)) {\n    fwrite(STDERR, \"$file not found in \" . getcwd() . \"\\n\");\n    exit(1);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run config commands from the directory containing composer.json.","Initialize the project with `composer init` before running config."],"tags":["cli","config","file-not-found"],"backgroundTag":null,"analyzedSha":"c435d285c9120efdca35696769c72ea9fdcc0466","analyzedAt":"2026-08-07T18:58:23.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}