Explore–Plan–Code 流程

使用 Claude Code 進行軟體開發

Dani Zysman

AI Curriculum Manager @ DataCamp

「直接下水」的問題

冰山:水面上是提示,水面下是隱藏的複雜度

使用 Claude Code 進行軟體開發

工作流程

流程圖:Init → Explore → Plan → Code

使用 Claude Code 進行軟體開發

API 專案總覽

music-analytics-api/
  app.py           # Application entry point
  routes.py        # API endpoints
  models.py        # Artist/Album models
  analytics.py     # Statistics functions
  middleware.py    # Request logging
  config.py        # Session settings

一個簡單的 Music Analytics API,已有需遵循的既有模式。

使用 Claude Code 進行軟體開發

CLAUDE.md:專案記憶

CLAUDE.md:

  • 提供 Claude 你專案的持久化背景
  • Claude 每個工作階段都會自動讀取
  • 不必每次重述你的環境設定
使用 Claude Code 進行軟體開發

從 /init 開始

> /init
Music Analytics API
A Flask-based REST API for music data analytics.

Project Structure
- app.py       Flask application entry point
- routes.py    API endpoint definitions
- analytics.py Statistical analysis functions

Coding Conventions
- Use type hints for function parameters
- Include docstrings for all public functions
- Follow PEP 8 style guidelines
使用 Claude Code 進行軟體開發

Plan 模式

  • 用 Shift+Tab 切換,或輸入 /plan
  • 產生計畫後,按下 Ctrl+G 可視覺化、核准、檢閱或編輯
使用 Claude Code 進行軟體開發

略過規劃的風險

> Add a /api/login endpoint that creates a session for a user
from flask import jsonify, request
from flask_login import LoginManager, login_user
from app import app

login_manager = LoginManager(app)
@app.route('/api/login', methods=['POST'])
def login():
    """Handle user login and create session."""
    data = request.get_json()
    user = User.query.filter_by(username=data['username']).first()
    if user and user.password == data['password']:
        login_user(user)
        return jsonify({'status': 'success'})
    return jsonify({'error': 'Invalid credentials'}), 401
使用 Claude Code 進行軟體開發

先規劃,再寫碼

> /plan Add a /api/login endpoint that creates a session for a user
Plan: Add POST /api/login endpoint

Context
The music analytics API has session infrastructure in place
(flask_session, SECRET_KEY, session already imported in routes)
but no authentication.

Files to Modify
- models.py:  add User class, UserStore class, user_store singleton
- routes.py:  expand import, add login route

No changes needed to app.py, config.py, middleware.py, or analytics.py.
使用 Claude Code 進行軟體開發

延伸思考

> think about how to add authentication to this API
使用 Claude Code 進行軟體開發

思考層級

指令 推理深度
think 基本推理
think more 擴展推理
think a lot 全面推理
think longer 延長時間推理
ultrathink 最高推理
使用 Claude Code 進行軟體開發

管理情境視窗與 Token

excalidraw:情境視窗被提示與回應填滿,並顯示 token 拆解

  • 「Context window exceeded」→ 工作階段過長,使用 /clear
  • 當情境滿載時,Claude 會優先近期對話
使用 Claude Code 進行軟體開發

完整流程

流程圖:/init → Explore → Plan → Review → Code → Test

使用 Claude Code 進行軟體開發

一起來練習吧!

使用 Claude Code 進行軟體開發

Preparing Video For Download...