readme summary
Each run queries a Chrome DevTools Protocol (CDP) endpoint for page tabs and compares each tab's title and URL with the previous run. When that pair has stayed unchanged for the configured threshold, the script reports the tab as idle; with --close, it asks Chrome to close it. It runs in dry-run mode by default, protects the first real page in Chrome’s list, and skips URLs matching --keep patterns.
Check python3 --version. If Python is missing or older than 3.8, install a supported Python 3 through your distribution's package manager. You can run python3 close_idle_tabs.py directly; neither pip nor a virtual environment is required.
what it does
Each run queries a Chrome DevTools Protocol endpoint for page tabs and compares each tab's title and URL with the previous run. Tabs unchanged for the configured threshold are reported as idle; with --close, it asks Chrome to close them. It protects the first real page and skips URLs matching --keep patterns.
why it helps run agents
Long agent sessions pile up tabs. Run it on a timer next to cdp-setup-kit to keep shared browsers lean.
requirements
- Python 3.8+, standard library only
- Chrome started with remote debugging
install
From the cloned repository, check the options first:
python3 close_idle_tabs.py --help
With CDP_ENDPOINT set, report tabs unchanged for ten minutes while keeping a docs path open:
python3 close_idle_tabs.py --idle-seconds 600 --keep 'https://example.com/docs/*'
The first run records tab state; run it repeatedly at a shorter interval than the threshold. Review the dry-run output, then add --close. The README includes example systemd user units for scheduled runs.
similar projects
| project | how it compares |
|---|---|
| greatsuspender/thegreatsuspender | A classic browser extension that suspends tabs to free memory. Extensions act inside a human's browser; cdpidletabs works from outside over CDP, suited to agent-controlled Chrome. |
| AnNOtis/close-idle-tabs | A browser extension with a button to close inactive tabs. Manual and in-browser, not schedulable from a server. |