본문 바로가기
C.W.K.
Stream
Lesson 09 of 11 · published

codex exec로 자동화 스크립트 만들기

~14 min · codex, exec, scripting, automation

Level 0🌱 입문자
0 XP0/70 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

codex exec는 한 번 실행하고 끝나는 자동화 입구야

codex exec는 인자나 stdin으로 지시를 받고 결과를 표준 출력에 남긴 뒤 종료해. Claude의 -p, Gemini의 -p와 같은 역할이라 셸 파이프와 cron, CI에 자연스럽게 붙어.

--output-last-message는 전체 도구 기록 대신 최종 답만 내보내고, 출력 형식은 text·json·markdown 중 고를 수 있어. 무인 실행에서는 현재 설정에 기대지 말고 --sandbox와 --ask-for-approval를 명령에 직접 고정해. 나중에 개인 설정이 바뀌어도 야간 작업의 경계는 그대로 남아야 하니까.

직접 확인할 항목: --output-format text|json|markdown, exec.

Code

codex exec를 쓰는 세 가지 실전 방식·bash
# 1. Generate a commit message from staged diff
git diff --staged | codex exec \
  --ask-for-approval never --sandbox read-only \
  "Write a concise conventional-commit message" \
  --output-last-message

# 2. Triage failing tests
npm test 2>&1 | tail -100 | codex exec \
  --sandbox read-only \
  "Diagnose these failures and rank by likely root cause" \
  > triage.md

# 3. Generate OpenAPI from route handlers
cat src/routes/*.ts | codex exec \
  --sandbox read-only \
  "Generate OpenAPI 3.1 spec for these handlers" \
  > openapi.yaml
Cron 작업 구성 예시·bash
# crontab -e
30 22 * * 1-5 cd /workspace && /usr/bin/env codex exec \
  --ask-for-approval never \
  --sandbox workspace-write \
  "Update dependencies, run tests, write a one-paragraph
   summary to /workspace/nightly-summary-$(date +%F).md" \
  --output-last-message \
  >> /var/log/codex-nightly.log 2>&1

External links

Exercise

지금까지 수동으로 실행하던 셸 스크립트 하나를 codex exec 호출로 바꿔. sandbox와 승인 모드를 명시적으로 고정하고 cron에 등록해. 일주일 뒤 로그를 살펴 작업이 문제없이 실행됐는지 확인해.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인 — 댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.