@@ -19,9 +19,12 @@ import { createRoutingBlock } from "./routing-block.mjs";
1919import { createToolNamer } from "./core/tool-naming.mjs" ;
2020import { buildAutoInjection } from "./auto-injection.mjs" ;
2121
22- const toolNamer = createToolNamer ( "claude-code" ) ;
22+ // Auto-detect platform for correct env vars and config paths
23+ const platformOpts = detectPlatform ( ) ;
24+ const platformId = platformOpts . configDir === ".qwen" ? "qwen-code" : "claude-code" ;
25+ const toolNamer = createToolNamer ( platformId ) ;
2326const ROUTING_BLOCK = createRoutingBlock ( toolNamer ) ;
24- import { readStdin , parseStdin , getSessionId , getSessionDBPath , getSessionEventsPath , getCleanupFlagPath , resolveConfigDir } from "./session-helpers.mjs" ;
27+ import { readStdin , parseStdin , getSessionId , getSessionDBPath , getSessionEventsPath , getCleanupFlagPath , resolveConfigDir , detectPlatform } from "./session-helpers.mjs" ;
2528import { writeSessionEventsFile , buildSessionDirective , getSessionEvents , getLatestSessionEvents } from "./session-directive.mjs" ;
2629import { createSessionLoaders } from "./session-loaders.mjs" ;
2730import { join , dirname } from "node:path" ;
@@ -102,18 +105,21 @@ try {
102105 db . cleanupOldSessions ( 7 ) ;
103106 db . db . exec ( `DELETE FROM session_events WHERE session_id NOT IN (SELECT session_id FROM session_meta)` ) ;
104107
105- // Proactively capture CLAUDE.md files — Claude Code loads them as system
108+ // Proactively capture CLAUDE.md / QWEN.md files — the host IDE loads them as system
106109 // context at startup, invisible to PostToolUse hooks. We read them from
107110 // disk so they survive compact/resume via the session events pipeline.
108111 const sessionId = getSessionId ( input ) ;
109- const projectDir = process . env . CLAUDE_PROJECT_DIR || process . cwd ( ) ;
112+ const projectDir = process . env [ platformOpts . projectDirEnv ] || process . cwd ( ) ;
110113 db . ensureSession ( sessionId , projectDir ) ;
111- const claudeMdPaths = [
112- join ( resolveConfigDir ( ) , "CLAUDE.md" ) ,
113- join ( projectDir , "CLAUDE.md" ) ,
114- join ( projectDir , ".claude" , "CLAUDE.md" ) ,
114+ const memoryFileNames = platformOpts . configDir === ".qwen"
115+ ? [ "QWEN.md" ]
116+ : [ "CLAUDE.md" ] ;
117+ const memoryMdPaths = [
118+ join ( resolveConfigDir ( platformOpts ) , memoryFileNames [ 0 ] ) ,
119+ join ( projectDir , memoryFileNames [ 0 ] ) ,
120+ join ( projectDir , platformOpts . configDir , memoryFileNames [ 0 ] ) ,
115121 ] ;
116- for ( const p of claudeMdPaths ) {
122+ for ( const p of memoryMdPaths ) {
117123 try {
118124 const content = readFileSync ( p , "utf-8" ) ;
119125 if ( content . trim ( ) ) {
@@ -128,7 +134,10 @@ try {
128134 // Age-gated lazy cleanup of old plugin cache version dirs (#181).
129135 // Only delete dirs older than 1 hour to avoid breaking active sessions.
130136 try {
131- const pluginRoot = process . env . CLAUDE_PLUGIN_ROOT ;
137+ const pluginRootEnv = platformOpts . configDir === ".qwen"
138+ ? "QWEN_PLUGIN_ROOT"
139+ : "CLAUDE_PLUGIN_ROOT" ;
140+ const pluginRoot = process . env [ pluginRootEnv ] ;
132141 if ( pluginRoot ) {
133142 const cacheParentMatch = pluginRoot . match ( / ^ ( .* [ \\ / ] p l u g i n s [ \\ / ] c a c h e [ \\ / ] [ ^ \\ / ] + [ \\ / ] [ ^ \\ / ] + [ \\ / ] ) / ) ;
134143 if ( cacheParentMatch ) {
0 commit comments