Skip to content

Bug: AGENTS.md loaded twice when the working directory is $HOME #911

Closed

Description

@maxivillus

Summary

load_agents_md_files_from_dir reads AGENTS.md from the working directory and from the home directory as two separate sources ("Project Instructions" + "Global Instructions"). When the working directory IS the home directory (very common for ACP hosts spawning jcode with cwd=$HOME — e.g. multica tasks whose workdir is the agent's home), the same file is loaded twice and both sections appear in the system prompt: duplicated instructions, duplicated tokens, and conflicting "which wins?" guidance for the model.

Gap

No dedup between the two sources. crates/jcode-base/src/prompt.rs load_agents_md_files_from_dir unconditionally loads both.

Fix (implemented and verified locally)

  • Core logic extracted into load_agents_md_files_from_dirs(project_dir, home_agents_path) (testable, no I/O in the decision): if canonicalize(project_dir) == canonicalize(home_dir), the home copy is skipped — the project source wins and only one "Project Instructions" section is emitted; the global section is not fabricated.
  • Distinct project/home dirs keep the current behavior (both sections).

Impact (measured)

With cwd=$HOME: ~2.9 KB of duplicated instructions removed from the system prompt (≈ 750 tokens, o200k_base).

Verification

  • 3 unit tests (agents_md_dedup_tests): project==home → loaded once (no "Global Instructions"), distinct dirs → both, missing home file → project only.
  • cargo check -p jcode-base + ACP smoke pass.

Files

crates/jcode-base/src/prompt.rs (load_agents_md_files_from_dirs, load_agents_md_files_from_dir shim).

Activity

  1. added
    bug
    priority: medium
    triage: reproducible
    autonomous: clear
    on Aug 13, 2026
  2. 1jehuang commented on Aug 13, 2026

    @1jehuang
    Owner

    I added canonical-path deduplication for home/project AGENTS.md loading, preserving project precedence and covering symlink and missing-file cases. Fix: #918.

    --- — Jcode agent (automated triage), on behalf of @1jehuang

  3. added
    triage: fixed-pending-release
    on Aug 13, 2026
  4. added a commit that references this issue on Aug 13, 2026
    898e3ef
  5. added a commit that references this issue on Aug 15, 2026
    a8e0afd
  6. added a commit that references this issue on Aug 28, 2026
    877e57f
  7. added 5 commits that reference this issue on Aug 30, 2026
    468f3a1
    74c3148
    7df9d7b
    4258a49
    c70f45c
  8. added a commit that references this issue on Sep 18, 2026
    84740e2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    autonomous: clearbugpriority: mediumtriage: fixed-pending-releasetriage: reproducible

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions