Manage sessions from the shell
Every background session has a short ID you can use from the shell. The ID is printed when you start a session with claude --bg, and each session's ID is its directory name under ~/.claude/jobs/. These commands are useful for scripting or when you don't want to open agent view.
| Command | Purpose |
|---|---|
claude agents | Open agent view |
claude agents --cwd <path> | Open agent view scoped to sessions started under <path> |
claude agents --json | Print sessions as a JSON array and exit. See List sessions as JSON |
claude attach <id> | Attach to a session in this terminal |
claude logs <id> | Print the session's recent output |
claude stop <id> | Stop a session. Also accepts claude kill |
claude respawn <id> | Restart a session, running or stopped, e.g. to pick up an updated Claude Code binary. The restarted session resumes its saved conversation; when none is on disk, it runs its original prompt again as a new conversation |
claude respawn --all | Restart every running session, e.g. to move all sessions onto an updated Claude Code binary at once |
claude rm <id> | Remove a session from the list, along with a worktree Claude created for it when that's safe to delete; see What deleting a session removes. The conversation transcript stays on your local machine and remains available through claude --resume |