Run Claude Code with /create-spec command to create project specification. The project path is passed as an argument so create-spec knows where to write files. Captures stderr to detect authentication errors and provide helpful guidance.
(project_dir: Path)
| 206 | |
| 207 | |
| 208 | def run_spec_creation(project_dir: Path) -> bool: |
| 209 | """ |
| 210 | Run Claude Code with /create-spec command to create project specification. |
| 211 | |
| 212 | The project path is passed as an argument so create-spec knows where to write files. |
| 213 | Captures stderr to detect authentication errors and provide helpful guidance. |
| 214 | """ |
| 215 | print("\n" + "=" * 50) |
| 216 | print(" Project Specification Setup") |
| 217 | print("=" * 50) |
| 218 | print(f"\nProject directory: {project_dir}") |
| 219 | print(f"Prompts will be saved to: {get_project_prompts_dir(project_dir)}") |
| 220 | print("\nLaunching Claude Code for interactive spec creation...") |
| 221 | print("Answer the questions to define your project.") |
| 222 | print("When done, Claude will generate the spec files.") |
| 223 | print("Exit Claude Code (Ctrl+C or /exit) when finished.\n") |
| 224 | |
| 225 | try: |
| 226 | # Launch CLI with /create-spec command |
| 227 | # Project path included in command string so it populates $ARGUMENTS |
| 228 | # Capture stderr to detect auth errors while letting stdout flow to terminal |
| 229 | result = subprocess.run( |
| 230 | ["claude", f"/create-spec {project_dir}"], |
| 231 | check=False, # Don't raise on non-zero exit |
| 232 | cwd=str(Path(__file__).parent), # Run from project root |
| 233 | stderr=subprocess.PIPE, |
| 234 | text=True |
| 235 | ) |
| 236 | |
| 237 | # Check for authentication errors in stderr |
| 238 | stderr_output = result.stderr or "" |
| 239 | if result.returncode != 0 and is_auth_error(stderr_output): |
| 240 | print_auth_error_help() |
| 241 | return False |
| 242 | |
| 243 | # If there was stderr output but not an auth error, show it |
| 244 | if stderr_output.strip() and result.returncode != 0: |
| 245 | print(f"\nClaude CLI error: {stderr_output.strip()}") |
| 246 | |
| 247 | # Check if spec was created in project prompts directory |
| 248 | if check_spec_exists(project_dir): |
| 249 | print("\n" + "-" * 50) |
| 250 | print("Spec files created successfully!") |
| 251 | return True |
| 252 | else: |
| 253 | print("\n" + "-" * 50) |
| 254 | print("Spec creation incomplete.") |
| 255 | print(f"Please ensure app_spec.txt exists in: {get_project_prompts_dir(project_dir)}") |
| 256 | # If failed with non-zero exit and no spec, might be auth issue |
| 257 | if result.returncode != 0: |
| 258 | print("\nIf you're having authentication issues, try running: claude login") |
| 259 | return False |
| 260 | |
| 261 | except FileNotFoundError: |
| 262 | print("\nError: 'claude' command not found.") |
| 263 | print("Make sure Claude Code CLI is installed:") |
| 264 | print(" npm install -g @anthropic-ai/claude-code") |
| 265 | return False |
no test coverage detected