Skip to content

fix(provider): respect CLAUDE_CONFIG_DIR in Claude detection - #134

Open
paoloantinori wants to merge 1 commit into
alexei-led:mainfrom
paoloantinori:fix/claude-config-dir-provider-detection
Open

fix(provider): respect CLAUDE_CONFIG_DIR in Claude detection#134
paoloantinori wants to merge 1 commit into
alexei-led:mainfrom
paoloantinori:fix/claude-config-dir-provider-detection

Conversation

@paoloantinori

Copy link
Copy Markdown

Fixes #133

Problem

detect_provider_from_payload (src/ccgram/hooks/adapters.py) recognizes a Claude transcript only by the hardcoded substring /.claude/. When CLAUDE_CONFIG_DIR redirects the config home (a documented Claude Code setting), Claude writes transcripts under the redirected dir, so the guard fails and the model/permission_mode fields in Claude Stop/Notification payloads trip the codex branch. The session is misdetected as codex, and on Stop the codex short-circuit drops the turn. See #133 for the full reproduction.

This extends PR #116, which added the /.claude/ guard for the default home but did not cover redirected config homes.

Fix

Add _claude_transcript_markers(), which returns the transcript-path markers that identify a Claude session:

  • /.claude/projects/ for the default home (basename match works across users), and
  • <resolved CLAUDE_CONFIG_DIR>/projects/ when CLAUDE_CONFIG_DIR is set.

Each marker is anchored on projects/ (Claude's actual transcript subtree) rather than the bare config dir, which avoids three false-positive cases:

  • CLAUDE_CONFIG_DIR=~ would otherwise resolve to the home dir and match almost any path.
  • a redirect named .claude.custom was silently shadowed by the default /.claude/ substring.
  • a codex transcript physically inside the redirected tree but outside projects/ would have matched the bare prefix.

config.py:92 already resolves CLAUDE_CONFIG_DIR the same way; this mirrors that resolution.

Tests

Four new tests in tests/ccgram/test_hook_provider_events.py:

  • redirected config dir recognized as Claude (not codex)
  • redirected config dir does not over-match a generic /config/ path
  • CLAUDE_CONFIG_DIR=~ does not sweep up a codex transcript under the home dir
  • a .claude.custom redirect is honored as its own config dir

Full file: 23 passed. ruff check, ruff format --check, and pyright clean.

CHANGELOG

Added an Unreleased > Fixed entry.

detect_provider_from_payload classified a session as Claude only when the
transcript path contained /.claude/. When CLAUDE_CONFIG_DIR redirects the
config home (a documented Claude Code setting used by multi-account setups,
dev containers, and cc-mirror clones), Claude writes transcripts under the
redirected dir, so the guard failed and Claude Stop/Notification events were
misdetected as codex, dropping the turn's status update.

Add _claude_transcript_markers() which returns /.claude/ plus the resolved
CLAUDE_CONFIG_DIR path when set (full path, not basename, to avoid
false-positives on generic components like /config/).
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.

Claude session misdetected as codex when CLAUDE_CONFIG_DIR redirects the config home

1 participant