> For the complete documentation index, see [llms.txt](https://chaoses-ib.gitbook.io/directory-opus/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chaoses-ib.gitbook.io/directory-opus/manual/reference/scripting_reference/scripting_events/onbeforefolderchange.md).

# OnBeforeFolderChange

The **OnBeforeFolderChange** event can be implemented by a [script add-in](/directory-opus/manual/scripting/script_add-ins.md) to receive notification before a new folder is read in a tab. Use the **OnAfterFolderChange** event if you want notification *after* a folder has been read.

| **Method Name:**   | OnBeforeFolderChange                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Argument Type:** | [**BeforeFolderChangeData**](/directory-opus/manual/reference/scripting_reference/scripting_objects/beforefolderchangedata.md)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| **Return Type:**   | *bool* or *string*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| **Description:**   | <p>The <strong>BeforeFolderChangeData.tab</strong> property identifies the tab, and the <strong>path</strong> property identifies the folder about to be read. The <strong>initial</strong> property indicates if this is the first folder read into this tab - if <strong>True</strong>, it means the tab was previously empty or newly opened.</p><p>You can return two different types from this event:</p><ul><li><em>bool</em>: If you return <strong>True</strong>, the folder read will be blocked and the tab will be unchanged. If you return <strong>False</strong> the read will be allowed to continue (this is the default).</li><li><em>string</em>: You can return a <em>string</em> (or a <a href="/pages/rIWyr8IKVnoic6aq4Yb4"><strong>Path</strong></a> object) to change the folder path to be read.</li></ul> |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://chaoses-ib.gitbook.io/directory-opus/manual/reference/scripting_reference/scripting_events/onbeforefolderchange.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
