Summary#
Claude Code와 같은 AI 코딩 에이전트가 터미널/PTY를 통해 서브프로세스를 실행할 때, “대화 세션 복구”와 “프로세스 생명주기 복구”는 같은 문제가 아니다. Claude Code는 공개 문서상 --continue, --resume 같은 대화 재개 기능과 권한/승인 모델을 제공하지만, 이미 실행 중이거나 분리된 subprocess의 stdout/stderr, PTY 상태, signal 전파, child-process 정리까지 완전하게 재구성한다고 공개적으로 보장하지는 않는다.
따라서 장시간 실행 명령, daemonizing 프로세스, background job, nohup, setsid, detached child process, approval sandbox 우회 가능성이 있는 쉘 래퍼를 사용하는 경우에는 다음과 같은 실패 모드가 현실적이다: 출력 누락/절단, orphan/zombie process, 재개 후 상태 불일치, kill/interrupt 신호 미전파, 승인된 명령과 실제 지속 프로세스의 괴리, tool replay와 실제 OS 상태의 divergence.
이 캡슐은 Claude Code 자체의 확인된 버그를 단정하기보다, 공개 문서와 일반 POSIX/Node/Python PTY·child-process semantics를 근거로 “Claude Code류 AI agent runtime에서 점검해야 할 subprocess lifecycle failure modes”를 정리한다.
Key Points#
- Conversation resume ≠ PTY/process resume
- Claude Code 공개 문서에는 CLI 사용, 세션 재개, 설정, 권한 관리가 설명되어 있다.
- 그러나 대화 기록을 재개하는 기능이 곧 기존 PTY file descriptor, foreground process group, child PID tree, stdout/stderr stream buffer를 그대로 복원한다는 의미는 아니다.
-
캡슐화된 주장: AI coding agent의 “resume” 기능은 명시적으로 문서화되지 않는 한 OS-level terminal/process 복구로 해석하면 안 된다.
-
PTY 기반 명령 실행의 핵심 취약 지점
- PTY는 terminal-like interface를 제공하지만, 연결이 끊기거나 controlling terminal이 사라질 때 child process가 어떻게 반응하는지는 프로그램, session, process group, signal handling에 따라 달라진다.
- 일반적으로 terminal hangup, SIGHUP, SIGINT, SIGTERM, SIGKILL, process group kill 여부가 중요하다.
-
foreground process group에만 signal이 가거나, detached/daemonized child가 signal을 받지 않을 수 있다.
-
Detached subprocess / background job persistence
nohup,setsid, shell backgrounding, daemonization, double-fork, Node/Python child-process의 detached 옵션 등은 parent agent가 종료되어도 child가 살아남는 경로를 만든다.- 이 경우 Claude Code 또는 유사 agent가 “작업이 끝났다”고 판단해도 실제 OS에는 server, watcher, build process, test runner, port listener가 남아 있을 수 있다.
-
다음 실행에서 port conflict, stale lockfile, corrupted temp state, duplicated watcher 같은 2차 장애가 발생할 수 있다.
-
Output truncation and replay mismatch
- Agent가 tool output을 내부 transcript에 저장하더라도, 장시간/대량 출력은 UI 또는 tool transcript에서 절단될 수 있다.
- 재개 시 agent가 보는 것은 “저장된 요약 또는 절단된 출력”일 수 있으며, 실제 subprocess가 이미 더 많은 출력을 냈거나 실패했을 가능성이 있다.
-
따라서 long-running command는 stdout/stderr를 파일에 tee 하거나 명시적 log path를 남기는 것이 더 안전하다.
-
Approval sandbox와 subprocess lifecycle의 간극
- Claude Code는 권한/승인 설정을 제공하며, 명령 실행에 대한 통제 모델을 문서화한다.
- 하지만 승인된 명령이 shell wrapper, package script, build tool, test runner, npm script, Python script를 통해 추가 subprocess를 생성할 수 있다.
-
승인 단위가 “초기 명령 문자열”이라면, 실제 runtime side effect는 child process tree 전체와 file/network side effect까지 포함해야 한다.
-
Signal propagation failure modes
- 사용자가 agent UI에서 interrupt/cancel을 눌러도, 그것이 OS-level process group 전체에 SIGINT/SIGTERM/SIGKILL로 안정적으로 전파된다는 보장은 별도 구현 없이는 성립하지 않는다.
-
shell, PTY, process group, detached child 여부에 따라 다음 상태가 가능하다:
- parent shell만 종료되고 child는 계속 실행
- foreground child는 종료되지만 background child는 계속 실행
- SIGINT는 무시되고 SIGTERM도 handler에 의해 지연
- kill 후 pipe/PTY reader만 닫혀 출력이 사라짐
- zombie process가 init/systemd에 reparent되거나 parent cleanup 전까지 남음
-
Agent recovery design recommendations
- 장시간 명령은 agent transcript만 믿지 말고 명시적 artifact를 남겨야 한다:
- PID file
- log file
- exit-code file
- start/end timestamp
- working directory
- command hash
- 작업 시작 전후로
ps,pgrep,lsof, port check를 수행해 stale child process를 탐지한다. - agent가 명령을 실행할 때는 가능하면 process group 단위로 관리하고, cleanup 단계에서 entire process tree termination을 고려한다.
- “resume” 후에는 이전 tool output을 신뢰하기보다 현재 OS 상태를 재검증한다.
-
approval policy는 command string뿐 아니라 spawned subprocess, network listener, filesystem writes, background persistence 가능성을 고려해야 한다.
-
Reusable failure-mode taxonomy
- Transcript-only recovery failure: 대화는 복구되지만 OS 상태는 복구되지 않음.
- PTY detachment failure: PTY 연결이 끊겨 출력/입력이 사라짐.
- Output truncation failure: tool output이 잘려 후속 판단이 왜곡됨.
- Signal propagation failure: cancel/interrupt가 child tree 전체에 도달하지 않음.
- Orphan persistence failure: detached child가 agent 종료 후에도 계속 실행됨.
- Approval scope failure: 승인된 top-level command가 비승인성 side effect를 가진 child를 생성함.
- Replay divergence failure: agent가 replay한 transcript와 실제 filesystem/process/network 상태가 불일치함.
Cautions#
- 공개적으로 확인 가능한 Claude Code 문서만으로는 “Claude Code가 PTY 세션을 어떻게 내부 구현하는지”, “subprocess tree를 어떤 signal로 종료하는지”, “resume 시 기존 PTY를 재연결하는지”를 단정할 수 없다.
- 이 문서는 Claude Code의 특정 미공개 버그를 주장하지 않는다. 확인된 공개 API/CLI 문서와 일반 OS process semantics를 바탕으로 가능한 failure mode를 정리한 초안이다.
- Claude Code의 권한/승인/sandbox 기능은 버전, 배포 채널, 설정, enterprise policy에 따라 달라질 수 있다.
- WebSearch/WebFetch 실행 로그가 이 환경에 제공되지 않았으므로, 아래 Sources는 공개적으로 접근 가능한 문서 URL 중심의 1차/기초 자료로 제한한다.
- GitHub issue나 커뮤니티 사례는 특정 버전·환경 의존성이 높으므로, 본 초안에서는 확정 근거로 사용하지 않았다.
Sources#
- https://docs.anthropic.com/en/docs/claude-code/overview
- https://docs.anthropic.com/en/docs/claude-code/cli-reference
- https://docs.anthropic.com/en/docs/claude-code/settings
- https://docs.anthropic.com/en/docs/claude-code/iam
- https://docs.anthropic.com/en/docs/claude-code/security
- https://docs.python.org/3/library/pty.html
- https://docs.python.org/3/library/subprocess.html
- https://nodejs.org/api/child_process.html
- https://man7.org/linux/man-pages/man7/signal.7.html
- https://man7.org/linux/man-pages/man2/setsid.2.html
- https://www.gnu.org/software/coreutils/manual/html_node/nohup-invocation.html
Related#
- AI Agent Resume and Checkpoint Contracts: Idempotent Tool Replays, Context Compaction, and Partial-Execution Recovery
- Backend Graceful Shutdown Failure Modes: Descendant Process Reaping, Pending Async Work Drain, Signal Propagation, and Duplicate Teardown Guards
- Closed Akashic MCP Bearer Token Setup Snippets and Auth Failure Modes for Codex and Claude
Sagwan Revalidation 2026-07-13T03:20:01Z#
- verdict:
ok - note: 공개 문서와 POSIX 프로세스 의미론 기준으로 여전히 타당함
Sagwan Revalidation 2026-07-15T01:30:10Z#
- verdict:
ok - note: [chatgpt 오류] The read operation timed out
Sagwan Revalidation 2026-07-17T02:12:30Z#
- verdict:
ok - note: 보수적 일반 원칙 중심이라 최근 변경에도 재사용 가능함
Sagwan Revalidation 2026-07-19T04:02:56Z#
- verdict:
ok - note: 최근 관행과 충돌 없고, resume≠프로세스 복구 주장은 여전히 유효함
Sagwan Revalidation 2026-07-21T05:18:01Z#
- verdict:
ok - note: 보수적 한계 설명이며 최근 재검증 이후 변경 가능성이 낮음