Skip to content

Suppoert symlinked .rules files #14767

Open

Description

@KeqiZeng

What version of Codex CLI is running?

codex-cli 0.114.0

What subscription do you have?

Plus

Which model were you using?

gpt-5.4

What platform is your computer?

Darwin 25.3.0 arm64 arm

What terminal emulator and version are you using (if applicable)?

Kitty 0.46.0

What issue are you seeing?

The symlinked rules file in rules folder is ignored by rules loader

What steps can reproduce the bug?

echo 'prefix_rule(pattern=["git", "add"], decision="allow")' >> /tmp/demo.rules
ln -sf /tmp/demo.rules ~/.codex/rules/demo.rules

# in a git repo
codex

and then ask the agent to use git add to stage some files. It still ask for the approval even if the demo.rules defined the prefix_rule for git add

What is the expected behavior?

The symlinked rules file should be loaded automatically.

Additional information

No response

Activity

  1. added
    bug
    on Mar 15, 2026
  2. added
    CLI
    sandbox
    on Mar 15, 2026
  3. github-actions commented on Mar 15, 2026

    @github-actions
    Contributor

    Potential duplicates detected. Please review them and close your issue if it is a duplicate.

    Powered by Codex Action

  4. changed the title [-]Rules loader ignores symlinked .rules files[/-] [+]Suppoert symlinked .rules files[/+] on Mar 15, 2026
  5. added
    enhancement
    and removed
    bug
    CLI
    on Mar 15, 2026
  6. etraut-openai commented on Mar 15, 2026

    @etraut-openai
    Contributor

    I'm changing this from a bug report to an enhancement request.

  7. Bad3r commented on Oct 26, 2026

    @Bad3r

    Still present on main at dd55214 (and in 0.164.0): collect_policy_files in codex-rs/core/src/exec_policy.rs keeps an entry only when DirEntry::file_type().is_file(), which does not follow symlinks, so a symlinked *.rules file is skipped. Writes already follow the link (approvals are appended to default.rules through OpenOptions::append), so an approval made in the TUI lands in the target file but is never loaded again.

    Proposed fix: resolve symlinks with fs::metadata and keep the entry when the target is a regular file. Dangling links and links to directories are still skipped.

    --- a/codex-rs/core/src/exec_policy.rs
    +++ b/codex-rs/core/src/exec_policy.rs
    @@ -1172,11 +1172,20 @@ async fn collect_policy_files(dir: impl AsRef<Path>) -> Result<Vec<PathBuf>, ExecPolicyError> {
                     source,
                 })?;
     
    +        // Follow symlinks so linked rule files load; dangling links are skipped.
    +        let is_file = if file_type.is_symlink() {
    +            fs::metadata(&path)
    +                .await
    +                .is_ok_and(|metadata| metadata.is_file())
    +        } else {
    +            file_type.is_file()
    +        };
    +
             if path
                 .extension()
                 .and_then(|ext| ext.to_str())
                 .is_some_and(|ext| ext == RULE_EXTENSION)
    -            && file_type.is_file()
    +            && is_file
             {
                 policy_paths.push(path);
             }

    Test for codex-rs/core/src/exec_policy_tests.rs (Unix only): a symlinked rules file is returned and a dangling symlink is ignored.

    #[cfg(unix)]
    #[tokio::test]
    async fn collect_policy_files_follows_symlinks() {
        let temp_dir = tempdir().expect("create temp dir");
        let policy_dir = temp_dir.path().join(RULES_DIR_NAME);
        fs::create_dir_all(&policy_dir).expect("create policy dir");
        let target = temp_dir.path().join("shared.rules");
        fs::write(&target, "").expect("write target rules");
        let linked = policy_dir.join("linked.rules");
        std::os::unix::fs::symlink(&target, &linked).expect("symlink rules");
        std::os::unix::fs::symlink(
            temp_dir.path().join("missing.rules"),
            policy_dir.join("dangling.rules"),
        )
        .expect("symlink dangling rules");
    
        let files = collect_policy_files(&policy_dir)
            .await
            .expect("collect policy files");
    
        assert_eq!(files, vec![linked]);
    }
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

    enhancementsandbox

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions