Skip to content

Search for AGENT.md in project subdirectory #2094

Closed

Description

@segoon

opencode can be started from a project's subdirectory. In this case it looks for AGENT*.md in current directory only, not in the project's root.

Suggestion: implement project root identification (e.g. based on special file existence like .git, pyproject.toml, etc.) & additionally load agents files starting from the project root.

Activity

  1. github-actions commented on Aug 20, 2025

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  2. segoon commented on Aug 20, 2025

    @segoon
    ContributorAuthor

    I think there are 2 different tasks and 1 common subtask:

    • use project's sessions
    • use project's AGENT.md
    • locate project root (common)
  3. rekram1-node commented on Aug 20, 2025

    @rekram1-node
    Collaborator

    hmm i thought we already loaded agents.md from project root everytime

  4. rekram1-node commented on Aug 20, 2025

    @rekram1-node
    Collaborator
    Image

    Maybe I misread your wording but as you can see in this basic project we definitely read AGENTS.md from project root even when you are in subdirectory.

  5. segoon commented on Aug 23, 2025

    @segoon
    ContributorAuthor

    Hmm looks like it works for projects with .git. However, how do you discover project root? It is this code - https://github.com/sst/opencode/blob/1f57b9a70f09bea9c9fd5662becdda18c967f9a1/packages/opencode/src/app/app.ts#L69 ? I don't think it is generic enough - there are projects without git and with other VCSs or even without VCS at all. It's better to enable user to define root marker files with some sane defaults (e.g. .git, .hg and similar).

  6. rekram1-node commented on Aug 23, 2025

    @rekram1-node
    Collaborator

    makes sense

  7. maiterth commented on Sep 5, 2025

    @maiterth

    Hmm looks like it works for projects with .git. However, how do you discover project root? It is this code -

    opencode/packages/opencode/src/app/app.ts

    Line 69 in 1f57b9a
    const root = git ?? input.cwd
    ? I don't think it is generic enough - there are projects without git and with other VCSs or even without VCS at all. It's better to enable user to define root marker files with some sane defaults (e.g. .git, .hg and similar).

    I started using git worktree and realized that opencode always is looking into the main worktree, but not in my current worktree. This implementation detail made me understand why. running git config --list --show-origin made me realize that opencode thinks it should look in the directory from which the worktree was generated.
    Not sure what a solution to this would be.

    --- After some digging:

    I looked: since the referenced code is old, most likely this part is relevant, which is already in develop:
    https://github.com/sst/opencode/blob/900fe5ca041c5b9e2de9449c441dd9cb10beed0a/packages/opencode/src/project/project.ts#L68C17-L68C70

      worktree = path.dirname(
        await $`git rev-parse --path-format=absolute --git-common-dir`
          .quiet()
          .nothrow()
          .cwd(worktree)
          .text()
          .then((x) => x.trim()),
      )
    

    And this looks like it already solves my issue. While i think git rev-parse --path-format=absolute --git-dir would give the worktree's directory and the above command gives the common directory.
    I'll have to test with the current develop.

  8. rekram1-node commented on Sep 5, 2025

    @rekram1-node
    Collaborator

    I'll have to test with the current develop.

    Does this mean you have to test on latest? sorry i didn't quite follow u

  9. maiterth commented on Sep 5, 2025

    @maiterth

    Sorry, for the confusion, I have opened an new issue #2445 And I have tested with latest and found a quick fix.
    https://github.com/maiterth/opencode/compare/dev...feature-test-worktree-rootdir
    But this is actually unrelated to OPs issue. -> #2445

  10. rekram1-node commented on Sep 5, 2025

    @rekram1-node
    Collaborator

    sweet, just saw it thanks @maiterth

  11. rekram1-node commented on Dec 28, 2025

    @rekram1-node
    Collaborator

    [automated] Closing due to 90+ days of inactivity. Feel free to reopen if you still need this!

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions