brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: claude agents --json lists background sessions for your scripts

Claude
~/tips/tip-claude-agents-json

claude agents --json

Prints your active Claude Code background sessions as a JSON array for scripts.

With several Claude Code sessions running in the background, a terminal screen is a poor way to keep track. The same list is available as JSON, which suits a script better.

claude agents opens agent view, a screen for monitoring and dispatching parallel background sessions. With --json it prints the active sessions as a JSON array instead, so no interactive terminal is needed.

claude agents --json

Add --all to include completed background sessions. --cwd limits the list to sessions started under one directory:

claude agents --json --all --cwd ~/projects/example

Pipe it to jq to pick what you need. The reference does not list the fields of each entry, so I do not either. Print the output once and read the keys before you build on them.

claude agents --json | jq 'length'

That counts the active sessions, a quick check for a status bar or a cron job. To jump into one of them from the terminal, claude attach <id|name> attaches to a background session, and claude --bg "query" starts one and returns right away.

Opening agent view itself requires an interactive terminal. Only the JSON output is meant for scripts.

Further reading: Claude Code CLI reference

More Claude tips /recap /focus /skill-doctor /autocompact 500k claude purge ~/work/my-repo --dry-run All Claude tips (83) All topics

Link