Skip to content

feat(cache): add cookie cache clearing to Debug tab and CLI#592

Open
coygeek wants to merge 2 commits intosteipete:mainfrom
coygeek:feat/clear-cookie-cache
Open

feat(cache): add cookie cache clearing to Debug tab and CLI#592
coygeek wants to merge 2 commits intosteipete:mainfrom
coygeek:feat/clear-cookie-cache

Conversation

@coygeek
Copy link

@coygeek coygeek commented Mar 24, 2026

Summary

  • Adds a "Clear cookie cache" button to the Debug → Caches section, alongside the existing "Clear cost cache" button
  • Adds a codexbar cache clear CLI command with --cookies, --cost, and --all flags, plus optional --provider for per-provider clearing
  • Adds CookieHeaderCache.clearAll() public API that iterates all providers and clears cached entries from Keychain

Motivation

When browser cookie imports become corrupt or stale (e.g., from a Firefox profile with bad session data), there is currently no user-facing way to clear the cached cookie entries. The only workaround is running a manual Keychain command:

security delete-generic-password -s "com.steipete.codexbar.cache" -a "cookie.claude"

This is not discoverable. Toggling the provider off/on or changing cookie source to "Off" and back doesn't clear the Keychain cache either.

Changes

File Change
Sources/CodexBarCore/CookieHeaderCache.swift Add clearAll() method
Sources/CodexBar/PreferencesDebugPane.swift Add "Clear cookie cache" button in Caches section
Sources/CodexBarCLI/CLICacheCommand.swift New file: cache clear subcommand
Sources/CodexBarCLI/CLIEntry.swift Wire up cache clear command path
Sources/CodexBarCLI/CLIHelp.swift Add cache help text
Sources/CodexBarCLI/CLIIO.swift Route cache/clear to help

CLI Usage

codexbar cache clear --cookies                    # Clear all cookie caches
codexbar cache clear --cookies --provider claude  # Clear only Claude cookies
codexbar cache clear --cost                       # Clear cost usage caches
codexbar cache clear --all                        # Clear everything
codexbar cache clear --all --format json --pretty # JSON output

Test plan

  • Build the app and verify the "Clear cookie cache" button appears in Debug → Caches
  • Click the button and verify it reports the number of cleared provider caches
  • Run codexbar cache clear --cookies and verify text output
  • Run codexbar cache clear --cookies --provider claude for single-provider clearing
  • Run codexbar cache clear --all --format json --pretty for JSON output
  • Verify re-enabling a provider after clearing causes a fresh browser cookie import

Closes #591

🤖 Generated with Claude Code

Add a "Clear cookie cache" button to the Debug → Caches section,
alongside the existing "Clear cost cache" button. This allows users
to clear stale or corrupt browser cookie caches from the GUI without
needing to run manual Keychain commands.

Also add a `codexbar cache clear` CLI command with --cookies, --cost,
and --all flags, plus optional --provider for per-provider clearing.

Changes:
- CookieHeaderCache: add clearAll() that iterates all providers
- PreferencesDebugPane: add "Clear cookie cache" button in Caches section
- CLICacheCommand: new file implementing `cache clear` subcommand
- CLIEntry: wire up `cache clear` command path
- CLIHelp/CLIIO: add cache help text and help routing

Closes steipete#591

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3f7d7f20aa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +71 to +72
if case .found = KeychainCacheStore.load(key: key, as: Entry.self) {
self.clear(provider: provider)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Clear provider caches even when decode fails

clearAll() only calls self.clear(provider:) when KeychainCacheStore.load(..., as: Entry.self) returns .found, so corrupted keychain entries (.invalid) and legacy-file-only caches are skipped. In those states, cache clear --cookies/the Debug button can report nothing cleared while stale cookie data remains (or gets re-migrated later), which defeats the main recovery path for broken cookie cache state.

Useful? React with 👍 / 👎.

clearAll() previously only cleared `.found` entries, skipping
`.invalid` (corrupt) keychain entries and legacy-file-only caches.
Since the primary use case is recovering from broken cookie state,
unconditionally clear both corrupt keychain entries and orphaned
legacy files.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ratulsarna
Copy link
Collaborator

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cef0db91eb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +13 to +16
let clearCookies = cookies || all
let clearCost = cost || all

if !clearCookies && !clearCost {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject --provider without cookie-clear flags

--provider is currently accepted whenever any clear action is chosen, but it is only used inside the cookie-clearing branch. In practice, codexbar cache clear --cost --provider claude silently ignores the provider and still exits success after clearing cost cache, which is misleading for users and scripts that expect provider-scoped behavior. Add validation so --provider requires --cookies (or explicitly documented semantics with --all) instead of being ignored.

Useful? React with 👍 / 👎.

Comment on lines +29 to +30
let had = CookieHeaderCache.load(provider: provider) != nil
CookieHeaderCache.clear(provider: provider)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 Badge Report provider clears correctly for invalid cookie entries

The provider-specific path derives cleared from CookieHeaderCache.load(...) != nil, but load returns nil for invalid/corrupt keychain payloads even when those entries are then removed. This causes cache clear --cookies --provider <name> to report cleared: 0/"nothing to clear" in corrupt-entry scenarios, producing incorrect CLI output and unreliable JSON for automation.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Clear cookie cache from Debug tab and CLI

2 participants