This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
BackToClose is a browser extension that closes the active tab when the user hits back on the last history entry in the session, replicating Safari's iOS behavior. The extension works with Chrome and Firefox using Manifest v3.
pnpm dev- Start development server for Chromepnpm dev:firefox- Start development server for Firefoxpnpm build- Build for Chromepnpm build:firefox- Build for Firefoxpnpm zip- Create distribution package for Chromepnpm zip:firefox- Create distribution package for Firefoxpnpm compile- Type check without emitting files
- Background Script (
src/entrypoints/background.ts): Manages tab tracking, injects content scripts into qualifying tabs, and handles tab closure - Content Script (
src/entrypoints/content.ts): Manipulates browser history and listens for PopStateEvents to trigger tab closure - Popup (
src/entrypoints/popup/): Extension configuration UI
The extension identifies 3 types of new tabs:
- New empty tab (showing the new tab page) - identified using the URL
- New child tab (open in new tab from another tab) - identified using the
openerTabIdproperty and the URL - Others
By default, only child tabs (type 2) are tracked.
Content scripts modify the browser history stack by:
- Changing the first history entry to have title "Close Tab" with special state
- Pushing the current page as the next entry
- Waiting for user interaction before applying changes (browser security requirement)
- Listening for PopStateEvents to detect back navigation to the special entry
- WXT Framework: Browser extension development framework
- TypeScript: Primary language
- pnpm: Package manager
- Manifest v3: Extension API version
- Use @https://jj-vcs.github.io for version control. YOU MUST ALWAYS USE JUJUTSU TO CREATE COMMITS. NEVER COMMIT WITH GIT. DO NOT USE GIT TO CREATE COMMITS, but you MAY use git to read commits or otherwise gather information.
src/entrypoints/- Extension entry points (background, content, popup)src/components/- Reusable componentssrc/assets/- Static assetspublic/- Public files for extensionwxt.config.ts- WXT framework configuration
- The
OpenerTabIdproperty is also available in new empty tabs - All tabs (including new empty tabs) have URL '' when first created, except for reopened tabs which have the last URL in the history of the tab
- Get the actual URL using
chrome.tabs.getafter tab creation and check forpendingUrlorurl. If the URL is 'chrome://newtab/' then it is a new empty tab
- New empty tabs have URL 'about:newtab', while other new tabs have URL 'about:blank' when first created
- The
OpenerTabIdproperty is only available in child tabs
- Browser extension development documentation:
- @notes.md
After every edit, remember to commit your changes using jujutsu (jj) with a clear and descriptive commit message using the command: jj commit -m "Your commit message here"