{"record":{"id":"9f7d84dfdeac69ca","repo":"google-gemini/gemini-cli","slug":"command-requires-a-workspace","errorCode":null,"errorMessage":"Command requires a workspace.","messagePattern":"Command requires a workspace\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/acp/commands/init.ts","lineNumber":27,"sourceCode":"import { performInit } from '@google/gemini-cli-core';\nimport type {\n  Command,\n  CommandContext,\n  CommandExecutionResponse,\n} from './types.js';\n\nexport class InitCommand implements Command {\n  name = 'init';\n  description = 'Analyzes the project and creates a tailored GEMINI.md file';\n  requiresWorkspace = true;\n\n  async execute(\n    context: CommandContext,\n    _args: string[] = [],\n  ): Promise<CommandExecutionResponse> {\n    const targetDir = context.agentContext.config.getTargetDir();\n    if (!targetDir) {\n      throw new Error('Command requires a workspace.');\n    }\n\n    const geminiMdPath = path.join(targetDir, 'GEMINI.md');\n    const result = performInit(fs.existsSync(geminiMdPath));\n\n    switch (result.type) {\n      case 'message':\n        return {\n          name: this.name,\n          data: result,\n        };\n      case 'submit_prompt':\n        fs.writeFileSync(geminiMdPath, '', 'utf8');\n\n        if (typeof result.content !== 'string') {\n          throw new Error('Init command content must be a string.');\n        }\n","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/google-gemini/gemini-cli/blob/5024443c7217464a66e98f80d73172a26440bd8f/packages/cli/src/acp/commands/init.ts#L9-L45","documentation":"The InitCommand (which generates a GEMINI.md file via performInit) requires a workspace target directory. If context.agentContext.config.getTargetDir() returns a falsy value, the command cannot determine where to write GEMINI.md and throws. The command declares requiresWorkspace = true.","triggerScenarios":"Running the /init command when the CLI was started without a target directory set, or when getTargetDir() has not been initialized in the agent context.","commonSituations":"CLI started in a mode without a workspace; target directory not configured in settings; running init from a context where no project root or CWD was resolved; ACP session initialized without a workspace path.","solutions":["Start the CLI from within a project directory so CWD resolves to a target dir.","Set the target directory in configuration before running init.","Ensure the agent context's config.getTargetDir() is initialized before dispatching the init command."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function hasWorkspace(context: CommandContext): boolean {\n  return Boolean(context.agentContext.config.getTargetDir());\n}\n\n// Before dispatching init:\nif (!hasWorkspace(context)) {\n  return { name: 'init', data: { type: 'message', messageType: 'error', content: 'Open a project directory first.' } };\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure the CLI is started from within a project directory so getTargetDir() resolves.","Check for a workspace before dispatching commands that declare requiresWorkspace = true.","Configure the target directory explicitly in settings if CWD resolution is unreliable."],"tags":["acp","command","init","workspace"],"backgroundTag":null,"analyzedSha":"5024443c7217464a66e98f80d73172a26440bd8f","analyzedAt":"2026-08-12T06:01:53.711Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}