apiVersion: v1
kind: Pod
metadata:
  name: claude-terminal
  namespace: agents
  labels:
    app: claude-terminal
spec:
  serviceAccountName: agent-sa
  containers:
  - name: claude
    image: alpine:3.19
    command: ["/bin/sh", "-c"]
    args:
      - |
        # Install dependencies
        apk add --no-cache \
          bash \
          git \
          curl \
          tmux \
          ttyd \
          nodejs \
          npm \
          openssh-client \
          ca-certificates

        # Install Bun
        curl -fsSL https://bun.sh/install | bash
        export PATH="/root/.bun/bin:$PATH"

        # Install Claude Code with Bun
        bun install -g @anthropic-ai/claude-code

        # Configure git
        git config --global user.name "Claude Agent"
        git config --global user.email "agent@aiworker.local"

        # Start tmux session with Claude Code
        tmux new-session -d -s claude 'bash -c "cd /workspace && exec bash"'

        # Start ttyd to expose tmux over HTTP
        ttyd -p 7681 -W tmux attach -t claude
    workingDir: /workspace
    ports:
    - containerPort: 7681
      name: web-terminal
    resources:
      requests:
        cpu: 200m
        memory: 512Mi
      limits:
        cpu: 2000m
        memory: 2Gi
    volumeMounts:
    - name: workspace
      mountPath: /workspace
    - name: kube-config
      mountPath: /root/.kube
      readOnly: true
  volumes:
  - name: workspace
    persistentVolumeClaim:
      claimName: claude-workspace
  - name: kube-config
    secret:
      secretName: agent-kubeconfig
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: claude-workspace
  namespace: agents
spec:
  accessModes:
  - ReadWriteOnce
  storageClassName: longhorn
  resources:
    requests:
      storage: 10Gi
---
apiVersion: v1
kind: Service
metadata:
  name: claude-terminal
  namespace: agents
spec:
  selector:
    app: claude-terminal
  ports:
  - port: 7681
    targetPort: 7681
    name: web-terminal
  type: ClusterIP
