The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): skip_context_files also disables subdirectory hint injection
teknium15148b76677f7
diff --git a/agent/agent_init.py b/agent/agent_init.pyindex 755086471a2..8561f1955c2 100644--- a/agent/agent_init.py+++ b/agent/agent_init.py@@ -2108,7 +2108,8 @@ def _snapshot_primary_runtime(agent):def _init_usage_state(agent):from agent.runtime_cwd import scope_terminal_cwd- agent._subdirectory_hints = SubdirectoryHintTracker(working_dir=scope_terminal_cwd() or None)+ agent._subdirectory_hints = SubdirectoryHintTracker(+ working_dir=scope_terminal_cwd() or None, enabled=not agent.skip_context_files)_set_defaults(agent, _USAGE_STATE)diff --git a/agent/subdirectory_hints.py b/agent/subdirectory_hints.pyindex 68512719cb1..02fd80a37be 100644--- a/agent/subdirectory_hints.py+++ b/agent/subdirectory_hints.py@@ -59,7 +59,11 @@ class SubdirectoryHintTracker:and append the returned text to the tool result."""- def __init__(self, working_dir: Optional[str] = None):+ def __init__(self, working_dir: Optional[str] = None, *, enabled: bool = True):+ # ``enabled=False`` mirrors ``skip_context_files``: a session that opted out of+ # AGENTS.md/CLAUDE.md injection at startup must not get the same files spliced into+ # tool results later — cron jobs relaying exact stdout leaked them to chat (#9441).+ self.enabled = enabledself.working_dir = Path(working_dir or os.getcwd()).resolve()# The working dir is pre-marked loaded (startup context handles it).self._loaded_dirs: Set[Path] = {self.working_dir}@@ -73,6 +77,8 @@ class SubdirectoryHintTracker:def check_tool_call(self, tool_name: str, tool_args: Dict[str, Any]) -> Optional[str]:"""Return formatted hint text for newly visited directories, or None."""+ if not self.enabled:+ return Noneall_hints = [h for d in self._extract_directories(tool_name, tool_args) if (h := self._load_hints_for_directory(d))]return "\n\n" + "\n\n".join(all_hints) if all_hints else Nonediff --git a/tests/agent/test_subdirectory_hints.py b/tests/agent/test_subdirectory_hints.pyindex 3709a3792b8..3b1e2adaa9a 100644--- a/tests/agent/test_subdirectory_hints.py+++ b/tests/agent/test_subdirectory_hints.py@@ -56,6 +56,12 @@ class TestSubdirectoryHintTracker:assert result is not Noneassert "Frontend rules" in result+ def test_disabled_tracker_never_injects_hints(self, project):+ """A session that skips context files (cron without a workdir) must not have the same+ files spliced into tool results, where they leak into exact-output deliveries (#9441)."""+ tracker = SubdirectoryHintTracker(working_dir=str(project), enabled=False)+ assert tracker.check_tool_call("read_file", {"path": str(project / "frontend" / "index.ts")}) is None+def test_no_duplicate_loading(self, project):"""Same directory should not be loaded twice."""tracker = SubdirectoryHintTracker(working_dir=str(project))